2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/item/ItemArmor.java
|
|
|
|
+++ b/net/minecraft/world/item/ItemArmor.java
|
2024-06-13 17:05:00 +02:00
|
|
|
@@ -29,6 +29,12 @@
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.level.block.BlockDispenser;
|
|
|
|
import net.minecraft.world.phys.AxisAlignedBB;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
2023-09-21 18:40:00 +02:00
|
|
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
2015-02-26 23:41:06 +01:00
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
2018-09-08 06:15:33 +02:00
|
|
|
+import org.bukkit.event.block.BlockDispenseArmorEvent;
|
2015-02-26 23:41:06 +01:00
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
2023-03-14 17:30:00 +01:00
|
|
|
public class ItemArmor extends Item implements Equipable {
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2024-06-13 17:05:00 +02:00
|
|
|
public static final IDispenseBehavior DISPENSE_ITEM_BEHAVIOR = new DispenseBehaviorItem() {
|
|
|
|
@@ -51,8 +57,34 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
EntityLiving entityliving = (EntityLiving) list.get(0);
|
2024-06-13 17:05:00 +02:00
|
|
|
EnumItemSlot enumitemslot = entityliving.getEquipmentSlotForItem(itemstack);
|
2021-11-21 23:00:00 +01:00
|
|
|
ItemStack itemstack1 = itemstack.split(1);
|
2016-02-29 22:32:46 +01:00
|
|
|
+ // CraftBukkit start
|
2023-09-21 18:40:00 +02:00
|
|
|
+ World world = sourceblock.level();
|
|
|
|
+ org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos());
|
2016-02-29 22:32:46 +01:00
|
|
|
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
|
2023-09-21 18:57:13 +02:00
|
|
|
|
|
|
|
- entityliving.setItemSlot(enumitemslot, itemstack1);
|
2019-06-02 11:49:41 +02:00
|
|
|
+ BlockDispenseArmorEvent event = new BlockDispenseArmorEvent(block, craftItem.clone(), (org.bukkit.craftbukkit.entity.CraftLivingEntity) entityliving.getBukkitEntity());
|
2016-02-29 22:32:46 +01:00
|
|
|
+ if (!BlockDispenser.eventFired) {
|
2021-06-11 13:33:49 +02:00
|
|
|
+ world.getCraftServer().getPluginManager().callEvent(event);
|
2016-02-29 22:32:46 +01:00
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ if (event.isCancelled()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ itemstack.grow(1);
|
2019-12-10 23:00:00 +01:00
|
|
|
+ return false;
|
2016-02-29 22:32:46 +01:00
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ if (!event.getItem().equals(craftItem)) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ itemstack.grow(1);
|
2016-02-29 22:32:46 +01:00
|
|
|
+ // Chain to handler for new item
|
|
|
|
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
|
2021-06-11 07:00:00 +02:00
|
|
|
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
|
|
|
|
+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) {
|
2023-09-21 18:40:00 +02:00
|
|
|
+ idispensebehavior.dispense(sourceblock, eventStack);
|
2019-12-10 23:00:00 +01:00
|
|
|
+ return true;
|
2015-02-26 23:41:06 +01:00
|
|
|
+ }
|
2016-02-29 22:32:46 +01:00
|
|
|
+ }
|
2023-09-21 18:57:13 +02:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ entityliving.setItemSlot(enumitemslot, CraftItemStack.asNMSCopy(event.getItem()));
|
2021-09-26 00:24:33 +02:00
|
|
|
+ // CraftBukkit end
|
2016-11-17 02:41:03 +01:00
|
|
|
if (entityliving instanceof EntityInsentient) {
|
2021-11-21 23:00:00 +01:00
|
|
|
((EntityInsentient) entityliving).setDropChance(enumitemslot, 2.0F);
|
|
|
|
((EntityInsentient) entityliving).setPersistenceRequired();
|