Paper/paper-server/nms-patches/net/minecraft/world/item/ItemArmor.patch
CraftBukkit/Spigot 43702a9e10 Update to Minecraft 1.18-pre5
By: md_5 <git@md-5.net>
2021-11-22 09:00:00 +11:00

51 lines
2.7 KiB
Diff

--- a/net/minecraft/world/item/ItemArmor.java
+++ b/net/minecraft/world/item/ItemArmor.java
@@ -27,6 +27,11 @@
import net.minecraft.world.level.block.BlockDispenser;
import net.minecraft.world.phys.AxisAlignedBB;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.block.BlockDispenseArmorEvent;
+// CraftBukkit end
+
public class ItemArmor extends Item implements ItemWearable {
private static final UUID[] ARMOR_MODIFIER_UUID_PER_SLOT = new UUID[]{UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"), UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"), UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")};
@@ -53,8 +58,34 @@
EntityLiving entityliving = (EntityLiving) list.get(0);
EnumItemSlot enumitemslot = EntityInsentient.getEquipmentSlotForItem(itemstack);
ItemStack itemstack1 = itemstack.split(1);
+ // CraftBukkit start
+ World world = isourceblock.getLevel();
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getPos().getX(), isourceblock.getPos().getY(), isourceblock.getPos().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+ BlockDispenseArmorEvent event = new BlockDispenseArmorEvent(block, craftItem.clone(), (org.bukkit.craftbukkit.entity.CraftLivingEntity) entityliving.getBukkitEntity());
+ if (!BlockDispenser.eventFired) {
+ world.getCraftServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
+ itemstack.grow(1);
+ return false;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ itemstack.grow(1);
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return true;
+ }
+ }
- entityliving.setItemSlot(enumitemslot, itemstack1);
+ entityliving.setItemSlot(enumitemslot, CraftItemStack.asNMSCopy(event.getItem()));
+ // CraftBukkit end
if (entityliving instanceof EntityInsentient) {
((EntityInsentient) entityliving).setDropChance(enumitemslot, 2.0F);
((EntityInsentient) entityliving).setPersistenceRequired();