From 2e6eafb7e87497f3823098a16365518ce629cca3 Mon Sep 17 00:00:00 2001 From: Abel <56084910+Abelkrijgtalles@users.noreply.github.com> Date: Sat, 9 Nov 2024 23:22:01 +0100 Subject: [PATCH] Improve Minecart#getMinecartMaterial (#11544) Removes the hardcoded lookup in favour of calling the AbstractVehicle getItemDrop method. --- ...et-Material-from-Boats-and-Minecarts.patch | 27 +++++++++---------- patches/server/0763-Friction-API.patch | 6 ++--- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/patches/server/0448-API-to-get-Material-from-Boats-and-Minecarts.patch b/patches/server/0448-API-to-get-Material-from-Boats-and-Minecarts.patch index d3e0aece3c..25467e469e 100644 --- a/patches/server/0448-API-to-get-Material-from-Boats-and-Minecarts.patch +++ b/patches/server/0448-API-to-get-Material-from-Boats-and-Minecarts.patch @@ -6,6 +6,16 @@ Subject: [PATCH] API to get Material from Boats and Minecarts == AT == public net.minecraft.world.entity.vehicle.AbstractBoat getDropItem()Lnet/minecraft/world/item/Item; +diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java +index fb9f0a62201dfeccd0eec9bb399f9edc6a01f1f0..d01a588aea379c962dd63f1428f92cf2442f4d45 100644 +--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java ++++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java +@@ -717,4 +717,5 @@ public abstract class AbstractMinecart extends VehicleEntity { + this.derailedZ = derailed.getZ(); + } + // CraftBukkit end ++ public net.minecraft.world.item.Item publicGetDropItem() { return getDropItem(); } // Paper - api to get boat and minecart material - expose public drop item + } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java index c101d01b55472efc9fc2829b8c17db5377ed57ff..5d51a49228eaee94f91cd04843e27c7918ca8796 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java @@ -25,7 +35,7 @@ index c101d01b55472efc9fc2829b8c17db5377ed57ff..5d51a49228eaee94f91cd04843e27c79 public Status getStatus() { return CraftBoat.boatStatusFromNms(this.getHandle().status); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java -index c4db7c00c66e064993b8b2158f226d063eea798c..8192ccb01ed4efe9e987cab94952c172ed876581 100644 +index c4db7c00c66e064993b8b2158f226d063eea798c..e02ecbdc158311bdc7e4d13307de6e2a2cf54235 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java @@ -4,6 +4,7 @@ import net.minecraft.server.level.ServerLevel; @@ -36,25 +46,14 @@ index c4db7c00c66e064993b8b2158f226d063eea798c..8192ccb01ed4efe9e987cab94952c172 import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.block.data.CraftBlockData; -@@ -69,6 +70,24 @@ public abstract class CraftMinecart extends CraftVehicle implements Minecart { +@@ -69,6 +70,13 @@ public abstract class CraftMinecart extends CraftVehicle implements Minecart { this.getHandle().setDerailedVelocityMod(derailed); } + // Paper start + @Override + public Material getMinecartMaterial() { -+ return CraftMagicNumbers.getMaterial(minecartEntityTypeToMaterial(this.getHandle().getType())); -+ } -+ -+ static net.minecraft.world.item.Item minecartEntityTypeToMaterial(final net.minecraft.world.entity.EntityType type) { -+ if (type == net.minecraft.world.entity.EntityType.MINECART) return net.minecraft.world.item.Items.MINECART; -+ else if (type == net.minecraft.world.entity.EntityType.CHEST_MINECART) return net.minecraft.world.item.Items.CHEST_MINECART; -+ else if (type == net.minecraft.world.entity.EntityType.FURNACE_MINECART) return net.minecraft.world.item.Items.FURNACE_MINECART; -+ else if (type == net.minecraft.world.entity.EntityType.SPAWNER_MINECART) return net.minecraft.world.item.Items.MINECART; -+ else if (type == net.minecraft.world.entity.EntityType.COMMAND_BLOCK_MINECART) return net.minecraft.world.item.Items.COMMAND_BLOCK_MINECART; -+ else if (type == net.minecraft.world.entity.EntityType.HOPPER_MINECART) return net.minecraft.world.item.Items.HOPPER_MINECART; -+ else if (type == net.minecraft.world.entity.EntityType.TNT_MINECART) return net.minecraft.world.item.Items.TNT_MINECART; -+ else throw new UnsupportedOperationException("Server implementation is missing minecart material binding for entity type " + type.toShortString()); ++ return CraftMagicNumbers.getMaterial(this.getHandle().publicGetDropItem()); + } + // Paper end + diff --git a/patches/server/0763-Friction-API.patch b/patches/server/0763-Friction-API.patch index b2946a72b1..e31a2d2226 100644 --- a/patches/server/0763-Friction-API.patch +++ b/patches/server/0763-Friction-API.patch @@ -110,7 +110,7 @@ index d555fd0b200c012f30ed0c0ec09a37b25a737b76..7a6d51020d9c6be33b4c34c0d6085595 this.discard(null); // CraftBukkit - add Bukkit remove cause } diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java -index 1fdf2179eb768575fa49c019fb6d81f466892f98..ce91809d66007def728a127a0a9d33f6235cc94d 100644 +index f88c1becd08e7b10f228624160b85f89a379fbeb..cdc8606ffe5c75ee19d92e9f86f26b2a502d765e 100644 --- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java +++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java @@ -93,6 +93,7 @@ public abstract class AbstractMinecart extends VehicleEntity { @@ -221,10 +221,10 @@ index 1ceaa081231a617bd87331b308c24d9c7a8dcf2b..2fd4a3068d86a37cc18c9203448823c5 + // Paper end - friction API } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java -index 8192ccb01ed4efe9e987cab94952c172ed876581..5791f9936532899b337b149a109781fba0819657 100644 +index e02ecbdc158311bdc7e4d13307de6e2a2cf54235..b42bce0c4f4b3aac2729cfdad392d863245ed693 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java -@@ -138,4 +138,18 @@ public abstract class CraftMinecart extends CraftVehicle implements Minecart { +@@ -127,4 +127,18 @@ public abstract class CraftMinecart extends CraftVehicle implements Minecart { public int getDisplayBlockOffset() { return this.getHandle().getDisplayOffset(); }