3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 19:10:09 +01:00
Paper/patches/server/0975-Adopt-MaterialRerouting.patch
Bjarne Koll 3b9db2b194
Updated Upstream (Bukkit/CraftBukkit) (#11501)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
bb4e97c6 Add support for Java 23
bc6874dd Bump asm to 9.7.1
50e8a00b PR-1064: Add specific getTopInventory methods for InventoryView derivatives
758b0a0f SPIGOT-7911: Fix Location#isWorldLoaded() for re-loaded worlds
133a64a7 Improve Registry#getOrThrow messages
be0f5957 PR-1058: Add tests for Minecraft registry <-> Bukkit fields
d1b31df2 PR-1062: Clarify BeaconView documentation
3fab4384 PR-1060: Cache Material to BlockType and ItemType conversion
967a7301 SPIGOT-7906: Increase YAML nesting limit to 100
6ecf033d SPIGOT-7899: Smithing recipes don't require inputs

CraftBukkit Changes:
0a7bd6c81 PR-1493: Improve reroute performance and add some tests
54941524c Add support for Java 23
f4d957fff SPIGOT-7915: Fix World#getKeepSpawnInMemory() using Spawn Radius rather than Spawn Chunk Radius
ded183674 Fix HIDE_ENCHANTS flag in items without enchantments
308785a0a Bump asm to 9.7.1 and re-add ClassReader to ClassWriter
72ce823cd PR-1487: Add specific getTopInventory methods for InventoryView derivatives
11a5e840c SPIGOT-7907, PR-1484: Improve merchant recipe item matching behavior to more closely align with older versions
45b66f7e4 SPIGOT-7909: Always set HIDE_ENCHANTS flag to item if flag is set
963459791 Increase outdated build delay
fc5b2d75f SPIGOT-7910: Fix launching breeze wind charge from API and improve dispenser launch API
c7d6428f2 SPIGOT-7856, PR-1483: End platform not dropping items after replacing blocks
2a5572b52 SPIGOT-7780, PR-1482: Cannot edit chunks during unload event
527041ab5 SPIGOT-7902, PR-1477: Fix CraftMetaPotion#hasCustomEffects() does not check if customEffects (List) is empty
5529a1769 Implement base methods for tags
30fbdbaaf Improve Registry#getOrThrow messages
6b71a7322 PR-1475: Add tests for Minecraft registry <-> Bukkit fields
5f24c255c SPIGOT-7908: Mark junit-platform-suite-engine as test scope
e4c92ef65 PR-1473: Change tests to use suites, to run tests in different environments and feature flags
d25e1e722 PR-1481: Fix BeaconView#set[X]Effect(null)
d69a05362 PR-1480: Fix PerMaterialTest#isEdible test running for legacy materials
bb3284a89 PR-1479: Use custom #isBlock method in legacy init instead of the one in Material, since it relies on legacy being init
98c57cbbe SPIGOT-7904: Fix NPE for PlayerItemBreakEvent
f35bae9ec Fix missing hasJukeboxPlayable
8a6f8b6d8 SPIGOT-7881: CTRL+Pick Block saves position data into item
7913b3be7 SPIGOT-7899: Smithing recipes don't require inputs
2024-10-21 00:06:54 +02:00

135 Zeilen
7.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bjarne Koll <lynxplay101@gmail.com>
Date: Thu, 13 Jun 2024 11:02:36 +0200
Subject: [PATCH] Adopt MaterialRerouting
Adopts the paper-api to the material rerouting infrastructure introduced
by upstream.
diff --git a/src/main/java/org/bukkit/craftbukkit/legacy/MaterialRerouting.java b/src/main/java/org/bukkit/craftbukkit/legacy/MaterialRerouting.java
index 3ff0f0e34356cee4c510fdd60af723b1c5df156a..6cc9d7a9e6d4bfdc27e52fc581b2bb832616f121 100644
--- a/src/main/java/org/bukkit/craftbukkit/legacy/MaterialRerouting.java
+++ b/src/main/java/org/bukkit/craftbukkit/legacy/MaterialRerouting.java
@@ -600,4 +600,82 @@ public class MaterialRerouting {
public static void setBlocks(ToolComponent.ToolRule toolRule, Collection<Material> blocks) {
toolRule.setBlocks(blocks.stream().map(MaterialRerouting::transformToBlockType).toList());
}
+
+ // Paper start - register paper API specific material consumers in rerouting
+ // A lot of these methods do *not* run through MaterialRerouting to avoid the overhead of a system that
+ // currently is an effective noop.
+ // The only downside is that upstream moved the handling of legacy materials into transformFromXType methods.
+ // As such, methods introduced prior to 1.13 need to run through the transformation to make sure legacy material
+ // constants still work.
+
+ // Utility method for constructing a set from an existing one after mapping each element.
+ private static <I, O> Set<O> mapSet(final Set<I> input, final java.util.function.Function<I,O> mapper) {
+ final Set<O> output = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>(input.size());
+ for (final I i : input) {
+ output.add(mapper.apply(i));
+ }
+ return output;
+ }
+
+ // Method added post-1.13, noop (https://github.com/PaperMC/Paper/pull/4965)
+ public static org.bukkit.Material getMinecartMaterial(org.bukkit.entity.Minecart minecart, @InjectPluginVersion ApiVersion version) {
+ return minecart.getMinecartMaterial();
+ }
+
+ // Method added post-1.13, noop (https://github.com/PaperMC/Paper/pull/4965)
+ public static Material getBoatMaterial(Boat boat, @InjectPluginVersion ApiVersion version) {
+ return boat.getBoatMaterial();
+ }
+
+ // Method added post-1.13, noop (https://github.com/PaperMC/Paper/pull/3807)
+ public static Material getType(io.papermc.paper.event.player.PlayerItemCooldownEvent event, @InjectPluginVersion ApiVersion version) {
+ return event.getType();
+ }
+
+ // Method added post-1.13, noop (https://github.com/PaperMC/Paper/pull/3850)
+ public static Collection<Material> getInfiniburn(World world, @InjectPluginVersion ApiVersion version) {
+ return world.getInfiniburn();
+ }
+
+ // Method added pre-1.13, needs legacy rerouting (https://github.com/PaperMC/Paper/commit/3438e96192)
+ public static Set<Material> getTypes(
+ final com.destroystokyo.paper.event.player.PlayerArmorChangeEvent.SlotType slotType,
+ @InjectPluginVersion final ApiVersion apiVersion
+ ) {
+ if (apiVersion.isNewerThanOrSameAs(ApiVersion.FLATTENING)) return slotType.getTypes();
+ else return mapSet(slotType.getTypes(), MaterialRerouting::transformToItemType); // Needed as pre-flattening is hanled by transformToItemType
+ }
+
+ // Method added pre-1.13, needs legacy rerouting (https://github.com/PaperMC/Paper/commit/3438e96192)
+ @RerouteStatic("com/destroystokyo/paper/event/player/PlayerArmorChangeEvent$SlotType")
+ public static com.destroystokyo.paper.event.player.PlayerArmorChangeEvent.SlotType getByMaterial(
+ final Material material
+ ) {
+ return com.destroystokyo.paper.event.player.PlayerArmorChangeEvent.SlotType.getByMaterial(MaterialRerouting.transformToItemType(material));
+ }
+
+ // Method added pre-1.13, needs legacy rerouting (https://github.com/PaperMC/Paper/commit/3438e96192)
+ @RerouteStatic("com/destroystokyo/paper/event/player/PlayerArmorChangeEvent$SlotType")
+ public static boolean isEquipable(final Material material) {
+ return com.destroystokyo.paper.event.player.PlayerArmorChangeEvent.SlotType.isEquipable(MaterialRerouting.transformToItemType(material));
+ }
+
+ // Method added post 1.13, no-op (https://github.com/PaperMC/Paper/pull/1244)
+ public static Material getMaterial(final com.destroystokyo.paper.event.block.AnvilDamagedEvent.DamageState damageState) {
+ return damageState.getMaterial();
+ }
+
+ // Method added post 1.13, no-op (https://github.com/PaperMC/Paper/pull/1244)
+ @RerouteStatic("com/destroystokyo/paper/event/block/AnvilDamagedEvent$DamageState")
+ public static com.destroystokyo.paper.event.block.AnvilDamagedEvent.DamageState getState(
+ final Material material
+ ) {
+ return com.destroystokyo.paper.event.block.AnvilDamagedEvent.DamageState.getState(material);
+ }
+
+ // Method added post 1.13, no-op (https://github.com/PaperMC/Paper/pull/10290)
+ public static ItemStack withType(final ItemStack itemStack, final Material material) {
+ return itemStack.withType(material);
+ }
+ // Paper end - register paper API specific material consumers in rerouting
}
diff --git a/src/test/java/org/bukkit/craftbukkit/legacy/MaterialReroutingTest.java b/src/test/java/org/bukkit/craftbukkit/legacy/MaterialReroutingTest.java
index cd03ea1f726894161ca786e7e7d00d04716405d3..329eeb174180b5d90b071247dac5459e4ffe3be3 100644
--- a/src/test/java/org/bukkit/craftbukkit/legacy/MaterialReroutingTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/legacy/MaterialReroutingTest.java
@@ -56,6 +56,9 @@ public class MaterialReroutingTest {
.filter(entry -> !entry.getName().endsWith("ItemType.class"))
.filter(entry -> !entry.getName().endsWith("Registry.class"))
.filter(entry -> !entry.getName().startsWith("org/bukkit/material"))
+ // Paper start - types that cannot be translated to ItemType/BlockType
+ .filter(entry -> !entry.getName().equals("com/destroystokyo/paper/MaterialSetTag.class"))
+ // Paper end - types that cannot be translated to ItemType/BlockType
.map(entry -> {
try {
return MaterialReroutingTest.jarFile.getInputStream(entry);
@@ -93,6 +96,10 @@ public class MaterialReroutingTest {
continue;
}
}
+ // Paper start - filter out more methods from rerouting test
+ if (methodNode.name.startsWith("lambda$")) continue;
+ if (isInternal(methodNode.invisibleAnnotations)) continue;
+ // Paper end - filter out more methods from rerouting test
if (!Commodore.rerouteMethods(ApiVersion.CURRENT, MaterialReroutingTest.MATERIAL_METHOD_REROUTE, (methodNode.access & Opcodes.ACC_STATIC) != 0, classNode.name, methodNode.name, methodNode.desc, a -> { })) {
missingReroute.add(methodNode.name + " " + methodNode.desc + " " + methodNode.signature);
@@ -109,6 +116,13 @@ public class MaterialReroutingTest {
}
}
+ // Paper start - filter out more methods from rerouting test
+ private static boolean isInternal(final List<org.objectweb.asm.tree.AnnotationNode> annotationNodes) {
+ return annotationNodes != null
+ && annotationNodes.stream().anyMatch(a -> a.desc.equals("Lorg/jetbrains/annotations/ApiStatus$Internal;"));
+ }
+ // Paper end - filter out more methods from rerouting test
+
@AfterAll
public static void clear() throws IOException {
if (MaterialReroutingTest.jarFile != null) {