aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1053-Adopt-MaterialRerouting.patch
blob: e628afe53a941d104daecf8e0834df868895fbcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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..2ea35134bdb04244739ac6740242d4e4ec62623a 100644
--- a/src/main/java/org/bukkit/craftbukkit/legacy/MaterialRerouting.java
+++ b/src/main/java/org/bukkit/craftbukkit/legacy/MaterialRerouting.java
@@ -600,4 +600,22 @@ 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
+    public static org.bukkit.Material getMinecartMaterial(org.bukkit.entity.Minecart minecart, @InjectPluginVersion ApiVersion version) {
+        return minecart.getMinecartMaterial();
+    }
+
+    public static Material getBoatMaterial(Boat boat, @InjectPluginVersion ApiVersion version) {
+        return boat.getBoatMaterial();
+    }
+
+    public static Material getType(io.papermc.paper.event.player.PlayerItemCooldownEvent event, @InjectPluginVersion ApiVersion version) {
+        return event.getType();
+    }
+
+    public static Collection<Material> getInfiniburn(World world, @InjectPluginVersion ApiVersion version) {
+        return world.getInfiniburn();
+    }
+    // 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 26208ca74688be062584824de5d074321b33f1b1..946cd46f3389a4d4ceda86e0115c59c5725a8a0a 100644
--- a/src/test/java/org/bukkit/craftbukkit/legacy/MaterialReroutingTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/legacy/MaterialReroutingTest.java
@@ -55,6 +55,9 @@ public class MaterialReroutingTest extends AbstractTestingBase {
                 .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);
@@ -92,6 +95,10 @@ public class MaterialReroutingTest extends AbstractTestingBase {
                             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(Collections.emptySet(), 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);
@@ -108,6 +115,13 @@ public class MaterialReroutingTest extends AbstractTestingBase {
         }
     }
 
+    // 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) {