Skip to content

Commit

Permalink
Too many changes to count. Enjoy my week of work :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed Sep 15, 2024
1 parent 5bf9733 commit 52e48d5
Show file tree
Hide file tree
Showing 145 changed files with 2,396 additions and 2,334 deletions.
2 changes: 1 addition & 1 deletion calio/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version = "v1.0.0"

println("Loaded subproject \"${project.name}\" with version {$version}")
println("Loaded subproject \"${project.name}\" with version '$version'")

dependencies {
compileOnly("org.quiltmc.parsers:json:0.2.1")
Expand Down
265 changes: 124 additions & 141 deletions calio/src/main/java/io/github/dueris/calio/SerializableDataTypes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.dueris.calio.data;

import io.github.dueris.calio.parser.RootResult;
import io.github.dueris.calio.registry.RegistryKey;
import net.minecraft.core.Registry;

import java.util.List;

public record DataBuildDirective<T>(List<String> modids, String folder, SerializableDataBuilder<RootResult<T>> builder,
int priority, RegistryKey<T> registryKey) {
public record DataBuildDirective<T>(List<String> modids, String folder, SerializableDataType<RootResult<T>> builder,
int priority, Registry<T> registryKey) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SerializableData {
public Consumer<Instance> postProcessor;
public ResourceLocation typedInstance;
Map<String, Object> defaultMap = new LinkedHashMap<>();
HashMap<String, ObjectTiedEnumState<SerializableDataBuilder<?>>> dataMap = new LinkedHashMap<>();
HashMap<String, ObjectTiedEnumState<SerializableDataType<?>>> dataMap = new LinkedHashMap<>();

public SerializableData(@NotNull SerializableData serializableData) {
this.defaultMap = serializableData.defaultMap;
Expand All @@ -35,29 +35,29 @@ public SerializableData() {
}

public synchronized <T> SerializableData add(String key, @NotNull Tuple<Codec<T>, Class<T>> data) {
return add(key, SerializableDataBuilder.of(data.getA(), data.getB()));
return add(key, SerializableDataType.of(data.getA(), data.getB()));
}

public synchronized SerializableData add(String key, SerializableDataBuilder<?> data) {
public synchronized SerializableData add(String key, SerializableDataType<?> data) {
dataMap.put(key, new ObjectTiedEnumState<>(data, SerializableType.REQUIRED));
return this;
}

public synchronized <T> SerializableData add(String key, @NotNull Tuple<Codec<T>, Class<T>> data, T defaultValue) {
return add(key, SerializableDataBuilder.of(data.getA(), data.getB()), defaultValue);
return add(key, SerializableDataType.of(data.getA(), data.getB()), defaultValue);
}

public synchronized <T> SerializableData add(String key, SerializableDataBuilder<T> data, T defaultValue) {
public synchronized <T> SerializableData add(String key, SerializableDataType<T> data, T defaultValue) {
dataMap.put(key, new ObjectTiedEnumState<>(data, SerializableType.DEFAULT));
defaultMap.put(key, defaultValue);
return this;
}

public synchronized <T> SerializableData add(String key, @NotNull Tuple<Codec<T>, Class<T>> data, Supplier<T> supplier) {
return addSupplied(key, SerializableDataBuilder.of(data.getA(), data.getB()), supplier);
return addSupplied(key, SerializableDataType.of(data.getA(), data.getB()), supplier);
}

public synchronized <T> SerializableData addSupplied(String key, SerializableDataBuilder<T> data, @NotNull Supplier<T> supplier) {
public synchronized <T> SerializableData addSupplied(String key, SerializableDataType<T> data, @NotNull Supplier<T> supplier) {
dataMap.put(key, new ObjectTiedEnumState<>(data, SerializableType.DEFAULT));
defaultMap.put(key, supplier.get());
return this;
Expand All @@ -73,7 +73,7 @@ public synchronized SerializableData typedRegistry(ResourceLocation type) {
return this;
}

public HashMap<String, ObjectTiedEnumState<SerializableDataBuilder<?>>> dataMap() {
public HashMap<String, ObjectTiedEnumState<SerializableDataType<?>>> dataMap() {
return dataMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
* The builder for parsing JsonElements -> Java objects
* Upon deserializing, if a null value is provided, it will not parse. It WILL return null.
*/
public interface SerializableDataBuilder<T> extends Codec<T> {
public interface SerializableDataType<T> extends Codec<T> {
DynamicOps<JsonElement> JSON_OPS = JsonOps.INSTANCE;
Logger log = LogManager.getLogger("SerializableDataBuilder");

static <T> @NotNull SerializableDataBuilder<List<T>> of(Codec<List<T>> listCodec) {
static <T> @NotNull SerializableDataType<List<T>> of(Codec<List<T>> listCodec) {
return of(listCodec, List.class);
}

static <T> @NotNull SerializableDataBuilder<T> of(Codec<T> codec, Class<?> type) {
return new AbstractSerializableDataBuilder<>(type) {
static <T> @NotNull SerializableDataType<T> of(Codec<T> codec, Class<?> type) {
return new AbstractSerializableDataType<>(type) {
@Override
public T deserialize(JsonElement object) {
if (object == null) return null;
Expand All @@ -46,12 +46,12 @@ public <T1> DataResult<Pair<T, T1>> decode(DynamicOps<T1> ops, T1 input) {
};
}

static <T> @NotNull SerializableDataBuilder<T> of(Function<JsonElement, T> deserialize, Class<?> type) {
static <T> @NotNull SerializableDataType<T> of(Function<JsonElement, T> deserialize, Class<?> type) {
return of(deserialize, type, true);
}

static <T> @NotNull SerializableDataBuilder<T> of(Function<JsonElement, T> deserialize, Class<?> type, boolean printJson) {
return new AbstractSerializableDataBuilder<>(type) {
static <T> @NotNull SerializableDataType<T> of(Function<JsonElement, T> deserialize, Class<?> type, boolean printJson) {
return new AbstractSerializableDataType<>(type) {
@Override
public T deserialize(@Nullable JsonElement object) {
if (object == null) return null;
Expand All @@ -62,6 +62,7 @@ public T deserialize(@Nullable JsonElement object) {
if (printJson) {
log.error("JsonElement : {}", object.toString());
}
throwable.printStackTrace();
return null;
}
}
Expand All @@ -76,7 +77,7 @@ public <T1> DataResult<Pair<T, T1>> decode(DynamicOps<T1> ops, T1 input) {
}

static <A> @NotNull Codec<A> of(final Encoder<A> encoder, final Decoder<A> decoder, final String name, Class<?> type) {
return new AbstractSerializableDataBuilder<>(type) {
return new AbstractSerializableDataType<>(type) {
@Override
public A deserialize(JsonElement object) {
if (object == null) return null;
Expand Down Expand Up @@ -142,8 +143,8 @@ public String toString() {
return instance;
}

static @NotNull <T> SerializableDataBuilder<T> compound(SerializableData definer, Function<SerializableData.Instance, T> fromData, Class<?> classType) {
return SerializableDataBuilder.of(
static @NotNull <T> SerializableDataType<T> compound(SerializableData definer, Function<SerializableData.Instance, T> fromData, Class<?> classType) {
return SerializableDataType.of(
(jsonElement) -> {
if (!(jsonElement instanceof JsonObject jo)) throw new JsonSyntaxException("Expected JsonObject");
SerializableData.Instance compound = compound(definer, jo, classType);
Expand All @@ -162,10 +163,10 @@ default String asString() {
return type().getSimpleName();
}

abstract class AbstractSerializableDataBuilder<T> implements SerializableDataBuilder<T> {
abstract class AbstractSerializableDataType<T> implements SerializableDataType<T> {
private final Class<?> type;

protected AbstractSerializableDataBuilder(Class<?> type) {
protected AbstractSerializableDataType(Class<?> type) {
this.type = type;
}

Expand All @@ -181,7 +182,7 @@ public <T1> DataResult<T1> encode(T input, DynamicOps<T1> ops, T1 prefix) {

@Override
public <S> Codec<S> comapFlatMap(Function<? super T, ? extends DataResult<? extends S>> to, Function<? super S, ? extends T> from, Class<?> type) {
return SerializableDataBuilder.of(comap(from), flatMap(to), this + "[comapFlatMapped]", type);
return SerializableDataType.of(comap(from), flatMap(to), this + "[comapFlatMapped]", type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import io.github.dueris.calio.data.DataBuildDirective;
import io.github.dueris.calio.registry.RegistryKey;
import io.github.dueris.calio.registry.impl.CalioRegistry;
import io.github.dueris.calio.util.ReflectionUtils;
import io.github.dueris.calio.util.annotations.SourceProvider;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Tuple;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -68,9 +67,9 @@ public static <T> void parseFiles(Map.@NotNull Entry<DataBuildDirective<T>, List
if (ReflectionUtils.hasFieldWithAnnotation(instance.getClass(), JsonObject.class, SourceProvider.class)) {
ReflectionUtils.setFieldWithAnnotation(instance, SourceProvider.class, jsonSource);
}
RegistryKey<T> registryKey = (RegistryKey<T>) dataBuildDirective.registryKey();
Registry<T> registryKey = (Registry<T>) dataBuildDirective.registryKey();
if (ReflectionUtils.invokeBooleanMethod(instance, "canRegister")) {
CalioRegistry.INSTANCE.retrieve(registryKey).register(instance, location);
Registry.register(registryKey, location, instance);
}

return instance;
Expand Down

This file was deleted.

This file was deleted.

185 changes: 0 additions & 185 deletions calio/src/main/java/io/github/dueris/calio/registry/Registrar.java

This file was deleted.

This file was deleted.

Loading

0 comments on commit 52e48d5

Please sign in to comment.