From 49318a4452f629274e96001700006e0b4a1464a5 Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Sun, 13 Feb 2022 07:52:10 +0200 Subject: Moved some stuff around --- .../shcm/shsupercm/fabric/citresewn/CITResewn.java | 2 +- .../citresewn/api/CITConditionContainer.java | 2 +- .../fabric/citresewn/api/CITTypeContainer.java | 4 +- .../fabric/citresewn/builtin/WeightCondition.java | 27 -------- .../shsupercm/fabric/citresewn/cit/ActiveCITs.java | 66 +++++++++++++++++++ .../shcm/shsupercm/fabric/citresewn/cit/CIT.java | 27 ++++++++ .../fabric/citresewn/cit/CITCondition.java | 35 +++++++++++ .../shsupercm/fabric/citresewn/cit/CITContext.java | 32 ++++++++++ .../fabric/citresewn/cit/CITRegistry.java | 73 ++++++++++++++++++++++ .../shsupercm/fabric/citresewn/cit/CITType.java | 10 +++ .../citresewn/cit/builtin/WeightCondition.java | 27 ++++++++ .../fabric/citresewn/mixin/ModelLoaderMixin.java | 2 +- .../fabric/citresewn/pack/PackParser.java | 10 +-- .../fabric/citresewn/pack/cit/ActiveCITs.java | 66 ------------------- .../shsupercm/fabric/citresewn/pack/cit/CIT.java | 27 -------- .../fabric/citresewn/pack/cit/CITCondition.java | 35 ----------- .../fabric/citresewn/pack/cit/CITContext.java | 32 ---------- .../fabric/citresewn/pack/cit/CITRegistry.java | 73 ---------------------- .../fabric/citresewn/pack/cit/CITType.java | 10 --- 19 files changed, 280 insertions(+), 280 deletions(-) delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/builtin/WeightCondition.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/CIT.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITCondition.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITContext.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/WeightCondition.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/ActiveCITs.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CIT.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITCondition.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITContext.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITRegistry.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITType.java (limited to 'src/main/java/shcm/shsupercm') diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java index ce908ed..482d757 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java @@ -5,7 +5,7 @@ import net.fabricmc.api.ClientModInitializer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITRegistry; +import shcm.shsupercm.fabric.citresewn.cit.CITRegistry; public class CITResewn implements ClientModInitializer { public static final Logger LOG = LogManager.getLogger("CITResewn"); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java index 6803526..56ac01f 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java @@ -1,6 +1,6 @@ package shcm.shsupercm.fabric.citresewn.api; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITCondition; +import shcm.shsupercm.fabric.citresewn.cit.CITCondition; import java.util.function.Supplier; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java index e207d00..8c375bb 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java @@ -1,7 +1,7 @@ package shcm.shsupercm.fabric.citresewn.api; -import shcm.shsupercm.fabric.citresewn.pack.cit.CIT; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITType; +import shcm.shsupercm.fabric.citresewn.cit.CIT; +import shcm.shsupercm.fabric.citresewn.cit.CITType; import java.util.List; import java.util.function.Supplier; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/builtin/WeightCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/builtin/WeightCondition.java deleted file mode 100644 index 4161a55..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/builtin/WeightCondition.java +++ /dev/null @@ -1,27 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.builtin; - -import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint; -import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer; -import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITCondition; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITContext; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; - -public class WeightCondition extends CITCondition { - @Entrypoint(CITConditionContainer.ENTRYPOINT) - public static final CITConditionContainer CONTAINER = new CITConditionContainer<>(WeightCondition.class, WeightCondition::new, - "weight"); - - public int weight = 0; - - @Override - public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException { - this.weight = parseInteger(value, properties); - } - - @Override - public boolean test(CITContext context) { - return true; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java new file mode 100644 index 0000000..d24faf8 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java @@ -0,0 +1,66 @@ +package shcm.shsupercm.fabric.citresewn.cit; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.profiler.Profiler; +import shcm.shsupercm.fabric.citresewn.api.CITDisposable; +import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; +import shcm.shsupercm.fabric.citresewn.pack.GlobalProperties; +import shcm.shsupercm.fabric.citresewn.pack.PackParser; + +import java.util.*; + +public class ActiveCITs implements CITDisposable { private ActiveCITs() {} + private static ActiveCITs active = null; + + public static ActiveCITs getActive() { + return active; + } + + public static boolean isActive() { + return active != null; + } + + public final GlobalProperties globalProperties = new GlobalProperties(); + + public final Map, List> cits = new IdentityHashMap<>(); + + public static ActiveCITs load(ResourceManager resourceManager, Profiler profiler) { + profiler.push("citresewn:disposing"); + if (active != null) { + active.dispose(); + active = null; + } + + ActiveCITs active = new ActiveCITs(); + + profiler.swap("citresewn:load_global_properties"); + PackParser.loadGlobalProperties(resourceManager, active.globalProperties); + active.globalProperties.callHandlers(); + + profiler.swap("citresewn:load_cits"); + for (CIT cit : PackParser.loadCITs(resourceManager)) + active.cits.computeIfAbsent(cit.type.getClass(), type -> new ArrayList<>()).add(cit); + for (Map.Entry, List> entry : active.cits.entrySet()) { + entry.getValue().sort(Comparator.comparingInt(cit -> cit.weight).reversed().thenComparing(cit -> cit.propertiesIdentifier.toString())); + for (CITTypeContainer typeContainer : CITRegistry.TYPES.values()) + if (typeContainer.type == entry.getKey()) { + typeContainer.load(entry.getValue()); + break; + } + } + + profiler.pop(); + + return ActiveCITs.active = active; + } + + @Override + public void dispose() { + for (CITDisposable disposable : FabricLoader.getInstance().getEntrypoints(CITDisposable.ENTRYPOINT, CITDisposable.class)) + disposable.dispose(); + + for (CITTypeContainer typeContainer : CITRegistry.TYPES.values()) + typeContainer.dispose(); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CIT.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CIT.java new file mode 100644 index 0000000..ea75c04 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CIT.java @@ -0,0 +1,27 @@ +package shcm.shsupercm.fabric.citresewn.cit; + +import net.minecraft.util.Identifier; + +public class CIT { + public final Identifier propertiesIdentifier; + public final String packName; + public final CITType type; + public final CITCondition[] conditions; + public final int weight; + + public CIT(Identifier propertiesIdentifier, String packName, CITType type, CITCondition[] conditions, int weight) { + this.propertiesIdentifier = propertiesIdentifier; + this.packName = packName; + this.type = type; + this.conditions = conditions; + this.weight = weight; + } + + public boolean test(CITContext context) { + for (CITCondition condition : conditions) + if (!condition.test(context)) + return false; + + return true; + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITCondition.java new file mode 100644 index 0000000..7640d3c --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITCondition.java @@ -0,0 +1,35 @@ +package shcm.shsupercm.fabric.citresewn.cit; + +import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; + +import java.util.Collections; +import java.util.Set; + +public abstract class CITCondition { + public abstract void load(PropertyValue value, PropertyGroup properties) throws CITParsingException; + + public Set> siblingConditions() { + return Collections.emptySet(); + } + + public T modifySibling(Class siblingType, T sibling) { + return sibling; + } + + public abstract boolean test(CITContext context); + + protected void warn(String message, PropertyValue value, PropertyGroup properties) { + CITResewn.logWarnLoading("Warning: " + CITParsingException.descriptionOf(message, properties, value.position())); + } + + protected int parseInteger(PropertyValue value, PropertyGroup properties) throws CITParsingException { + try { + return Integer.parseInt(value.value()); + } catch (NumberFormatException e) { + throw new CITParsingException("\"" + value.value() + "\" is not a valid integer", properties, value.position()); + } + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITContext.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITContext.java new file mode 100644 index 0000000..99cdbf0 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITContext.java @@ -0,0 +1,32 @@ +package shcm.shsupercm.fabric.citresewn.cit; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import java.util.Objects; + +public class CITContext { + public final ItemStack stack; + public final World world; + public final LivingEntity entity; + + public CITContext(ItemStack stack, World world, LivingEntity entity) { + this.stack = stack; + this.world = world; + this.entity = entity; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof CITContext that && + Objects.equals(this.stack, that.stack) && + Objects.equals(this.world, that.world) && + Objects.equals(this.entity, that.entity); + } + + @Override + public int hashCode() { + return Objects.hash(stack, world, entity); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java new file mode 100644 index 0000000..33f6367 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java @@ -0,0 +1,73 @@ +package shcm.shsupercm.fabric.citresewn.cit; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.util.Identifier; +import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer; +import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; +import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; +import shcm.shsupercm.fabric.citresewn.ex.UnknownCITTypeException; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; + +import java.util.*; + +import static shcm.shsupercm.fabric.citresewn.CITResewn.info; +import static shcm.shsupercm.fabric.citresewn.CITResewn.logWarnLoading; + +public class CITRegistry { + public static final Map> TYPES = new HashMap<>(); + public static final Map> CONDITIONS = new HashMap<>(); + + public static void registerAll() { + info("Registering CIT Conditions"); + for (var entrypointContainer : FabricLoader.getInstance().getEntrypointContainers(CITConditionContainer.ENTRYPOINT, CITConditionContainer.class)) { + String namespace = entrypointContainer.getProvider().getMetadata().getId(); + if (namespace.equals("citresewn-defaults")) + namespace = "citresewn"; + + for (String alias : entrypointContainer.getEntrypoint().aliases) + CONDITIONS.put(new PropertyKey(namespace, alias), (CITConditionContainer) entrypointContainer.getEntrypoint()); + } + + info("Registering CIT Types"); + for (var entrypointContainer : FabricLoader.getInstance().getEntrypointContainers(CITTypeContainer.ENTRYPOINT, CITTypeContainer.class)) { + String namespace = entrypointContainer.getProvider().getMetadata().getId(); + if (namespace.equals("citresewn-defaults")) + namespace = "citresewn"; + + TYPES.put(new Identifier(namespace, entrypointContainer.getEntrypoint().id), (CITTypeContainer) entrypointContainer.getEntrypoint()); + } + } + + public static CITCondition parseCondition(PropertyKey key, PropertyValue value, PropertyGroup properties) throws CITParsingException { + CITConditionContainer conditionContainer = CONDITIONS.get(key); + if (conditionContainer == null) { + logWarnLoading("Skipping condition: " + CITParsingException.descriptionOf("Unknown condition type", properties, value.position())); + return null; + } + + CITCondition condition = conditionContainer.createCondition.get(); + condition.load(value, properties); + return condition; + } + + public static CITType parseType(PropertyGroup properties) throws CITParsingException { + Identifier type = new Identifier("citresewn", "item"); + + PropertyValue propertiesType = properties.getLast("citresewn", "type"); + if (propertiesType != null) { + String value = propertiesType.value(); + if (!value.contains(":")) + value = "citresewn:" + value; + type = new Identifier(value); + } + + CITTypeContainer typeContainer = TYPES.get(type); + if (typeContainer == null) + // assert (propertiesType != null) because the default citresewn:item should always be registered + throw new UnknownCITTypeException(properties, propertiesType == null ? -1 : propertiesType.position()); + + return typeContainer.createType.get(); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java new file mode 100644 index 0000000..abbe755 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java @@ -0,0 +1,10 @@ +package shcm.shsupercm.fabric.citresewn.cit; + +import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; + +import java.util.List; + +public abstract class CITType { + public abstract void load(List conditions, PropertyGroup properties) throws CITParsingException; +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/WeightCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/WeightCondition.java new file mode 100644 index 0000000..ec0a5d7 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/WeightCondition.java @@ -0,0 +1,27 @@ +package shcm.shsupercm.fabric.citresewn.cit.builtin; + +import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint; +import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer; +import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; +import shcm.shsupercm.fabric.citresewn.cit.CITCondition; +import shcm.shsupercm.fabric.citresewn.cit.CITContext; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; + +public class WeightCondition extends CITCondition { + @Entrypoint(CITConditionContainer.ENTRYPOINT) + public static final CITConditionContainer CONTAINER = new CITConditionContainer<>(WeightCondition.class, WeightCondition::new, + "weight"); + + public int weight = 0; + + @Override + public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException { + this.weight = parseInteger(value, properties); + } + + @Override + public boolean test(CITContext context) { + return true; + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java index e5e000d..ea1d5ab 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java @@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import shcm.shsupercm.fabric.citresewn.pack.cit.ActiveCITs; +import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; @Mixin(ModelLoader.class) public class ModelLoaderMixin { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java index c82b505..35e8c87 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java @@ -5,13 +5,13 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.resource.*; import net.minecraft.util.Identifier; import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.builtin.WeightCondition; +import shcm.shsupercm.fabric.citresewn.cit.builtin.WeightCondition; import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; import shcm.shsupercm.fabric.citresewn.mixin.GroupResourcePackAccessor; -import shcm.shsupercm.fabric.citresewn.pack.cit.CIT; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITCondition; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITRegistry; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITType; +import shcm.shsupercm.fabric.citresewn.cit.CIT; +import shcm.shsupercm.fabric.citresewn.cit.CITCondition; +import shcm.shsupercm.fabric.citresewn.cit.CITRegistry; +import shcm.shsupercm.fabric.citresewn.cit.CITType; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/ActiveCITs.java deleted file mode 100644 index 4d9377c..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/ActiveCITs.java +++ /dev/null @@ -1,66 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cit; - -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.resource.ResourceManager; -import net.minecraft.util.profiler.Profiler; -import shcm.shsupercm.fabric.citresewn.api.CITDisposable; -import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; -import shcm.shsupercm.fabric.citresewn.pack.GlobalProperties; -import shcm.shsupercm.fabric.citresewn.pack.PackParser; - -import java.util.*; - -public class ActiveCITs implements CITDisposable { private ActiveCITs() {} - private static ActiveCITs active = null; - - public static ActiveCITs getActive() { - return active; - } - - public static boolean isActive() { - return active != null; - } - - public final GlobalProperties globalProperties = new GlobalProperties(); - - public final Map, List> cits = new IdentityHashMap<>(); - - public static ActiveCITs load(ResourceManager resourceManager, Profiler profiler) { - profiler.push("citresewn:disposing"); - if (active != null) { - active.dispose(); - active = null; - } - - ActiveCITs active = new ActiveCITs(); - - profiler.swap("citresewn:load_global_properties"); - PackParser.loadGlobalProperties(resourceManager, active.globalProperties); - active.globalProperties.callHandlers(); - - profiler.swap("citresewn:load_cits"); - for (CIT cit : PackParser.loadCITs(resourceManager)) - active.cits.computeIfAbsent(cit.type.getClass(), type -> new ArrayList<>()).add(cit); - for (Map.Entry, List> entry : active.cits.entrySet()) { - entry.getValue().sort(Comparator.comparingInt(cit -> cit.weight).reversed().thenComparing(cit -> cit.propertiesIdentifier.toString())); - for (CITTypeContainer typeContainer : CITRegistry.TYPES.values()) - if (typeContainer.type == entry.getKey()) { - typeContainer.load(entry.getValue()); - break; - } - } - - profiler.pop(); - - return ActiveCITs.active = active; - } - - @Override - public void dispose() { - for (CITDisposable disposable : FabricLoader.getInstance().getEntrypoints(CITDisposable.ENTRYPOINT, CITDisposable.class)) - disposable.dispose(); - - for (CITTypeContainer typeContainer : CITRegistry.TYPES.values()) - typeContainer.dispose(); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CIT.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CIT.java deleted file mode 100644 index b4aa9fb..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CIT.java +++ /dev/null @@ -1,27 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cit; - -import net.minecraft.util.Identifier; - -public class CIT { - public final Identifier propertiesIdentifier; - public final String packName; - public final CITType type; - public final CITCondition[] conditions; - public final int weight; - - public CIT(Identifier propertiesIdentifier, String packName, CITType type, CITCondition[] conditions, int weight) { - this.propertiesIdentifier = propertiesIdentifier; - this.packName = packName; - this.type = type; - this.conditions = conditions; - this.weight = weight; - } - - public boolean test(CITContext context) { - for (CITCondition condition : conditions) - if (!condition.test(context)) - return false; - - return true; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITCondition.java deleted file mode 100644 index c16d96a..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITCondition.java +++ /dev/null @@ -1,35 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cit; - -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; - -import java.util.Collections; -import java.util.Set; - -public abstract class CITCondition { - public abstract void load(PropertyValue value, PropertyGroup properties) throws CITParsingException; - - public Set> siblingConditions() { - return Collections.emptySet(); - } - - public T modifySibling(Class siblingType, T sibling) { - return sibling; - } - - public abstract boolean test(CITContext context); - - protected void warn(String message, PropertyValue value, PropertyGroup properties) { - CITResewn.logWarnLoading("Warning: " + CITParsingException.descriptionOf(message, properties, value.position())); - } - - protected int parseInteger(PropertyValue value, PropertyGroup properties) throws CITParsingException { - try { - return Integer.parseInt(value.value()); - } catch (NumberFormatException e) { - throw new CITParsingException("\"" + value.value() + "\" is not a valid integer", properties, value.position()); - } - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITContext.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITContext.java deleted file mode 100644 index d8d66ad..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITContext.java +++ /dev/null @@ -1,32 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cit; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import java.util.Objects; - -public class CITContext { - public final ItemStack stack; - public final World world; - public final LivingEntity entity; - - public CITContext(ItemStack stack, World world, LivingEntity entity) { - this.stack = stack; - this.world = world; - this.entity = entity; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof CITContext that && - Objects.equals(this.stack, that.stack) && - Objects.equals(this.world, that.world) && - Objects.equals(this.entity, that.entity); - } - - @Override - public int hashCode() { - return Objects.hash(stack, world, entity); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITRegistry.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITRegistry.java deleted file mode 100644 index ba61757..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITRegistry.java +++ /dev/null @@ -1,73 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cit; - -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.util.Identifier; -import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer; -import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; -import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; -import shcm.shsupercm.fabric.citresewn.ex.UnknownCITTypeException; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; - -import java.util.*; - -import static shcm.shsupercm.fabric.citresewn.CITResewn.info; -import static shcm.shsupercm.fabric.citresewn.CITResewn.logWarnLoading; - -public class CITRegistry { - public static final Map> TYPES = new HashMap<>(); - public static final Map> CONDITIONS = new HashMap<>(); - - public static void registerAll() { - info("Registering CIT Conditions"); - for (var entrypointContainer : FabricLoader.getInstance().getEntrypointContainers(CITConditionContainer.ENTRYPOINT, CITConditionContainer.class)) { - String namespace = entrypointContainer.getProvider().getMetadata().getId(); - if (namespace.equals("citresewn-defaults")) - namespace = "citresewn"; - - for (String alias : entrypointContainer.getEntrypoint().aliases) - CONDITIONS.put(new PropertyKey(namespace, alias), (CITConditionContainer) entrypointContainer.getEntrypoint()); - } - - info("Registering CIT Types"); - for (var entrypointContainer : FabricLoader.getInstance().getEntrypointContainers(CITTypeContainer.ENTRYPOINT, CITTypeContainer.class)) { - String namespace = entrypointContainer.getProvider().getMetadata().getId(); - if (namespace.equals("citresewn-defaults")) - namespace = "citresewn"; - - TYPES.put(new Identifier(namespace, entrypointContainer.getEntrypoint().id), (CITTypeContainer) entrypointContainer.getEntrypoint()); - } - } - - public static CITCondition parseCondition(PropertyKey key, PropertyValue value, PropertyGroup properties) throws CITParsingException { - CITConditionContainer conditionContainer = CONDITIONS.get(key); - if (conditionContainer == null) { - logWarnLoading("Skipping condition: " + CITParsingException.descriptionOf("Unknown condition type", properties, value.position())); - return null; - } - - CITCondition condition = conditionContainer.createCondition.get(); - condition.load(value, properties); - return condition; - } - - public static CITType parseType(PropertyGroup properties) throws CITParsingException { - Identifier type = new Identifier("citresewn", "item"); - - PropertyValue propertiesType = properties.getLast("citresewn", "type"); - if (propertiesType != null) { - String value = propertiesType.value(); - if (!value.contains(":")) - value = "citresewn:" + value; - type = new Identifier(value); - } - - CITTypeContainer typeContainer = TYPES.get(type); - if (typeContainer == null) - // assert (propertiesType != null) because the default citresewn:item should always be registered - throw new UnknownCITTypeException(properties, propertiesType == null ? -1 : propertiesType.position()); - - return typeContainer.createType.get(); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITType.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITType.java deleted file mode 100644 index 4504c01..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITType.java +++ /dev/null @@ -1,10 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cit; - -import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; - -import java.util.List; - -public abstract class CITType { - public abstract void load(List conditions, PropertyGroup properties) throws CITParsingException; -} -- cgit