Improve Minecart#getMinecartMaterial (#11544)

Removes the hardcoded lookup in favour of calling the
AbstractVehicle getItemDrop method.
This commit is contained in:
Abel 2024-11-09 23:22:01 +01:00
parent 9ce7eb4087
commit 89d6bc1a93

View File

@ -6,6 +6,16 @@ Subject: [PATCH] API to get Material from Boats and Minecarts
== AT == == AT ==
public net.minecraft.world.entity.vehicle.AbstractBoat getDropItem()Lnet/minecraft/world/item/Item; 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
@@ -0,0 +0,0 @@ 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 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java
@ -43,18 +53,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start + // Paper start
+ @Override + @Override
+ public Material getMinecartMaterial() { + public Material getMinecartMaterial() {
+ return CraftMagicNumbers.getMaterial(minecartEntityTypeToMaterial(this.getHandle().getType())); + return CraftMagicNumbers.getMaterial(this.getHandle().publicGetDropItem());
+ }
+
+ 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());
+ } + }
+ // Paper end + // Paper end
+ +