From f0322303f43825050d9761b45195978350ff1e0a Mon Sep 17 00:00:00 2001 From: SuperMartijn624 Date: Tue, 19 Dec 2023 02:03:06 +0100 Subject: [PATCH 1/8] Add null checking when checking tags --- src/main/java/com/supermartijn642/core/block/BaseBlock.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/supermartijn642/core/block/BaseBlock.java b/src/main/java/com/supermartijn642/core/block/BaseBlock.java index 86a9b7ac..e21b8475 100644 --- a/src/main/java/com/supermartijn642/core/block/BaseBlock.java +++ b/src/main/java/com/supermartijn642/core/block/BaseBlock.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.List; import java.util.Random; +import java.util.Set; import java.util.function.Consumer; /** @@ -273,7 +274,8 @@ public int getHarvestLevel(IBlockState state){ } private boolean is(ResourceLocation tag){ - return TagLoader.getTag(Registries.BLOCKS, tag).contains(Registries.BLOCKS.getIdentifier(this)); + Set blocks = TagLoader.getTag(Registries.BLOCKS, tag); + return blocks != null && blocks.contains(Registries.BLOCKS.getIdentifier(this)); } @Override From b081cbbd19bd98a8fec78802f14471d6719ce209 Mon Sep 17 00:00:00 2001 From: SuperMartijn624 Date: Tue, 19 Dec 2023 02:03:48 +0100 Subject: [PATCH 2/8] Update version --- changelog.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 2b754856..4e0a9037 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +### SuperMartijn642's Core Library 1.1.16a +- Fixed crash with Tool Progression + ### SuperMartijn642's Core Library 1.1.16 - Allow `ClientRegistrationHandler#registerAtlasSprite` to accept a different namespace diff --git a/gradle.properties b/gradle.properties index 5d19f9fd..dbd0814d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ coremod_class=CoreModPlugin mod_name=SuperMartijn642's Core Lib mod_description=SuperMartijn642's Core Lib adds lots of basic implementations for guis that allow for similar code between Minecraft 1.12, 1.14, 1.15, and 1.16! mod_id=supermartijn642corelib -mod_version=1.1.16 +mod_version=1.1.16a mod_license=All rights reserved mod_page=https://www.curseforge.com/minecraft/mc-mods/supermartijn642s-core-lib mod_sources=https://github.com/SuperMartijn642/SuperMartijn642sCoreLib From 40613496041fcbaab5d2826e1349084f5b64ec45 Mon Sep 17 00:00:00 2001 From: SuperMartijn624 Date: Sat, 10 Feb 2024 19:47:12 +0100 Subject: [PATCH 3/8] Update gradle-wrapper.properties --- gradle/wrapper/gradle-wrapper.properties | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 768ba834..f3f0da4f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://downloads.gradle-dn.com/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 82110533acd00722fdaaf1ca299265651da51081 Mon Sep 17 00:00:00 2001 From: SuperMartijn624 Date: Sat, 10 Feb 2024 01:15:20 +0100 Subject: [PATCH 4/8] Update .gitignore --- .gitignore | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a0dff286..9cd1bdb4 100644 --- a/.gitignore +++ b/.gitignore @@ -25,8 +25,10 @@ bin/ # macos *.DS_Store -# forge -forge*changelog.txt +# neoforge +runs +run-data +repo # other eclipse/ From 69d44340fad6535fe3e19adfb47cdede55164878 Mon Sep 17 00:00:00 2001 From: SuperMartijn624 Date: Mon, 12 Feb 2024 15:50:04 +0100 Subject: [PATCH 5/8] Add custom tag entries and fix tag loading behaviour --- .../com/supermartijn642/core/CoreLib.java | 4 + .../supermartijn642/core/data/TagLoader.java | 263 ++++++++---------- .../core/data/tag/CustomTagEntries.java | 89 ++++++ .../core/data/tag/CustomTagEntry.java | 31 +++ .../data/tag/CustomTagEntrySerializer.java | 13 + .../data/tag/entries/ElementTagEntry.java | 62 +++++ .../data/tag/entries/NamespaceTagEntry.java | 55 ++++ .../core/data/tag/entries/TagTagEntry.java | 67 +++++ .../core/generator/TagGenerator.java | 73 +++-- .../core/registry/RegistrationHandler.java | 21 ++ .../core/registry/Registries.java | 4 +- 11 files changed, 487 insertions(+), 195 deletions(-) create mode 100644 src/main/java/com/supermartijn642/core/data/tag/CustomTagEntries.java create mode 100644 src/main/java/com/supermartijn642/core/data/tag/CustomTagEntry.java create mode 100644 src/main/java/com/supermartijn642/core/data/tag/CustomTagEntrySerializer.java create mode 100644 src/main/java/com/supermartijn642/core/data/tag/entries/ElementTagEntry.java create mode 100644 src/main/java/com/supermartijn642/core/data/tag/entries/NamespaceTagEntry.java create mode 100644 src/main/java/com/supermartijn642/core/data/tag/entries/TagTagEntry.java diff --git a/src/main/java/com/supermartijn642/core/CoreLib.java b/src/main/java/com/supermartijn642/core/CoreLib.java index e4e9b792..ca5cd1de 100644 --- a/src/main/java/com/supermartijn642/core/CoreLib.java +++ b/src/main/java/com/supermartijn642/core/CoreLib.java @@ -2,6 +2,7 @@ import com.supermartijn642.core.data.TagLoader; import com.supermartijn642.core.data.condition.*; +import com.supermartijn642.core.data.tag.entries.NamespaceTagEntry; import com.supermartijn642.core.generator.GeneratorManager; import com.supermartijn642.core.generator.standard.CoreLibMiningTagGenerator; import com.supermartijn642.core.loot_table.SurvivesExplosionLootCondition; @@ -43,6 +44,9 @@ public CoreLib(){ handler.registerResourceConditionSerializer("and", AndResourceCondition.SERIALIZER); handler.registerResourceConditionSerializer("ore_dict_populated", OreDictPopulatedResourceCondition.SERIALIZER); + // Register custom tag entry types + handler.registerCustomTagEntrySerializer("namespace", NamespaceTagEntry.SERIALIZER); + // Register loot condition LootConditionManager.registerCondition(SurvivesExplosionLootCondition.SERIALIZER); LootConditionManager.registerCondition(ToolMatchLootCondition.SERIALIZER); diff --git a/src/main/java/com/supermartijn642/core/data/TagLoader.java b/src/main/java/com/supermartijn642/core/data/TagLoader.java index fe1d881b..5021a496 100644 --- a/src/main/java/com/supermartijn642/core/data/TagLoader.java +++ b/src/main/java/com/supermartijn642/core/data/TagLoader.java @@ -1,10 +1,9 @@ package com.supermartijn642.core.data; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; +import com.google.gson.*; import com.supermartijn642.core.CoreLib; +import com.supermartijn642.core.data.tag.CustomTagEntries; +import com.supermartijn642.core.data.tag.CustomTagEntry; import com.supermartijn642.core.registry.Registries; import com.supermartijn642.core.registry.RegistryUtil; import net.minecraft.util.ResourceLocation; @@ -41,9 +40,11 @@ public class TagLoader { } public static void loadTags(){ + for(Registries.Registry registry : TAG_TYPES.values()) + TAGS.put(registry, new HashMap<>()); Loader.instance().getActiveModList().forEach(TagLoader::loadTags); - CoreLib.LOGGER.info("Loaded '" + TAGS.getOrDefault(Registries.BLOCKS, Collections.emptyMap()).keySet().size() + "' block tags"); - CoreLib.LOGGER.info("Loaded '" + TAGS.getOrDefault(Registries.ITEMS, Collections.emptyMap()).keySet().size() + "' item tags"); + CoreLib.LOGGER.info("Loaded '" + TAGS.get(Registries.BLOCKS).keySet().size() + "' block tags"); + CoreLib.LOGGER.info("Loaded '" + TAGS.get(Registries.ITEMS).keySet().size() + "' item tags"); } private static void loadTags(ModContainer mod){ @@ -60,7 +61,7 @@ private static void loadTags(ModContainer mod){ if(source.isFile()){ try{ - fs = FileSystems.newFileSystem(source.toPath(), (ClassLoader)null); + fs = FileSystems.newFileSystem(source.toPath(), null); root = fs.getPath("/data"); }catch(IOException e){ CoreLib.LOGGER.error("Error loading FileSystem from jar!", e); @@ -80,32 +81,31 @@ private static void loadTags(ModContainer mod){ namespaceFolders = stream.filter(Predicate.isEqual(root).negate()).collect(Collectors.toList()); } - // Now go through all namespaces - for(Path namespaceFolder : namespaceFolders){ - if(!Files.isDirectory(namespaceFolder)) - continue; + // Go over the different registry types + for(Map.Entry> tagType : TAG_TYPES.entrySet()){ + // Keep track of the entries per tag + Map> entries = new HashMap<>(); + Map> removeEntries = new HashMap<>(); - String fileName = namespaceFolder.getFileName().toString(); - String namespace = fileName.endsWith("/") ? fileName.substring(0, fileName.length() - 1) : fileName; - if(!RegistryUtil.isValidNamespace(namespace)) - continue; + // First, go through all folder and read all tags + for(Path namespaceFolder : namespaceFolders){ + if(!Files.isDirectory(namespaceFolder)) + continue; + + String fileName = namespaceFolder.getFileName().toString(); + String namespace = fileName.endsWith("/") ? fileName.substring(0, fileName.length() - 1) : fileName; + if(!RegistryUtil.isValidNamespace(namespace)) + continue; - // Find the 'tags' folder - Path tagsFolder = namespaceFolder.resolve("tags"); - if(!Files.exists(tagsFolder) || !Files.isDirectory(tagsFolder)) - continue; + // Find the 'tags' folder + Path tagsFolder = namespaceFolder.resolve("tags"); + if(!Files.exists(tagsFolder) || !Files.isDirectory(tagsFolder)) + continue; - // Go over the different registry types - for(Map.Entry> tagType : TAG_TYPES.entrySet()){ Path tagTypeFolder = tagsFolder.resolve(tagType.getKey()); if(!Files.exists(tagTypeFolder) || !Files.isDirectory(tagTypeFolder)) continue; - // Keep track of references to other tags - Map> references = new HashMap<>(); - Map> optionalReferences = new HashMap<>(); - Map> removeEntries = new HashMap<>(); - // Now walk through all files in the folder to find jsons try(Stream paths = Files.walk(tagTypeFolder)){ paths.forEach( @@ -122,34 +122,44 @@ private static void loadTags(ModContainer mod){ } ResourceLocation fullIdentifier = new ResourceLocation(namespace, identifier); - readTagFile(mod, fullIdentifier, path, tagType.getKey(), tagType.getValue(), references.computeIfAbsent(fullIdentifier, f -> new HashSet<>()), optionalReferences.computeIfAbsent(fullIdentifier, f -> new HashSet<>()), removeEntries.computeIfAbsent(fullIdentifier, f -> new HashSet<>())); + readTagFile(mod, fullIdentifier, path, tagType.getKey(), tagType.getValue(), entries.computeIfAbsent(fullIdentifier, f -> new ArrayList<>()), removeEntries.computeIfAbsent(fullIdentifier, f -> new ArrayList<>())); } ); } + } - // Apply references TODO maybe move this to after all mods are done, depending on behaviour in 1.14+ - loop: - for(Map.Entry> entry : references.entrySet()){ - for(ResourceLocation reference : entry.getValue()){ - if(!TAGS.get(tagType.getValue()).containsKey(reference)){ - CoreLib.LOGGER.warn("Tag file '" + reference.getResourceDomain() + ":" + tagType.getKey() + "/" + reference.getResourcePath() + ".json' from mod '" + mod.getName() + "' references unknown tag '" + reference + "'!"); - TAGS.get(tagType.getValue()).get(entry.getKey()).clear(); - continue loop; - } + // Finally, resolve the tags + Stack dependencyStack = new Stack<>(); + //noinspection unchecked + Registries.Registry registry = (Registries.Registry)tagType.getValue(); + CustomTagEntry.TagEntryResolutionContext entryResolutionContext = new CustomTagEntry.TagEntryResolutionContext() { + @Override + public Object getElement(ResourceLocation identifier){ + return registry.getValue(identifier); + } - TAGS.get(tagType.getValue()).get(entry.getKey()).addAll(TAGS.get(tagType.getValue()).get(reference)); - } + @Override + public Collection getTag(ResourceLocation identifier){ + return TAGS.get(registry).get(identifier).stream().map(registry::getValue).collect(Collectors.toList()); } - for(Map.Entry> entry : optionalReferences.entrySet()){ - for(ResourceLocation reference : entry.getValue()){ - if(TAGS.get(tagType.getValue()).containsKey(reference)) - TAGS.get(tagType.getValue()).get(entry.getKey()).addAll(TAGS.get(tagType.getValue()).get(reference)); - } + + @Override + public Collection getAllElements(){ + return registry.getValues(); } - // Apply remove entries - for(Map.Entry> entry : removeEntries.entrySet()) - TAGS.get(tagType.getValue()).get(entry.getKey()).removeAll(entry.getValue()); + @Override + public Set getAllIdentifiers(){ + return registry.getIdentifiers(); + } + }; + while(!entries.isEmpty()){ + ResourceLocation tag = entries.keySet().stream().findAny().get(); + try{ + resolve(tag, entries, removeEntries, dependencyStack, registry, entryResolutionContext, mod); + }catch(JsonParseException e){ + CoreLib.LOGGER.error(e); + } } } }catch(IOException e){ @@ -159,7 +169,7 @@ private static void loadTags(ModContainer mod){ } } - private static void readTagFile(ModContainer mod, ResourceLocation identifier, Path file, String registryName, Registries.Registry registry, Set references, Set optionalReferences, Set removeEntries){ + private static void readTagFile(ModContainer mod, ResourceLocation identifier, Path file, String registryName, Registries.Registry registry, Collection entries, Collection removeEntries){ // Read the file contents as a json object JsonObject json; try(Reader reader = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8)){ @@ -172,147 +182,96 @@ private static void readTagFile(ModContainer mod, ResourceLocation identifier, P } // Add the tag if not present, do this here to prevent other tags referencing this from throwing an error - Set tagEntries = TAGS.computeIfAbsent(registry, r -> new HashMap<>()).computeIfAbsent(identifier, i -> new HashSet<>()); + Set tagEntries = TAGS.get(registry).computeIfAbsent(identifier, i -> new HashSet<>()); try{ // Check for replace flag - if(json.has("required") && (!json.get("required").isJsonPrimitive() || !json.get("required").getAsJsonPrimitive().isBoolean())) + if(json.has("replace") && (!json.get("replace").isJsonPrimitive() || !json.get("replace").getAsJsonPrimitive().isBoolean())) throw new RuntimeException("'replace' must be a boolean!"); boolean replace = json.has("replace") && json.get("replace").getAsBoolean(); if(replace) tagEntries.clear(); // Read the 'values' array - List entries = new ArrayList<>(); - List optionalEntries = new ArrayList<>(); if(json.has("values")){ if(!json.get("values").isJsonArray()) throw new RuntimeException("'values' must be an array!"); // Loop over the entries in 'values' json.get("values").getAsJsonArray().forEach( - element -> { - if(element.isJsonObject()){ - JsonObject object = element.getAsJsonObject(); - if(!object.has("id") || !object.get("id").isJsonPrimitive() || !object.get("id").getAsJsonPrimitive().isString()) - throw new RuntimeException("Entries in 'values' must contain key 'id'!"); - if(object.has("required") && (!object.get("required").isJsonPrimitive() || !object.get("required").getAsJsonPrimitive().isBoolean())) - throw new RuntimeException("Key 'required' for entries in 'values' must be a boolean!"); - - if(!object.has("required") || object.get("required").getAsBoolean()) - entries.add(element.getAsJsonObject().get("id").getAsString()); - else - optionalEntries.add(element.getAsJsonObject().get("id").getAsString()); - }else if(element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) - entries.add(element.getAsString()); - else - throw new RuntimeException("'values' must only contain objects and strings!"); - } + element -> entries.add(CustomTagEntries.deserialize(element)) ); } - // Move values starting with '#' into references - List rawReferences = new ArrayList<>(); - entries.stream().filter(s -> s.charAt(0) == '#').map(s -> s.substring(1)).forEach(rawReferences::add); - entries.removeIf(s -> s.charAt(0) == '#'); - List rawOptionalReferences = new ArrayList<>(); - optionalEntries.stream().filter(s -> s.charAt(0) == '#').map(s -> s.substring(1)).forEach(rawOptionalReferences::add); - optionalEntries.removeIf(s -> s.charAt(0) == '#'); - // Read the 'remove' array - List remove = new ArrayList<>(); - List optionalRemove = new ArrayList<>(); if(json.has("remove")){ if(!json.get("remove").isJsonArray()) throw new RuntimeException("'remove' must be an array!"); // Loop over the entries in 'remove' json.get("remove").getAsJsonArray().forEach( - element -> { - if(element.isJsonObject()){ - JsonObject object = element.getAsJsonObject(); - if(!object.has("id") || !object.get("id").isJsonPrimitive() || !object.get("id").getAsJsonPrimitive().isString()) - throw new RuntimeException("Entries in 'remove' must contain key 'id'!"); - if(object.has("required") && (!object.get("required").isJsonPrimitive() || !object.get("required").getAsJsonPrimitive().isBoolean())) - throw new RuntimeException("Key 'required' for entries in 'remove' must be a boolean!"); - - if(!object.has("required") || object.get("required").getAsBoolean()) - remove.add(element.getAsJsonObject().get("id").getAsString()); - else - optionalRemove.add(element.getAsJsonObject().get("id").getAsString()); - }else if(element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) - remove.add(element.getAsString()); - else - throw new RuntimeException("'remove' must only contain objects and strings!"); - } + element -> removeEntries.add(CustomTagEntries.deserialize(element)) ); } + }catch(Exception e){ + CoreLib.LOGGER.error("Encountered exception in tag json '" + identifier.getResourceDomain() + ":" + registryName + "/" + identifier.getResourcePath() + ".json' in mod '" + mod.getName() + "'!", e); + tagEntries.clear(); + entries.clear(); + removeEntries.clear(); + } + } - // Validate entries - for(String entry : entries){ - if(!RegistryUtil.isValidIdentifier(entry)) - throw new RuntimeException("'values' entry '" + entry + "' is not a valid identifier!"); - - ResourceLocation entryIdentifier = new ResourceLocation(entry); - if(!registry.hasIdentifier(entryIdentifier)) - throw new RuntimeException("Could not find a registered object for 'values' entry '" + entryIdentifier + "'!"); - - tagEntries.add(entryIdentifier); - } - - // Add optional entries - for(String entry : optionalEntries){ - if(!RegistryUtil.isValidIdentifier(entry)) - throw new RuntimeException("'values' optional entry '" + entry + "' is not a valid identifier!"); - - ResourceLocation entryIdentifier = new ResourceLocation(entry); - if(registry.hasIdentifier(entryIdentifier)) - tagEntries.add(entryIdentifier); - } - - // Add references - for(String reference : rawReferences){ - if(!RegistryUtil.isValidIdentifier(reference)) - throw new RuntimeException("'values' reference '#" + reference + "' is not a valid identifier!"); - - references.add(new ResourceLocation(reference)); - } - - // Add optional references - for(String reference : rawOptionalReferences){ - if(!RegistryUtil.isValidIdentifier(reference)) - throw new RuntimeException("'values' reference '#" + reference + "' is not a valid identifier!"); + private static void resolve(ResourceLocation tagIdentifier, Map> entries, Map> removeEntries, Stack dependencyStack, Registries.Registry registry, CustomTagEntry.TagEntryResolutionContext entryResolutionContext, ModContainer mod){ + // Check for circular dependencies + if(dependencyStack.contains(tagIdentifier)){ + TAGS.get(registry).get(tagIdentifier).clear(); + entries.remove(tagIdentifier); + removeEntries.remove(tagIdentifier); + throw new JsonParseException("Mod " + mod.getName() + " has contains a circular tag dependency: " + dependencyStack.stream().map(ResourceLocation::toString).map(s -> "'" + s + "'").collect(Collectors.joining(" -> "))); + } + dependencyStack.push(tagIdentifier); - optionalReferences.add(new ResourceLocation(reference)); + // Resolve dependencies first + try{ + for(Map.Entry> tag : entries.entrySet()){ + for(CustomTagEntry entry : tag.getValue()){ + Set dependencies = new HashSet<>(entry.getTagDependencies()); + for(ResourceLocation dependency : dependencies){ + if(entries.containsKey(dependency)) + resolve(dependency, entries, removeEntries, dependencyStack, registry, entryResolutionContext, mod); + } + } } + }catch(Exception e){ + TAGS.get(registry).get(tagIdentifier).clear(); + entries.remove(tagIdentifier); + removeEntries.remove(tagIdentifier); + dependencyStack.pop(); + throw e; + } - // Validate remove entries - for(String entry : remove){ - if(!RegistryUtil.isValidIdentifier(entry)) - throw new RuntimeException("'remove' entry '" + entry + "' is not a valid identifier!"); - - ResourceLocation entryIdentifier = new ResourceLocation(entry); - if(!registry.hasIdentifier(entryIdentifier)) - throw new RuntimeException("Could not find a registered object for 'remove' entry '" + entryIdentifier + "'!"); - - removeEntries.add(entryIdentifier); + try{ + // Add elements + for(CustomTagEntry entry : entries.get(tagIdentifier)){ + Collection elements = entry.resolve(entryResolutionContext); + if(elements != null) + TAGS.get(registry).get(tagIdentifier).addAll(elements.stream().map(registry::getIdentifier).collect(Collectors.toList())); } - // Add optional remove entries - for(String entry : optionalRemove){ - if(!RegistryUtil.isValidIdentifier(entry)) - throw new RuntimeException("'remove' optional entry '" + entry + "' is not a valid identifier!"); - - ResourceLocation entryIdentifier = new ResourceLocation(entry); - if(registry.hasIdentifier(entryIdentifier)) - removeEntries.add(entryIdentifier); + // Remove elements + for(CustomTagEntry entry : removeEntries.get(tagIdentifier)){ + Collection elements = entry.resolve(entryResolutionContext); + if(elements != null) + TAGS.get(registry).get(tagIdentifier).removeAll(elements.stream().map(registry::getIdentifier).collect(Collectors.toList())); } }catch(Exception e){ - CoreLib.LOGGER.error("Encountered exception in tag json '" + identifier.getResourceDomain() + ":" + registryName + "/" + identifier.getResourcePath() + ".json' in mod '" + mod.getName() + "'!", e); - tagEntries.clear(); - references.clear(); - optionalReferences.clear(); + CoreLib.LOGGER.error("Encountered exception in tag json '" + tagIdentifier.getResourceDomain() + ":" + registry.getRegistryIdentifier().getResourcePath() + "/" + tagIdentifier.getResourcePath() + ".json' in mod '" + mod.getName() + "'!", e); + TAGS.get(registry).get(tagIdentifier).clear(); } + + entries.remove(tagIdentifier); + removeEntries.remove(tagIdentifier); + dependencyStack.pop(); } public static Set getTag(Registries.Registry registry, ResourceLocation identifier){ diff --git a/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntries.java b/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntries.java new file mode 100644 index 00000000..e62cfded --- /dev/null +++ b/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntries.java @@ -0,0 +1,89 @@ +package com.supermartijn642.core.data.tag; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.supermartijn642.core.data.tag.entries.ElementTagEntry; +import com.supermartijn642.core.data.tag.entries.TagTagEntry; +import com.supermartijn642.core.registry.Registries; +import com.supermartijn642.core.registry.RegistryUtil; +import net.minecraft.util.ResourceLocation; + +/** + * Created 09/02/2024 by SuperMartijn642 + */ +public class CustomTagEntries { + + public static JsonElement serialize(CustomTagEntry entry){ + // Special case for vanilla standards + if(entry instanceof ElementTagEntry){ + if(((ElementTagEntry)entry).isRequired()){ + JsonObject json = new JsonObject(); + json.addProperty("id", ((ElementTagEntry)entry).getElementIdentifier().toString()); + json.addProperty("required", true); + return json; + } + return new JsonPrimitive(((ElementTagEntry)entry).getElementIdentifier().toString()); + }else if(entry instanceof TagTagEntry){ + if(((TagTagEntry)entry).isRequired()){ + JsonObject json = new JsonObject(); + json.addProperty("id", "#" + ((TagTagEntry)entry).getTagIdentifier()); + json.addProperty("required", true); + return json; + } + return new JsonPrimitive("#" + ((TagTagEntry)entry).getTagIdentifier()); + } + + JsonObject json = new JsonObject(); + CustomTagEntrySerializer serializer = entry.getSerializer(); + json.addProperty("type", Registries.CUSTOM_TAG_ENTRY_SERIALIZERS.getIdentifier(serializer).toString()); + try{ + //noinspection unchecked,rawtypes + ((CustomTagEntrySerializer)serializer).serialize(json, entry); + }catch(Exception e){ + throw new RuntimeException("Encountered an exception whilst serializing custom tag entry for type '" + Registries.CUSTOM_TAG_ENTRY_SERIALIZERS.getIdentifier(serializer).toString() + "'!"); + } + return json; + } + + public static CustomTagEntry deserialize(JsonElement input){ + // Special case for vanilla standards + if(input.isJsonPrimitive() && input.getAsJsonPrimitive().isString()){ + String s = input.getAsString(); + return s.startsWith("#") ? + new TagTagEntry(new ResourceLocation(s.substring(1)), true) : + new ElementTagEntry(new ResourceLocation(s), true); + } + + if(!(input instanceof JsonObject)) + throw new JsonParseException("Entry must be an object!"); + JsonObject json = (JsonObject)input; + + // Special case for vanilla standards + if(!json.has("type") || !json.get("type").isJsonPrimitive() || !json.getAsJsonPrimitive("type").isString()){ + if(!json.has("id") || !json.get("id").isJsonPrimitive() || !json.getAsJsonPrimitive("id").isString()) + throw new JsonParseException("Missing string field 'id'!"); + if(json.has("required") && (!json.get("required").isJsonPrimitive() || !json.get("required").getAsJsonPrimitive().isBoolean())) + throw new RuntimeException("Field 'required' must be a boolean!"); + boolean required = !json.has("required") || json.get("required").getAsBoolean(); + String s = json.get("id").getAsString(); + return s.startsWith("#") ? + new TagTagEntry(new ResourceLocation(s.substring(1)), required) : + new ElementTagEntry(new ResourceLocation(s), required); + } + + String typeString = json.get("type").getAsString(); + if(!RegistryUtil.isValidIdentifier(typeString)) + throw new JsonParseException("Invalid identifier '" + typeString + "'!"); + ResourceLocation type = new ResourceLocation(typeString); + if(!Registries.CUSTOM_TAG_ENTRY_SERIALIZERS.hasIdentifier(type)) + throw new JsonParseException("Unknown custom tag entry serializer '" + typeString + "'!"); + CustomTagEntrySerializer serializer = Registries.CUSTOM_TAG_ENTRY_SERIALIZERS.getValue(type); + try{ + return serializer.deserialize(json); + }catch(JsonParseException e){ + throw new RuntimeException("Encountered an exception whilst deserializing custom tag entry for type '" + type + "'!", e); + } + } +} diff --git a/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntry.java b/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntry.java new file mode 100644 index 00000000..df988180 --- /dev/null +++ b/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntry.java @@ -0,0 +1,31 @@ +package com.supermartijn642.core.data.tag; + +import net.minecraft.util.ResourceLocation; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +/** + * Created 09/02/2024 by SuperMartijn642 + */ +public interface CustomTagEntry { + + Collection resolve(TagEntryResolutionContext context); + + default Collection getTagDependencies(){ + return Collections.emptyList(); + } + + CustomTagEntrySerializer getSerializer(); + + interface TagEntryResolutionContext { + T getElement(ResourceLocation identifier); + + Collection getTag(ResourceLocation identifier); + + Collection getAllElements(); + + Set getAllIdentifiers(); + } +} diff --git a/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntrySerializer.java b/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntrySerializer.java new file mode 100644 index 00000000..a77c4ecb --- /dev/null +++ b/src/main/java/com/supermartijn642/core/data/tag/CustomTagEntrySerializer.java @@ -0,0 +1,13 @@ +package com.supermartijn642.core.data.tag; + +import com.google.gson.JsonObject; + +/** + * Created 09/02/2024 by SuperMartijn642 + */ +public interface CustomTagEntrySerializer { + + void serialize(JsonObject json, T entry); + + T deserialize(JsonObject json); +} diff --git a/src/main/java/com/supermartijn642/core/data/tag/entries/ElementTagEntry.java b/src/main/java/com/supermartijn642/core/data/tag/entries/ElementTagEntry.java new file mode 100644 index 00000000..880e4091 --- /dev/null +++ b/src/main/java/com/supermartijn642/core/data/tag/entries/ElementTagEntry.java @@ -0,0 +1,62 @@ +package com.supermartijn642.core.data.tag.entries; + +import com.google.gson.JsonObject; +import com.supermartijn642.core.data.tag.CustomTagEntry; +import com.supermartijn642.core.data.tag.CustomTagEntrySerializer; +import net.minecraft.util.ResourceLocation; + +import java.util.Collection; +import java.util.Collections; + +/** + * Created 11/02/2024 by SuperMartijn642 + */ +public class ElementTagEntry implements CustomTagEntry { + + public static final CustomTagEntrySerializer SERIALIZER = new Serializer(); + + private final ResourceLocation identifier; + private final boolean required; + + public ElementTagEntry(ResourceLocation identifier, boolean required){ + this.identifier = identifier; + this.required = required; + } + + public ResourceLocation getElementIdentifier(){ + return this.identifier; + } + + public boolean isRequired(){ + return this.required; + } + + @Override + public Collection resolve(TagEntryResolutionContext context){ + T element = context.getElement(this.identifier); + if(element == null && this.required) + throw new RuntimeException("Unknown identifier '" + this.identifier + "'!"); + return element == null ? null : Collections.singleton(element); + } + + @Override + public CustomTagEntrySerializer getSerializer(){ + return SERIALIZER; + } + + private static class Serializer implements CustomTagEntrySerializer { + @Override + public void serialize(JsonObject json, ElementTagEntry entry){ + json.addProperty("identifier", entry.identifier.toString()); + json.addProperty("required", entry.required); + } + + @Override + public ElementTagEntry deserialize(JsonObject json){ + return new ElementTagEntry( + new ResourceLocation(json.get("identifier").getAsString()), + !json.has("required") || json.get("required").getAsBoolean() + ); + } + } +} diff --git a/src/main/java/com/supermartijn642/core/data/tag/entries/NamespaceTagEntry.java b/src/main/java/com/supermartijn642/core/data/tag/entries/NamespaceTagEntry.java new file mode 100644 index 00000000..ae367d18 --- /dev/null +++ b/src/main/java/com/supermartijn642/core/data/tag/entries/NamespaceTagEntry.java @@ -0,0 +1,55 @@ +package com.supermartijn642.core.data.tag.entries; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.supermartijn642.core.data.tag.CustomTagEntry; +import com.supermartijn642.core.data.tag.CustomTagEntrySerializer; +import com.supermartijn642.core.registry.RegistryUtil; + +import java.util.Collection; +import java.util.stream.Collectors; + +/** + * Created 09/02/2024 by SuperMartijn642 + */ +public class NamespaceTagEntry implements CustomTagEntry { + + public static final CustomTagEntrySerializer SERIALIZER = new Serializer(); + + private final String namespace; + + public NamespaceTagEntry(String namespace){ + this.namespace = namespace; + } + + @Override + public Collection resolve(TagEntryResolutionContext context){ + return context.getAllIdentifiers().stream() + .filter(i -> i.getResourceDomain().equals(this.namespace)) + .map(context::getElement) + .collect(Collectors.toList()); + } + + @Override + public CustomTagEntrySerializer getSerializer(){ + return SERIALIZER; + } + + private static class Serializer implements CustomTagEntrySerializer { + + @Override + public void serialize(JsonObject json, NamespaceTagEntry entry){ + json.addProperty("namespace", entry.namespace); + } + + @Override + public NamespaceTagEntry deserialize(JsonObject json){ + if(!json.has("namespace") || !json.get("namespace").isJsonPrimitive() || !json.getAsJsonPrimitive("namespace").isString()) + throw new JsonParseException("Tag entry must have string key 'namespace'!"); + String namespace = json.get("namespace").getAsString(); + if(!RegistryUtil.isValidNamespace(namespace)) + throw new JsonParseException("Invalid namespace '" + namespace + "'!"); + return new NamespaceTagEntry(namespace); + } + } +} diff --git a/src/main/java/com/supermartijn642/core/data/tag/entries/TagTagEntry.java b/src/main/java/com/supermartijn642/core/data/tag/entries/TagTagEntry.java new file mode 100644 index 00000000..0a8f8df7 --- /dev/null +++ b/src/main/java/com/supermartijn642/core/data/tag/entries/TagTagEntry.java @@ -0,0 +1,67 @@ +package com.supermartijn642.core.data.tag.entries; + +import com.google.gson.JsonObject; +import com.supermartijn642.core.data.tag.CustomTagEntry; +import com.supermartijn642.core.data.tag.CustomTagEntrySerializer; +import net.minecraft.util.ResourceLocation; + +import java.util.Collection; +import java.util.Collections; + +/** + * Created 11/02/2024 by SuperMartijn642 + */ +public class TagTagEntry implements CustomTagEntry { + + public static final CustomTagEntrySerializer SERIALIZER = new Serializer(); + + private final ResourceLocation tag; + private final boolean required; + + public TagTagEntry(ResourceLocation tag, boolean required){ + this.tag = tag; + this.required = required; + } + + public ResourceLocation getTagIdentifier(){ + return this.tag; + } + + public boolean isRequired(){ + return this.required; + } + + @Override + public Collection resolve(TagEntryResolutionContext context){ + Collection tag = context.getTag(this.tag); + if(tag == null && this.required) + throw new RuntimeException("Unknown tag '" + this.tag + "'!"); + return tag; + } + + @Override + public Collection getTagDependencies(){ + return Collections.singleton(this.tag); + } + + @Override + public CustomTagEntrySerializer getSerializer(){ + return SERIALIZER; + } + + private static class Serializer implements CustomTagEntrySerializer { + @Override + public void serialize(JsonObject json, TagTagEntry entry){ + json.addProperty("tag", entry.tag.toString()); + json.addProperty("required", entry.required); + } + + @Override + public TagTagEntry deserialize(JsonObject json){ + return new TagTagEntry( + new ResourceLocation(json.get("tag").getAsString()), + !json.has("required") || json.get("required").getAsBoolean() + ); + } + } +} diff --git a/src/main/java/com/supermartijn642/core/generator/TagGenerator.java b/src/main/java/com/supermartijn642/core/generator/TagGenerator.java index 2cd65bd5..ff23b272 100644 --- a/src/main/java/com/supermartijn642/core/generator/TagGenerator.java +++ b/src/main/java/com/supermartijn642/core/generator/TagGenerator.java @@ -5,6 +5,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.supermartijn642.core.data.TagLoader; +import com.supermartijn642.core.data.tag.CustomTagEntries; +import com.supermartijn642.core.data.tag.CustomTagEntry; +import com.supermartijn642.core.data.tag.entries.ElementTagEntry; +import com.supermartijn642.core.data.tag.entries.TagTagEntry; import com.supermartijn642.core.generator.aggregator.ResourceAggregator; import com.supermartijn642.core.registry.Registries; import com.supermartijn642.core.registry.RegistryUtil; @@ -61,31 +65,12 @@ public void write(OutputStream stream, TagBuilder tag) throws IOException{ json.addProperty("replace", tag.replace); // Entries & references JsonArray entries = new JsonArray(); - tag.entries.forEach(entries::add); - tag.references.stream().map(ResourceLocation::toString).map(s -> "#" + s).forEach(entries::add); - tag.optionalEntries.stream().map(e -> { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("id", e); - jsonObject.addProperty("required", false); - return jsonObject; - }).forEach(entries::add); - tag.optionalReferences.stream().map(e -> { - JsonObject entryObject = new JsonObject(); - entryObject.addProperty("id", "#" + e); - entryObject.addProperty("required", false); - return entryObject; - }).forEach(entries::add); - if(entries.size() > 0 || tag.remove.isEmpty()) + tag.entries.forEach(entry -> entries.add(CustomTagEntries.serialize(entry))); + if(entries.size() == 0 || tag.remove.isEmpty()) json.add("values", entries); // Removed JsonArray removedEntries = new JsonArray(); - tag.remove.forEach(removedEntries::add); - tag.optionalRemove.stream().map(e -> { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("id", e); - jsonObject.addProperty("required", false); - return jsonObject; - }).forEach(entries::add); + tag.remove.forEach(entry -> removedEntries.add(CustomTagEntries.serialize(entry))); if(removedEntries.size() > 0) json.add("remove", removedEntries); @@ -110,7 +95,10 @@ public void save(){ // Loop over all tags for(TagBuilder tag : registryEntry.getValue().values()){ // Validate tag references - for(ResourceLocation reference : tag.references){ + for(CustomTagEntry entry : tag.entries){ + if(!(entry instanceof TagTagEntry)) + continue; + ResourceLocation reference = ((TagTagEntry)entry).getTagIdentifier(); if(registryEntry.getValue().containsKey(reference)) continue; if(TagLoader.getTag(registryEntry.getKey(), reference) != null) @@ -292,12 +280,8 @@ protected static class TagBuilder { private final Registries.Registry registry; protected final ResourceLocation identifier; - private final Set entries = new HashSet<>(); - private final Set optionalEntries = new HashSet<>(); - private final Set references = new HashSet<>(); - private final Set optionalReferences = new HashSet<>(); - private final Set remove = new HashSet<>(); - private final Set optionalRemove = new HashSet<>(); + private final Set entries = new HashSet<>(); + private final Set remove = new HashSet<>(); private boolean replace; protected TagBuilder(Registries.Registry registry, ResourceLocation identifier){ @@ -326,7 +310,7 @@ public TagBuilder replace(){ * @param entry entry to be added */ public TagBuilder add(T entry){ - this.entries.add(this.registry.getIdentifier(entry).toString()); + this.entries.add(new ElementTagEntry(this.registry.getIdentifier(entry), true)); return this; } @@ -338,7 +322,7 @@ public TagBuilder add(ResourceLocation entry){ if(!this.registry.hasIdentifier(entry)) throw new RuntimeException("Could not find any object registered under '" + entry + "'!"); - this.entries.add(entry.toString()); + this.entries.add(new ElementTagEntry(entry, true)); return this; } @@ -374,7 +358,7 @@ public TagBuilder add(String entry){ * @param entry entry to be added */ public TagBuilder addOptional(T entry){ - this.optionalEntries.add(this.registry.getIdentifier(entry).toString()); + this.entries.add(new ElementTagEntry(this.registry.getIdentifier(entry), false)); return this; } @@ -383,7 +367,7 @@ public TagBuilder addOptional(T entry){ * @param entry entry to be added */ public TagBuilder addOptional(ResourceLocation entry){ - this.optionalEntries.add(entry.toString()); + this.entries.add(new ElementTagEntry(entry, false)); return this; } @@ -414,6 +398,15 @@ public TagBuilder addOptional(String entry){ return this; } + /** + * Adds an optional custom entry to this tag. + * @param entry entry to be added + */ + public TagBuilder addOptional(CustomTagEntry entry){ + this.entries.add(entry); + return this; + } + /** * Adds a reference to the given tag. */ @@ -421,7 +414,7 @@ public TagBuilder addReference(ResourceLocation tag){ if(this.identifier.equals(tag)) throw new IllegalArgumentException("Cannot add self reference to tag '" + tag + "'!"); - this.references.add(tag); + this.entries.add(new TagTagEntry(tag, true)); return this; } @@ -456,7 +449,7 @@ public TagBuilder addOptionalReference(ResourceLocation tag){ if(this.identifier.equals(tag)) throw new IllegalArgumentException("Cannot add self reference to tag '" + tag + "'!"); - this.optionalReferences.add(tag.toString()); + this.entries.add(new TagTagEntry(tag, false)); return this; } @@ -489,7 +482,7 @@ public TagBuilder addOptionalReference(String tag){ * @param entry entry to be removed */ public TagBuilder remove(T entry){ - this.remove.add(this.registry.getIdentifier(entry).toString()); + this.remove.add(new ElementTagEntry(this.registry.getIdentifier(entry), true)); return this; } @@ -501,7 +494,7 @@ public TagBuilder remove(ResourceLocation entry){ if(!this.registry.hasIdentifier(entry)) throw new RuntimeException("Could not find any object registered under '" + entry + "'!"); - this.remove.add(entry.toString()); + this.remove.add(new ElementTagEntry(entry, true)); return this; } @@ -545,7 +538,7 @@ public TagBuilder removeOptional(T entry){ * @param entry entry to be removed */ public TagBuilder removeOptional(ResourceLocation entry){ - this.optionalRemove.add(entry.toString()); + this.remove.add(new ElementTagEntry(entry, false)); return this; } @@ -578,11 +571,7 @@ public TagBuilder removeOptional(String entry){ private void addAll(TagBuilder other){ this.entries.addAll(other.entries); - this.optionalEntries.addAll(other.optionalEntries); - this.references.addAll(other.references); - this.optionalReferences.addAll(other.optionalReferences); this.remove.addAll(other.remove); - this.optionalRemove.addAll(other.optionalRemove); } } } diff --git a/src/main/java/com/supermartijn642/core/registry/RegistrationHandler.java b/src/main/java/com/supermartijn642/core/registry/RegistrationHandler.java index c960d76b..1f4cfd6e 100644 --- a/src/main/java/com/supermartijn642/core/registry/RegistrationHandler.java +++ b/src/main/java/com/supermartijn642/core/registry/RegistrationHandler.java @@ -3,6 +3,7 @@ import com.supermartijn642.core.CoreLib; import com.supermartijn642.core.block.BaseBlockEntityType; import com.supermartijn642.core.data.condition.ResourceConditionSerializer; +import com.supermartijn642.core.data.tag.CustomTagEntrySerializer; import com.supermartijn642.core.gui.BaseContainerType; import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; @@ -363,6 +364,26 @@ public > X registerOverride(String name })); } + public void registerCustomTagEntrySerializer(String identifier, Supplier> serializer){ + this.addEntry(Registries.CUSTOM_TAG_ENTRY_SERIALIZERS, identifier, serializer); + } + + public void registerCustomTagEntrySerializer(String identifier, CustomTagEntrySerializer serializer){ + this.addEntry(Registries.CUSTOM_TAG_ENTRY_SERIALIZERS, identifier, () -> serializer); + } + + public void registerCustomTagEntrySerializerOverride(String namespace, String identifier, Supplier> serializer){ + this.addEntry(Registries.CUSTOM_TAG_ENTRY_SERIALIZERS, namespace, identifier, serializer); + } + + public void registerCustomTagEntrySerializerOverride(String namespace, String identifier, CustomTagEntrySerializer serializer){ + this.addEntry(Registries.CUSTOM_TAG_ENTRY_SERIALIZERS, namespace, identifier, () -> serializer); + } + + public void registerCustomTagEntrySerializerCallback(Consumer>> callback){ + this.addCallback(Registries.CUSTOM_TAG_ENTRY_SERIALIZERS, callback); + } + private void addEntry(Registries.Registry registry, String identifier, Supplier entry){ this.addEntry(registry, this.modid, identifier, entry); } diff --git a/src/main/java/com/supermartijn642/core/registry/Registries.java b/src/main/java/com/supermartijn642/core/registry/Registries.java index 4332bdb3..7ce9de5f 100644 --- a/src/main/java/com/supermartijn642/core/registry/Registries.java +++ b/src/main/java/com/supermartijn642/core/registry/Registries.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import com.supermartijn642.core.CommonUtils; import com.supermartijn642.core.block.BaseBlockEntityType; +import com.supermartijn642.core.data.tag.CustomTagEntrySerializer; import com.supermartijn642.core.extensions.RegistrySimpleExtension; import com.supermartijn642.core.gui.BaseContainerType; import com.supermartijn642.core.util.MappedSetView; @@ -108,13 +109,14 @@ public void register(ResourceLocation identifier, Item object){ public static final Registry> BLOCK_ENTITY_CLASSES = vanilla(new ResourceLocation("block_entities"), TileEntity.REGISTRY, Class.class); public static final Registry> MENU_TYPES = new MapBackedRegistry<>(new ResourceLocation("supermartijn642corelib", "container_types"), BaseContainerType.class); public static final Registry RECIPE_CONDITION_SERIALIZERS = new RecipeConditionSerializerRegistry(); + public static final Registry> CUSTOM_TAG_ENTRY_SERIALIZERS = new MapBackedRegistry<>(new ResourceLocation("supermartijn642corelib", "custom_tag_entries"), CustomTagEntrySerializer.class); static{ ((RecipeConditionSerializerRegistry)RECIPE_CONDITION_SERIALIZERS).initializeMap(); // Add all registries which don't have a forge registry REGISTRATION_ORDER_MAP.put(ITEMS, Lists.newArrayList(BLOCK_ENTITY_TYPES, BLOCK_ENTITY_CLASSES, FLUIDS)); - REGISTRATION_ORDER_MAP.put(ENTITY_TYPES, Lists.newArrayList(MENU_TYPES)); + REGISTRATION_ORDER_MAP.put(ENTITY_TYPES, Lists.newArrayList(MENU_TYPES, CUSTOM_TAG_ENTRY_SERIALIZERS)); } private static Registry vanilla(ResourceLocation identifier, IRegistry registry, Class valueClass){ From 937fa6a276061110d203fa1414a951e933f4f469 Mon Sep 17 00:00:00 2001 From: SuperMartijn624 Date: Mon, 12 Feb 2024 16:05:36 +0100 Subject: [PATCH 6/8] Add workaround for side `BUKKIT` errors --- .../core/mixin/NetworkRegistryMixin.java | 42 +++++++++++++++++++ src/main/resources/modid.mixins.json | 1 + 2 files changed, 43 insertions(+) create mode 100644 src/main/java/com/supermartijn642/core/mixin/NetworkRegistryMixin.java diff --git a/src/main/java/com/supermartijn642/core/mixin/NetworkRegistryMixin.java b/src/main/java/com/supermartijn642/core/mixin/NetworkRegistryMixin.java new file mode 100644 index 00000000..d5ae2170 --- /dev/null +++ b/src/main/java/com/supermartijn642/core/mixin/NetworkRegistryMixin.java @@ -0,0 +1,42 @@ +package com.supermartijn642.core.mixin; + +import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.relauncher.Side; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * Created 12/02/2024 by SuperMartijn642 + */ +@Mixin(value = NetworkRegistry.class, remap = false) +public class NetworkRegistryMixin { + + @Unique + private static final Side[] SIDES = {Side.CLIENT, Side.SERVER}; + + @Redirect( + method = "newChannel(Ljava/lang/String;[Lio/netty/channel/ChannelHandler;)Ljava/util/EnumMap;", + at = @At( + value = "INVOKE", + target = "Lnet/minecraftforge/fml/relauncher/Side;values()[Lnet/minecraftforge/fml/relauncher/Side;" + ), + require = 0 + ) + private Side[] replaceSides(){ + return SIDES; + } + + @Redirect( + method = "newChannel(Lnet/minecraftforge/fml/common/ModContainer;Ljava/lang/String;[Lio/netty/channel/ChannelHandler;)Ljava/util/EnumMap;", + at = @At( + value = "INVOKE", + target = "Lnet/minecraftforge/fml/relauncher/Side;values()[Lnet/minecraftforge/fml/relauncher/Side;" + ), + require = 0 + ) + private Side[] replaceSides2(){ + return SIDES; + } +} diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/modid.mixins.json index 4f9cc5bb..e33e98ab 100644 --- a/src/main/resources/modid.mixins.json +++ b/src/main/resources/modid.mixins.json @@ -27,6 +27,7 @@ "LootPoolSerializerMixin", "MinMaxBoundsMixin", "NBTPredicateMixin", + "NetworkRegistryMixin", "OredictItemPredicateMixin", "OreIngredientMixin", "PlayerEntityMixin", From 88ca7e397a4ba0080a18f1eef942dc35672bee95 Mon Sep 17 00:00:00 2001 From: SuperMartijn624 Date: Sun, 11 Feb 2024 14:12:06 +0100 Subject: [PATCH 7/8] Update version --- changelog.md | 6 ++++++ gradle.properties | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 4e0a9037..3cb6a3ee 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +### SuperMartijn642's Core Library 1.1.17 +- Added support for custom tag entry types +- Added a namespace tag entry type +- Added workaround for side `BUKKIT` related errors +- Updated tag loading behaviour to match newer Minecraft versions + ### SuperMartijn642's Core Library 1.1.16a - Fixed crash with Tool Progression diff --git a/gradle.properties b/gradle.properties index dbd0814d..8761bf85 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ coremod_class=CoreModPlugin mod_name=SuperMartijn642's Core Lib mod_description=SuperMartijn642's Core Lib adds lots of basic implementations for guis that allow for similar code between Minecraft 1.12, 1.14, 1.15, and 1.16! mod_id=supermartijn642corelib -mod_version=1.1.16a +mod_version=1.1.17 mod_license=All rights reserved mod_page=https://www.curseforge.com/minecraft/mc-mods/supermartijn642s-core-lib mod_sources=https://github.com/SuperMartijn642/SuperMartijn642sCoreLib From bceabefc7baf7795b906190dc8c275fbfecec08d Mon Sep 17 00:00:00 2001 From: OptimusZeGaming Date: Tue, 28 May 2024 09:52:46 +0200 Subject: [PATCH 8/8] build: update mixin 8.3 to 8.5 :arrow_up: --- build.gradle | 83 +--------------------------------------------------- 1 file changed, 1 insertion(+), 82 deletions(-) diff --git a/build.gradle b/build.gradle index bc1f619f..5dc71fe0 100644 --- a/build.gradle +++ b/build.gradle @@ -8,10 +8,7 @@ buildscript { classpath "org.spongepowered:mixingradle:0.7.+" } } -plugins { - id "com.matthewprenger.cursegradle" version "1.4.0" - id "com.modrinth.minotaur" version "2.+" -} + apply plugin: "net.minecraftforge.gradle" apply plugin: "eclipse" apply plugin: "org.spongepowered.mixin" @@ -28,9 +25,6 @@ println("Java: " + System.getProperty("java.version") + " JVM: " + System.getPro compileJava.options.compilerArgs.add '-parameters' repositories { - maven { - url "https://www.cursemaven.com" - } maven { url = "https://repo.spongepowered.org/maven" } @@ -209,73 +203,6 @@ tasks.whenTaskAdded { it.dependsOn "prepareDataResources" } -// CurseGradle settings for uploading to CurseForge -curseforge { - project { - // Get the CurseForge token from the environment variables - apiKey = System.getenv("CURSEFORGE_TOKEN") - // Copy settings from gradle.properties - id = project.curseforge_project_id - releaseType = project.curseforge_release_type - project.curseforge_game_versions.split(" ").each it::addGameVersion - addGameVersion("Forge") - addGameVersion("NeoForge") - // Point to 'changelog' setting to a the changelog file - changelog = file("changelog.md") - changelogType = "markdown" - if (!project.curseforge_required_dependency_ids.isEmpty() || !project.curseforge_optional_dependency_ids.isEmpty()) { - relations { - // Required dependencies - if (!project.curseforge_required_dependency_ids.isEmpty()) - project.curseforge_required_dependency_ids.split(" ").each it::requiredDependency - // Optional dependencies - if (!project.curseforge_optional_dependency_ids.isEmpty()) - project.curseforge_optional_dependency_ids.split(" ").each it::optionalDependency - } - } - - mainArtifact(file('build/renamedLibs/_' + jar.getArchiveFileName().get())) { - displayName = "${project.mod_name} ${project.mod_version} for Forge ${project.minecraft_suffix.substring(2)}" - } - } - options { - // Don't add project Java version - javaVersionAutoDetect = false - } -} - -// Move CurseGradle's tasks from 'upload' to 'publishing' -project.gradle.taskGraph.whenReady { - tasks.stream().filter(task -> task.group.equals "upload").each { task -> task.group = "publishing" } -} - -// Minotaur settings for uploading to Modrinth -modrinth { - // Get the Modrinth token from the environment variables - token = System.getenv("MODRINTH_TOKEN") - // Copy settings from gradle.properties - projectId = project.modrinth_project_id - versionNumber = version - versionType = project.modrinth_release_type // Can be either 'release', 'alpha', or 'beta' - versionName = "${project.mod_name} ${project.mod_version}" - gameVersions = project.modrinth_game_versions.split(" ") as List - // Convert the changelog file to text - changelog = file("changelog.md").text - uploadFile = file('build/renamedLibs/_' + jar.getArchiveFileName().get()) - // With Loom, this MUST be set to `remapJar` instead of `jar`! - loaders = ["forge", "neoforge"] - if (!project.modrinth_required_dependency_ids.isEmpty() || !project.modrinth_optional_dependency_ids.isEmpty()) { - dependencies { - // Required dependencies - if (!project.modrinth_required_dependency_ids.isEmpty()) - project.modrinth_required_dependency_ids.split(" ").each required::project - // Optional dependencies - if (!project.modrinth_optional_dependency_ids.isEmpty()) - project.modrinth_optional_dependency_ids.split(" ").each optional::project - } - } -} - // Create task which copies from 'jar', but renames the file tasks.register('renameJar', Copy) { dependsOn build @@ -284,11 +211,3 @@ tasks.register('renameJar', Copy) { rename "_"::concat } jar.finalizedBy renameJar - -// Create a task to upload to both CurseForge and Modrinth -task publishAll { - group "publishing" - dependsOn("curseforge", "modrinth") - // Also build the file so I have a copy locally - dependsOn "build" -}