From 8cafc0729775aa8321b68e10de6a3953333b1392 Mon Sep 17 00:00:00 2001 From: Layla Silbernberg / LadySilver47 <119636966+LaylaSilbernberg@users.noreply.github.com> Date: Sun, 5 Nov 2023 00:37:51 +0100 Subject: [PATCH] Added missing enchantables to material tags (#9888) --- patches/api/0153-Add-Material-Tags.patch | 15 +++-- patches/server/0004-Test-changes.patch | 42 +++++++++++++- patches/server/0013-Paper-Plugins.patch | 4 +- .../server/1046-Add-MaterialTagsTest.patch | 58 +++++++++++++++++++ 4 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 patches/server/1046-Add-MaterialTagsTest.patch diff --git a/patches/api/0153-Add-Material-Tags.patch b/patches/api/0153-Add-Material-Tags.patch index ef2f0502dd..7ffc6ee166 100644 --- a/patches/api/0153-Add-Material-Tags.patch +++ b/patches/api/0153-Add-Material-Tags.patch @@ -7,7 +7,8 @@ This adds a bunch of useful and missing Tags to be able to identify items that are related to each other by a trait. Co-authored-by: Jake Potrebic -Co-authored by: Lena Kolb +Co-authored-by: Lena Kolb +Co-authored-by: Layla Silbernberg diff --git a/src/main/java/com/destroystokyo/paper/MaterialSetTag.java b/src/main/java/com/destroystokyo/paper/MaterialSetTag.java new file mode 100644 @@ -114,10 +115,10 @@ index 0000000000000000000000000000000000000000..a02a02aa0c87e0f0ed9e509e4dcab015 +} diff --git a/src/main/java/com/destroystokyo/paper/MaterialTags.java b/src/main/java/com/destroystokyo/paper/MaterialTags.java new file mode 100644 -index 0000000000000000000000000000000000000000..0b92f3279fe5dcbea77b22803447b7ad21ef999f +index 0000000000000000000000000000000000000000..f59151cec84fc0e300a8d759c6d74a804cbd047f --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/MaterialTags.java -@@ -0,0 +1,704 @@ +@@ -0,0 +1,708 @@ +/* + * Copyright (c) 2018 Daniel Ennis (Aikar) MIT License + * @@ -682,8 +683,12 @@ index 0000000000000000000000000000000000000000..0b92f3279fe5dcbea77b22803447b7ad + */ + public static final MaterialSetTag ENCHANTABLE = new MaterialSetTag(keyFor("enchantable")) + .add(PICKAXES, SWORDS, SHOVELS, AXES, HOES, HELMETS, CHEST_EQUIPPABLE, LEGGINGS, BOOTS, BOWS) -+ .add(Material.TRIDENT, Material.SHIELD, Material.FISHING_ROD, Material.SHEARS, Material.FLINT_AND_STEEL, Material.CARROT_ON_A_STICK, Material.WARPED_FUNGUS_ON_A_STICK) -+ .ensureSize("ENCHANTABLE", 65).lock(); ++ .add(Material.TRIDENT, Material.SHIELD, Material.FISHING_ROD, Material.SHEARS, ++ Material.FLINT_AND_STEEL, Material.CARROT_ON_A_STICK, Material.WARPED_FUNGUS_ON_A_STICK, ++ Material.BRUSH, Material.CARVED_PUMPKIN, Material.COMPASS, Material.SKELETON_SKULL, ++ Material.WITHER_SKELETON_SKULL, Material.PLAYER_HEAD, Material.ZOMBIE_HEAD, ++ Material.CREEPER_HEAD, Material.DRAGON_HEAD, Material.PIGLIN_HEAD) ++ .ensureSize("ENCHANTABLE", 75).lock(); + + /** + * Covers the variants of raw ores. diff --git a/patches/server/0004-Test-changes.patch b/patches/server/0004-Test-changes.patch index 80539ed829..887c73f6aa 100644 --- a/patches/server/0004-Test-changes.patch +++ b/patches/server/0004-Test-changes.patch @@ -21,11 +21,48 @@ index ff4d0f970990187e9b46324b5cf051fcc546119f..844eff88c9ad95871900c2d8aa3136b3 publishing { publications.create("maven") { artifact(tasks.shadowJar) +diff --git a/src/test/java/io/papermc/paper/util/EmptyTag.java b/src/test/java/io/papermc/paper/util/EmptyTag.java +new file mode 100644 +index 0000000000000000000000000000000000000000..6eb95a5e2534974c0e52e2b78b04e7c2b2f28525 +--- /dev/null ++++ b/src/test/java/io/papermc/paper/util/EmptyTag.java +@@ -0,0 +1,31 @@ ++package io.papermc.paper.util; ++ ++import java.util.Collections; ++import java.util.Set; ++import org.bukkit.Keyed; ++import org.bukkit.NamespacedKey; ++import org.bukkit.Tag; ++import org.jetbrains.annotations.NotNull; ++ ++public record EmptyTag(NamespacedKey key) implements Tag { ++ ++ @SuppressWarnings("deprecation") ++ public EmptyTag() { ++ this(NamespacedKey.randomKey()); ++ } ++ ++ @Override ++ public @NotNull NamespacedKey getKey() { ++ return this.key; ++ } ++ ++ @Override ++ public boolean isTagged(@NotNull final Keyed item) { ++ return false; ++ } ++ ++ @Override ++ public @NotNull Set getValues() { ++ return Collections.emptySet(); ++ } ++} diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java -index d96efc9aa90debcca5f237c949ba11b10070223a..efa4452cd20231051cdac1b497d7bfafb72bed78 100644 +index d96efc9aa90debcca5f237c949ba11b10070223a..d1253a07a90aa4cc29d0140795203a71118c827a 100644 --- a/src/test/java/org/bukkit/support/DummyServer.java +++ b/src/test/java/org/bukkit/support/DummyServer.java -@@ -38,6 +38,14 @@ public final class DummyServer { +@@ -38,6 +38,15 @@ public final class DummyServer { when(instance.getRegistry(any())).then(mock -> CraftRegistry.createRegistry(mock.getArgument(0), AbstractTestingBase.REGISTRY_CUSTOM)); @@ -35,6 +72,7 @@ index d96efc9aa90debcca5f237c949ba11b10070223a..efa4452cd20231051cdac1b497d7bfaf + + final org.bukkit.plugin.PluginManager pluginManager = new org.bukkit.plugin.SimplePluginManager(instance, new org.bukkit.command.SimpleCommandMap(instance)); + when(instance.getPluginManager()).thenReturn(pluginManager); ++ when(instance.getTag(anyString(), any(org.bukkit.NamespacedKey.class), any())).thenAnswer(ignored -> new io.papermc.paper.util.EmptyTag()); + // paper end - testing additions + Bukkit.setServer(instance); diff --git a/patches/server/0013-Paper-Plugins.patch b/patches/server/0013-Paper-Plugins.patch index 4507a81829..8cacf14b4b 100644 --- a/patches/server/0013-Paper-Plugins.patch +++ b/patches/server/0013-Paper-Plugins.patch @@ -7892,7 +7892,7 @@ index 0000000000000000000000000000000000000000..ba271c35eb2804f94cfc893bf94affb9 + } +} diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java -index efa4452cd20231051cdac1b497d7bfafb72bed78..1f6f055805454d7c0f726c9feef57578482c003a 100644 +index d1253a07a90aa4cc29d0140795203a71118c827a..c20d5ed12efed109f3702a994188ac4af66c8b9a 100644 --- a/src/test/java/org/bukkit/support/DummyServer.java +++ b/src/test/java/org/bukkit/support/DummyServer.java @@ -42,7 +42,7 @@ public final class DummyServer { @@ -7902,5 +7902,5 @@ index efa4452cd20231051cdac1b497d7bfafb72bed78..1f6f055805454d7c0f726c9feef57578 - final org.bukkit.plugin.PluginManager pluginManager = new org.bukkit.plugin.SimplePluginManager(instance, new org.bukkit.command.SimpleCommandMap(instance)); + final org.bukkit.plugin.PluginManager pluginManager = new io.papermc.paper.plugin.manager.PaperPluginManagerImpl(instance, new org.bukkit.command.SimpleCommandMap(instance), null); when(instance.getPluginManager()).thenReturn(pluginManager); + when(instance.getTag(anyString(), any(org.bukkit.NamespacedKey.class), any())).thenAnswer(ignored -> new io.papermc.paper.util.EmptyTag()); // paper end - testing additions - diff --git a/patches/server/1046-Add-MaterialTagsTest.patch b/patches/server/1046-Add-MaterialTagsTest.patch new file mode 100644 index 0000000000..34233ba1ca --- /dev/null +++ b/patches/server/1046-Add-MaterialTagsTest.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shane Freeder +Date: Sat, 4 Nov 2023 18:39:18 -0400 +Subject: [PATCH] Add MaterialTagsTest + + +diff --git a/src/test/java/io/papermc/paper/inventory/item/MaterialTagsTest.java b/src/test/java/io/papermc/paper/inventory/item/MaterialTagsTest.java +new file mode 100644 +index 0000000000000000000000000000000000000000..3f2734eae2053b4b8fccd7149178699e36ce8b78 +--- /dev/null ++++ b/src/test/java/io/papermc/paper/inventory/item/MaterialTagsTest.java +@@ -0,0 +1,46 @@ ++package io.papermc.paper.inventory.item; ++ ++import com.destroystokyo.paper.MaterialTags; ++import it.unimi.dsi.fastutil.objects.ObjectArrayList; ++import java.util.List; ++import java.util.stream.Collectors; ++import java.util.stream.Stream; ++import net.minecraft.core.registries.BuiltInRegistries; ++import net.minecraft.world.item.Item; ++import net.minecraft.world.item.enchantment.EnchantmentCategory; ++import org.bukkit.craftbukkit.util.CraftMagicNumbers; ++import org.bukkit.support.AbstractTestingBase; ++import org.jetbrains.annotations.NotNull; ++import org.junit.jupiter.api.Assertions; ++import org.junit.jupiter.params.ParameterizedTest; ++import org.junit.jupiter.params.provider.MethodSource; ++ ++public class MaterialTagsTest extends AbstractTestingBase { ++ ++ private final static EnchantmentCategory[] ENCHANTMENT_CATEGORIES = EnchantmentCategory.values(); ++ ++ @ParameterizedTest ++ @MethodSource("items") ++ public void testEnchantables(@NotNull final Item item) { ++ final List enchantableCategories = new ObjectArrayList<>(); ++ for (final EnchantmentCategory enchantmentCategory : ENCHANTMENT_CATEGORIES) { ++ if (enchantmentCategory.canEnchant(item)) enchantableCategories.add(enchantmentCategory); ++ } ++ ++ final boolean taggedAsEnchantable = MaterialTags.ENCHANTABLE.isTagged(CraftMagicNumbers.getMaterial(item)); ++ final boolean requiresTagByInternals = !enchantableCategories.isEmpty(); ++ Assertions.assertEquals( ++ requiresTagByInternals, ++ taggedAsEnchantable, ++ () -> "%s matches enchantment categories [%s] but was tagged by material tags as enchantable: %s".formatted( ++ item.getDescriptionId(), ++ enchantableCategories.stream().map(Enum::name).collect(Collectors.joining(", ")), ++ taggedAsEnchantable ++ ) ++ ); ++ } ++ ++ private static Stream items() { ++ return BuiltInRegistries.ITEM.stream(); ++ } ++}