diff options
| author | SHsuperCM <shsupercm@gmail.com> | 2022-02-12 09:21:09 +0200 |
|---|---|---|
| committer | SHsuperCM <shsupercm@gmail.com> | 2022-02-12 09:21:09 +0200 |
| commit | d51ec9fd6cde3ad393d4d0c91e30cc5d03945eaf (patch) | |
| tree | 0f31635f43220e6a3ffcc9bc9390de7016242959 /src/main/java/shcm/shsupercm/fabric/citresewn/pack | |
| parent | ba570a6b2e37f6f45b149515cd41d10037cbda7f (diff) | |
| download | CITResewn-d51ec9fd6cde3ad393d4d0c91e30cc5d03945eaf.tar.gz CITResewn-d51ec9fd6cde3ad393d4d0c91e30cc5d03945eaf.tar.bz2 CITResewn-d51ec9fd6cde3ad393d4d0c91e30cc5d03945eaf.zip | |
More work on type registry/api
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack')
6 files changed, 73 insertions, 10 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java index d4f89f0..c9e2cf8 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java @@ -8,7 +8,7 @@ import shcm.shsupercm.fabric.citresewn.CITResewn; 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 shcm.shsupercm.fabric.citresewn.api.GlobalPropertiesHandler; +import shcm.shsupercm.fabric.citresewn.api.CITGlobalProperties; import java.io.IOException; import java.io.InputStream; @@ -37,7 +37,7 @@ public class GlobalProperties extends PropertyGroup { } public void callHandlers() { - for (EntrypointContainer<GlobalPropertiesHandler> container : FabricLoader.getInstance().getEntrypointContainers("citresewn:cit_global_properties", GlobalPropertiesHandler.class)) { + for (EntrypointContainer<CITGlobalProperties> container : FabricLoader.getInstance().getEntrypointContainers("citresewn:cit_global_properties", CITGlobalProperties.class)) { String containerNamespace = container.getProvider().getMetadata().getId(); if (containerNamespace.equals("citresewn-defaults")) containerNamespace = "citresewn"; 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 463d34a..4945120 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java @@ -41,7 +41,7 @@ public class PackParser { globalProperties.load(pack.getName(), identifier, pack.open(ResourceType.CLIENT_RESOURCES, identifier)); } catch (ResourceNotFoundException ignored) { } catch (IOException e) { - CITResewn.logErrorLoading("Errored while loading global properties: " + identifier + " in " + pack.getName()); + CITResewn.logErrorLoading("Errored while loading global properties: " + identifier + " from " + pack.getName()); e.printStackTrace(); } } 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 index f8df1ee..62f011e 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/ActiveCITs.java @@ -3,11 +3,11 @@ 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.Disposable; +import shcm.shsupercm.fabric.citresewn.api.CITDisposable; import shcm.shsupercm.fabric.citresewn.pack.GlobalProperties; import shcm.shsupercm.fabric.citresewn.pack.PackParser; -public class ActiveCITs implements Disposable { private ActiveCITs() {} +public class ActiveCITs implements CITDisposable { private ActiveCITs() {} private static ActiveCITs active = null; public static ActiveCITs getActive() { @@ -39,7 +39,7 @@ public class ActiveCITs implements Disposable { private ActiveCITs() {} @Override public void dispose() { - for (Disposable disposable : FabricLoader.getInstance().getEntrypoints(Disposable.ENTRYPOINT, Disposable.class)) + for (CITDisposable disposable : FabricLoader.getInstance().getEntrypoints(CITDisposable.ENTRYPOINT, CITDisposable.class)) disposable.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 index ee293ce..0eac632 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CIT.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CIT.java @@ -3,10 +3,10 @@ package shcm.shsupercm.fabric.citresewn.pack.cit; import net.minecraft.util.Identifier; public class CIT { - private final Identifier propertiesIdentifier; - private final String packName; - private final CITType type; - private final CITCondition[] conditions; + public final Identifier propertiesIdentifier; + public final String packName; + public final CITType type; + public final CITCondition[] conditions; public CIT(Identifier propertiesIdentifier, String packName, CITType type, CITCondition[] conditions) { this.propertiesIdentifier = propertiesIdentifier; @@ -14,4 +14,12 @@ public class CIT { this.type = type; this.conditions = conditions; } + + 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/CITRegistry.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITRegistry.java new file mode 100644 index 0000000..9dd423b --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cit/CITRegistry.java @@ -0,0 +1,48 @@ +package shcm.shsupercm.fabric.citresewn.pack.cit; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.util.Identifier; +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.PropertyValue; + +import java.util.HashMap; +import java.util.Map; + +import static shcm.shsupercm.fabric.citresewn.CITResewn.info; + +public class CITRegistry { + private static final Map<Identifier, CITTypeContainer<? extends CITType>> TYPES = new HashMap<>(); + + public static void registerAll() { + 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<? extends CITType>) entrypointContainer.getEntrypoint()); + } + } + + public static CITTypeContainer<? extends 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<? extends CITType> 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; + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java index 3864569..6955ac1 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java @@ -40,6 +40,13 @@ public abstract class PropertyGroup { return values; } + public PropertyValue getLast(String namespace, String... pathAliases) { + PropertyValue value = null; + for (Iterator<PropertyValue> iterator = get(namespace, pathAliases).iterator(); iterator.hasNext(); value = iterator.next()); + + return value; + } + public static PropertyGroup tryParseGroup(String packName, Identifier identifier, InputStream is) throws IOException { PropertyGroup group = null; if (identifier.getPath().endsWith(PropertiesGroupAdapter.EXTENSION)) |
