From 702c90574d0537d0cf4822d432753bfe7ee95348 Mon Sep 17 00:00:00 2001 From: Nightenom <17338378+Nightenom@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:56:23 +0200 Subject: [PATCH] Adjust nbt matching --- .../compatibility/itemnbtmatching.json | 25 +------- .../core/generation/ItemNbtCalculator.java | 61 +++++++++++-------- 2 files changed, 38 insertions(+), 48 deletions(-) diff --git a/src/datagen/generated/minecolonies/data/minecolonies/compatibility/itemnbtmatching.json b/src/datagen/generated/minecolonies/data/minecolonies/compatibility/itemnbtmatching.json index 93084104710..9f489aa0e1e 100644 --- a/src/datagen/generated/minecolonies/data/minecolonies/compatibility/itemnbtmatching.json +++ b/src/datagen/generated/minecolonies/data/minecolonies/compatibility/itemnbtmatching.json @@ -967,8 +967,7 @@ { "checkednbtkeys": [ "minecraft:enchantments", - "minecraft:max_damage", - "structurize:pos_selection" + "minecraft:max_damage" ], "item": "minecolonies:scan_analyzer" }, @@ -2503,14 +2502,12 @@ }, { "checkednbtkeys": [ - "minecraft:enchantment_glint_override", "minecraft:stored_enchantments" ], "item": "minecraft:enchanted_book" }, { "checkednbtkeys": [ - "minecraft:enchantment_glint_override", "minecraft:food" ], "item": "minecraft:enchanted_golden_apple" @@ -2519,9 +2516,6 @@ "item": "minecraft:enchanting_table" }, { - "checkednbtkeys": [ - "minecraft:enchantment_glint_override" - ], "item": "minecraft:end_crystal" }, { @@ -2567,9 +2561,6 @@ "item": "minecraft:evoker_spawn_egg" }, { - "checkednbtkeys": [ - "minecraft:enchantment_glint_override" - ], "item": "minecraft:experience_bottle" }, { @@ -3682,9 +3673,6 @@ "item": "minecraft:nether_sprouts" }, { - "checkednbtkeys": [ - "minecraft:enchantment_glint_override" - ], "item": "minecraft:nether_star" }, { @@ -5465,9 +5453,6 @@ "item": "structurize:blocktagsubstitution" }, { - "checkednbtkeys": [ - "structurize:pos_selection" - ], "item": "structurize:caliper" }, { @@ -5476,18 +5461,14 @@ { "checkednbtkeys": [ "minecraft:enchantments", - "minecraft:max_damage", - "structurize:pos_selection", - "structurize:scan_tool" + "minecraft:max_damage" ], "item": "structurize:sceptersteel" }, { "checkednbtkeys": [ "minecraft:enchantments", - "minecraft:max_damage", - "structurize:pos_selection", - "structurize:tags" + "minecraft:max_damage" ], "item": "structurize:sceptertag" }, diff --git a/src/main/java/com/minecolonies/core/generation/ItemNbtCalculator.java b/src/main/java/com/minecolonies/core/generation/ItemNbtCalculator.java index 334010e430d..629a3dfedb1 100644 --- a/src/main/java/com/minecolonies/core/generation/ItemNbtCalculator.java +++ b/src/main/java/com/minecolonies/core/generation/ItemNbtCalculator.java @@ -7,9 +7,12 @@ import com.ldtteam.domumornamentum.block.IMateriallyTexturedBlockComponent; import com.ldtteam.domumornamentum.client.model.data.MaterialTextureData; import com.ldtteam.domumornamentum.client.model.data.MaterialTextureData.Builder; +import com.minecolonies.api.items.component.ModDataComponents; import com.minecolonies.api.util.CraftingUtils; +import it.unimi.dsi.fastutil.objects.ReferenceArraySet; import net.minecraft.core.HolderLookup; -import net.minecraft.core.component.TypedDataComponent; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.CachedOutput; import net.minecraft.data.DataProvider; @@ -84,50 +87,56 @@ public CompletableFuture run(@NotNull final CachedOutput cache) allStacks = listBuilder.build(); final TreeMap> keyMapping = new TreeMap<>(); + final Set> typesToRemove = new ReferenceArraySet<>(); + + // We ignore damage in nbt. + typesToRemove.add(DataComponents.DAMAGE); + + // The following we don't care about matching. + typesToRemove.add(DataComponents.LORE); + typesToRemove.add(DataComponents.MAX_STACK_SIZE); + typesToRemove.add(DataComponents.RARITY); + typesToRemove.add(DataComponents.ENCHANTMENT_GLINT_OVERRIDE); + ModDataComponents.REGISTRY.getEntries().forEach(t -> typesToRemove.add(t.get())); + com.ldtteam.structurize.component.ModDataComponents.REGISTRY.getEntries().forEach(t -> typesToRemove.add(t.get())); + for (final ItemStack stack : allStacks) { final ResourceLocation resourceLocation = stack.getItemHolder().unwrapKey().get().location(); - final Set keys = new TreeSet<>(); - for (final TypedDataComponent key : stack.getComponents()) - { - keys.add(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(key.type()).toString()); - } + final Set> keys = new ReferenceArraySet<>(stack.getComponents().keySet()); if (stack.getItem() instanceof ArmorItem) { - keys.add("minecraft:dyed_color"); + keys.add(DataComponents.DYED_COLOR); } if (!stack.isEnchantable()) { - keys.remove("minecraft:enchantments"); + keys.remove(DataComponents.ENCHANTMENTS); } if (!stack.isRepairable()) { - keys.remove("minecraft:repair_cost"); + keys.remove(DataComponents.REPAIR_COST); } if (stack.getAttributeModifiers().modifiers().isEmpty()) { - keys.remove("minecraft:attribute_modifiers"); + keys.remove(DataComponents.ATTRIBUTE_MODIFIERS); } - // We ignore damage in nbt. - keys.remove("minecraft:damage"); + keys.removeAll(typesToRemove); + + keyMapping.compute(resourceLocation.toString(), (k, keysInMap) -> { + if (keysInMap == null) + { + keysInMap = new TreeSet<>(); + } - // The following we don't care about matching. - keys.remove("minecraft:lore"); - keys.remove("minecraft:max_stack_size"); - keys.remove("minecraft:rarity"); + for (final DataComponentType type : keys) + { + keysInMap.add(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(type).toString()); + } - if (keyMapping.containsKey(resourceLocation.toString())) - { - final Set list = keyMapping.get(resourceLocation.toString()); - list.addAll(keys); - keyMapping.put(resourceLocation.toString(), list); - } - else - { - keyMapping.put(resourceLocation.toString(), keys); - } + return keysInMap; + }); } final Path path = packOutput.createPathProvider(PackOutput.Target.DATA_PACK, "compatibility").file(new ResourceLocation(MOD_ID, "itemnbtmatching"), "json");