Skip to content

Commit

Permalink
Adjust nbt matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightenom committed Aug 25, 2024
1 parent 95135d9 commit 702c905
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,7 @@
{
"checkednbtkeys": [
"minecraft:enchantments",
"minecraft:max_damage",
"structurize:pos_selection"
"minecraft:max_damage"
],
"item": "minecolonies:scan_analyzer"
},
Expand Down Expand Up @@ -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"
Expand All @@ -2519,9 +2516,6 @@
"item": "minecraft:enchanting_table"
},
{
"checkednbtkeys": [
"minecraft:enchantment_glint_override"
],
"item": "minecraft:end_crystal"
},
{
Expand Down Expand Up @@ -2567,9 +2561,6 @@
"item": "minecraft:evoker_spawn_egg"
},
{
"checkednbtkeys": [
"minecraft:enchantment_glint_override"
],
"item": "minecraft:experience_bottle"
},
{
Expand Down Expand Up @@ -3682,9 +3673,6 @@
"item": "minecraft:nether_sprouts"
},
{
"checkednbtkeys": [
"minecraft:enchantment_glint_override"
],
"item": "minecraft:nether_star"
},
{
Expand Down Expand Up @@ -5465,9 +5453,6 @@
"item": "structurize:blocktagsubstitution"
},
{
"checkednbtkeys": [
"structurize:pos_selection"
],
"item": "structurize:caliper"
},
{
Expand All @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,50 +87,56 @@ public CompletableFuture<?> run(@NotNull final CachedOutput cache)
allStacks = listBuilder.build();

final TreeMap<String, Set<String>> keyMapping = new TreeMap<>();
final Set<DataComponentType<?>> 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<String> keys = new TreeSet<>();
for (final TypedDataComponent<?> key : stack.getComponents())
{
keys.add(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(key.type()).toString());
}
final Set<DataComponentType<?>> 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<String> 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");
Expand Down

0 comments on commit 702c905

Please sign in to comment.