mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
Added missing enchantables to material tags (#9888)
This commit is contained in:
parent
e289accb03
commit
8cafc07297
4 changed files with 110 additions and 9 deletions
|
@ -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 <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
|
||||
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.
|
||||
|
|
|
@ -21,11 +21,48 @@ index ff4d0f970990187e9b46324b5cf051fcc546119f..844eff88c9ad95871900c2d8aa3136b3
|
|||
publishing {
|
||||
publications.create<MavenPublication>("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<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
|
||||
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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
58
patches/server/1046-Add-MaterialTagsTest.patch
Normal file
58
patches/server/1046-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..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<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();
|
||||
+ }
|
||||
+}
|
Loading…
Reference in a new issue