mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-05 06:32:17 -07:00
Added missing enchantables to material tags (#9888)
This commit is contained in:
@@ -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.
|
are related to each other by a trait.
|
||||||
|
|
||||||
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||||
Co-authored by: Lena Kolb <lenakolb2204@gmail.com>
|
Co-authored-by: Lena Kolb <lenakolb2204@gmail.com>
|
||||||
|
Co-authored-by: Layla Silbernberg <livsilbernberg@gmail.com>
|
||||||
|
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/MaterialSetTag.java b/src/main/java/com/destroystokyo/paper/MaterialSetTag.java
|
diff --git a/src/main/java/com/destroystokyo/paper/MaterialSetTag.java b/src/main/java/com/destroystokyo/paper/MaterialSetTag.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
@@ -682,8 +683,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ */
|
+ */
|
||||||
+ public static final MaterialSetTag ENCHANTABLE = new MaterialSetTag(keyFor("enchantable"))
|
+ public static final MaterialSetTag ENCHANTABLE = new MaterialSetTag(keyFor("enchantable"))
|
||||||
+ .add(PICKAXES, SWORDS, SHOVELS, AXES, HOES, HELMETS, CHEST_EQUIPPABLE, LEGGINGS, BOOTS, BOWS)
|
+ .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)
|
+ .add(Material.TRIDENT, Material.SHIELD, Material.FISHING_ROD, Material.SHEARS,
|
||||||
+ .ensureSize("ENCHANTABLE", 65).lock();
|
+ 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.
|
+ * Covers the variants of raw ores.
|
||||||
|
58
patches/server/Add-MaterialTagsTest.patch
Normal file
58
patches/server/Add-MaterialTagsTest.patch
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Shane Freeder <theboyetronic@gmail.com>
|
||||||
|
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..0000000000000000000000000000000000000000
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/test/java/io/papermc/paper/inventory/item/MaterialTagsTest.java
|
||||||
|
@@ -0,0 +0,0 @@
|
||||||
|
+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<EnchantmentCategory> 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<Item> items() {
|
||||||
|
+ return BuiltInRegistries.ITEM.stream();
|
||||||
|
+ }
|
||||||
|
+}
|
@@ -7902,5 +7902,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
- 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 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);
|
+ 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.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
|
// paper end - testing additions
|
||||||
|
|
||||||
|
@@ -21,6 +21,43 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
publishing {
|
publishing {
|
||||||
publications.create<MavenPublication>("maven") {
|
publications.create<MavenPublication>("maven") {
|
||||||
artifact(tasks.shadowJar)
|
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..0000000000000000000000000000000000000000
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/test/java/io/papermc/paper/util/EmptyTag.java
|
||||||
|
@@ -0,0 +0,0 @@
|
||||||
|
+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<Keyed> {
|
||||||
|
+
|
||||||
|
+ @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<Keyed> getValues() {
|
||||||
|
+ return Collections.emptySet();
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java
|
diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/test/java/org/bukkit/support/DummyServer.java
|
--- a/src/test/java/org/bukkit/support/DummyServer.java
|
||||||
@@ -35,6 +72,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ 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 org.bukkit.plugin.SimplePluginManager(instance, new org.bukkit.command.SimpleCommandMap(instance));
|
||||||
+ when(instance.getPluginManager()).thenReturn(pluginManager);
|
+ 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
|
+ // paper end - testing additions
|
||||||
+
|
+
|
||||||
Bukkit.setServer(instance);
|
Bukkit.setServer(instance);
|
||||||
|
Reference in New Issue
Block a user