Paper/patches/server/0798-Fix-inconsistencies-in-dispense-events-regarding-sta.patch

458 lines
27 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 11 Dec 2022 23:47:22 -0800
Subject: [PATCH] Fix inconsistencies in dispense events regarding stack size
The javadocs for BlockDispenseEvent suggest the ItemStack is a single
item which is being dispensed. Before this fix, sometimes it was the whole
stack before a single item had been taken. This fixes that so the stack size
is always 1.
diff --git a/src/main/java/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java
2023-12-06 17:21:56 +01:00
index 90e1914599b43c8bf813596b3b428d8be3bac1b5..6df0db8b4cdab23494ea34236949ece4989110a3 100644
--- a/src/main/java/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java
2023-12-06 17:21:56 +01:00
@@ -58,7 +58,7 @@ public class BoatDispenseItemBehavior extends DefaultDispenseItemBehavior {
2023-06-08 10:47:19 +02:00
// Object object = this.isChestBoat ? new ChestBoat(worldserver, d1, d2 + d4, d3) : new EntityBoat(worldserver, d1, d2 + d4, d3);
// CraftBukkit start
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink at end and single item in event
org.bukkit.block.Block block = CraftBlock.at(worldserver, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
2023-12-06 17:21:56 +01:00
@@ -68,12 +68,13 @@ public class BoatDispenseItemBehavior extends DefaultDispenseItemBehavior {
}
if (event.isCancelled()) {
- stack.grow(1);
+ // stack.grow(1); // Paper - shrink below
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- stack.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2023-12-06 17:21:56 +01:00
@@ -89,8 +90,7 @@ public class BoatDispenseItemBehavior extends DefaultDispenseItemBehavior {
EntityType.createDefaultStackConfig(worldserver, stack, (Player) null).accept(object);
((Boat) object).setVariant(this.type);
((Boat) object).setYRot(enumdirection.toYRot());
- if (!worldserver.addFreshEntity((Entity) object)) stack.grow(1); // CraftBukkit
- // itemstack.shrink(1); // CraftBukkit - handled during event processing
+ if (worldserver.addFreshEntity((Entity) object) && shrink) stack.shrink(1); // Paper - if entity add was successful and supposed to shrink
return stack;
}
diff --git a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
2024-04-25 00:36:49 +02:00
index 2bb3d1f0b89ef5b9b1f9f8da1070d21168830645..9507dbbb4b490149b9248c384be5adaccae40c41 100644
--- a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
2024-04-25 00:36:49 +02:00
@@ -109,7 +109,7 @@ public interface DispenseItemBehavior {
// CraftBukkit start
ServerLevel worldserver = pointer.level();
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink below and single item in event
org.bukkit.block.Block block = CraftBlock.at(worldserver, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
2024-04-25 00:36:49 +02:00
@@ -119,12 +119,13 @@ public interface DispenseItemBehavior {
}
if (event.isCancelled()) {
- stack.grow(1);
+ // stack.grow(1); // Paper - shrink below
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- stack.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2024-04-25 00:36:49 +02:00
@@ -141,7 +142,7 @@ public interface DispenseItemBehavior {
return ItemStack.EMPTY;
}
- // itemstack.shrink(1); // Handled during event processing
+ if (shrink) stack.shrink(1); // Paper - actually handle here
// CraftBukkit end
2024-04-25 00:36:49 +02:00
pointer.level().gameEvent((Entity) null, (Holder) GameEvent.ENTITY_PLACE, pointer.pos());
return stack;
2024-04-25 00:36:49 +02:00
@@ -163,7 +164,7 @@ public interface DispenseItemBehavior {
ServerLevel worldserver = pointer.level();
// CraftBukkit start
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink below and single item in event
org.bukkit.block.Block block = CraftBlock.at(worldserver, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
2024-04-25 00:36:49 +02:00
@@ -173,12 +174,13 @@ public interface DispenseItemBehavior {
}
if (event.isCancelled()) {
- stack.grow(1);
+ // stack.grow(1); // Paper - shrink below
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- stack.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2024-04-25 00:36:49 +02:00
@@ -195,7 +197,7 @@ public interface DispenseItemBehavior {
ArmorStand entityarmorstand = (ArmorStand) EntityType.ARMOR_STAND.spawn(worldserver, consumer, blockposition, MobSpawnType.DISPENSER, false, false);
2023-03-14 22:29:14 +01:00
if (entityarmorstand != null) {
- // itemstack.shrink(1); // CraftBukkit - Handled during event processing
+ if (shrink) stack.shrink(1); // Paper - actually handle here
}
return stack;
2024-04-25 00:36:49 +02:00
@@ -215,7 +217,7 @@ public interface DispenseItemBehavior {
if (!list.isEmpty()) {
// CraftBukkit start
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink below and single item in event
2024-04-25 00:36:49 +02:00
ServerLevel world = pointer.level();
org.bukkit.block.Block block = CraftBlock.at(world, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
2024-04-25 00:36:49 +02:00
@@ -226,12 +228,13 @@ public interface DispenseItemBehavior {
}
if (event.isCancelled()) {
- stack.grow(1);
+ // stack.grow(1); // Paper - shrink below
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- stack.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2024-04-25 00:36:49 +02:00
@@ -242,7 +245,7 @@ public interface DispenseItemBehavior {
}
// CraftBukkit end
((Saddleable) list.get(0)).equipSaddle(SoundSource.BLOCKS, CraftItemStack.asNMSCopy(event.getItem())); // Paper - Fix saddles losing nbt data - MC-191591
- // itemstack.shrink(1); // CraftBukkit - handled above
+ if (shrink) stack.shrink(1); // Paper - actually handle here
this.setSuccess(true);
return stack;
} else {
2024-04-25 00:36:49 +02:00
@@ -270,7 +273,7 @@ public interface DispenseItemBehavior {
} while (!entityhorseabstract.isBodyArmorItem(stack) || entityhorseabstract.isWearingBodyArmor() || !entityhorseabstract.isTamed());
// CraftBukkit start
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink below and single item in event
2024-04-25 00:36:49 +02:00
ServerLevel world = pointer.level();
org.bukkit.block.Block block = CraftBlock.at(world, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
2024-04-25 00:36:49 +02:00
@@ -281,12 +284,13 @@ public interface DispenseItemBehavior {
}
if (event.isCancelled()) {
- stack.grow(1);
+ // stack.grow(1); // Paper - shrink below
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- stack.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2024-04-25 00:36:49 +02:00
@@ -296,6 +300,7 @@ public interface DispenseItemBehavior {
}
}
+ if (shrink) stack.shrink(1); // Paper - shrink here
2024-04-25 00:36:49 +02:00
entityhorseabstract.setBodyArmorItem(CraftItemStack.asNMSCopy(event.getItem()));
// CraftBukkit end
this.setSuccess(true);
2024-04-25 00:36:49 +02:00
@@ -342,7 +347,7 @@ public interface DispenseItemBehavior {
entityhorsechestedabstract = (AbstractChestedHorse) iterator1.next();
// CraftBukkit start
} while (!entityhorsechestedabstract.isTamed());
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink below
2024-04-25 00:36:49 +02:00
ServerLevel world = pointer.level();
org.bukkit.block.Block block = CraftBlock.at(world, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
2024-04-25 00:36:49 +02:00
@@ -353,10 +358,13 @@ public interface DispenseItemBehavior {
}
if (event.isCancelled()) {
+ // stack.grow(1); // Paper - shrink below (this was actually missing and should be here, added it commented out to be consistent)
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2024-04-25 00:36:49 +02:00
@@ -368,7 +376,7 @@ public interface DispenseItemBehavior {
entityhorsechestedabstract.getSlot(499).set(CraftItemStack.asNMSCopy(event.getItem()));
// CraftBukkit end
- // itemstack.shrink(1); // CraftBukkit - handled above
+ if (shrink) stack.shrink(1); // Paper - actually handle here
this.setSuccess(true);
return stack;
}
2024-04-25 00:36:49 +02:00
@@ -413,7 +421,7 @@ public interface DispenseItemBehavior {
if (willEmptyContentsSolidBucketItem || willEmptyBucketItem) {
// Paper end - correctly check if the bucket place will succeed
org.bukkit.block.Block block = CraftBlock.at(worldserver, pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack.copyWithCount(1)); // Paper - single item in event
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(x, y, z));
if (!DispenserBlock.eventFired) {
2024-04-25 00:36:49 +02:00
@@ -486,7 +494,7 @@ public interface DispenseItemBehavior {
// CraftBukkit start
org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldserver, pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack.copyWithCount(1)); // Paper - single item in event
BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
if (!DispenserBlock.eventFired) {
2024-04-25 00:36:49 +02:00
@@ -533,7 +541,7 @@ public interface DispenseItemBehavior {
2023-12-06 17:21:56 +01:00
// CraftBukkit start
org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldserver, pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack); // Paper - ignore stack size on damageable items
BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
if (!DispenserBlock.eventFired) {
2024-04-25 00:36:49 +02:00
@@ -596,7 +604,7 @@ public interface DispenseItemBehavior {
BlockPos blockposition = pointer.pos().relative((Direction) pointer.state().getValue(DispenserBlock.FACING));
// CraftBukkit start
org.bukkit.block.Block block = CraftBlock.at(worldserver, pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack.copyWithCount(1)); // Paper - single item in event
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
if (!DispenserBlock.eventFired) {
2024-04-25 00:36:49 +02:00
@@ -662,7 +670,7 @@ public interface DispenseItemBehavior {
// CraftBukkit start
// EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldserver, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, (EntityLiving) null);
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink at end and single item in event
org.bukkit.block.Block block = CraftBlock.at(worldserver, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
2024-04-25 00:36:49 +02:00
@@ -672,12 +680,13 @@ public interface DispenseItemBehavior {
}
if (event.isCancelled()) {
- stack.grow(1);
+ // stack.grow(1); // Paper - shrink below
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- stack.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2024-04-25 00:36:49 +02:00
@@ -693,7 +702,7 @@ public interface DispenseItemBehavior {
worldserver.addFreshEntity(entitytntprimed);
worldserver.playSound((Player) null, entitytntprimed.getX(), entitytntprimed.getY(), entitytntprimed.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
2024-04-25 00:36:49 +02:00
worldserver.gameEvent((Entity) null, (Holder) GameEvent.ENTITY_PLACE, blockposition);
- // itemstack.shrink(1); // CraftBukkit - handled above
+ if (shrink) stack.shrink(1); // Paper - actually handle here
return stack;
}
});
2024-04-25 00:36:49 +02:00
@@ -720,7 +729,7 @@ public interface DispenseItemBehavior {
// CraftBukkit start
org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldserver, pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack.copyWithCount(1)); // Paper - single item in event
BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
if (!DispenserBlock.eventFired) {
2024-04-25 00:36:49 +02:00
@@ -769,7 +778,7 @@ public interface DispenseItemBehavior {
// CraftBukkit start
org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldserver, pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack.copyWithCount(1)); // Paper - single item in event
BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
if (!DispenserBlock.eventFired) {
2024-04-25 00:36:49 +02:00
@@ -842,7 +851,7 @@ public interface DispenseItemBehavior {
// CraftBukkit start
org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldserver, pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack.copyWithCount(1)); // Paper - only single item in event
BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
if (!DispenserBlock.eventFired) {
2024-04-25 00:36:49 +02:00
diff --git a/src/main/java/net/minecraft/core/dispenser/ProjectileDispenseBehavior.java b/src/main/java/net/minecraft/core/dispenser/ProjectileDispenseBehavior.java
index 1b1c54ce8f187b968352d4aad05821ece182e20b..985954030654d521291cccbfc3ca49b67ee4357d 100644
--- a/src/main/java/net/minecraft/core/dispenser/ProjectileDispenseBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/ProjectileDispenseBehavior.java
@@ -40,7 +40,7 @@ public class ProjectileDispenseBehavior extends DefaultDispenseItemBehavior {
// CraftBukkit start
// this.projectileItem.shoot(iprojectile, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty());
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper
org.bukkit.block.Block block = CraftBlock.at(worldserver, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
@@ -50,12 +50,13 @@ public class ProjectileDispenseBehavior extends DefaultDispenseItemBehavior {
}
if (event.isCancelled()) {
- stack.grow(1);
+ // stack.grow(1); // Paper - shrink below
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- stack.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
@@ -69,7 +70,7 @@ public class ProjectileDispenseBehavior extends DefaultDispenseItemBehavior {
((Entity) iprojectile).projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(pointer.blockEntity());
// CraftBukkit end
worldserver.addFreshEntity(iprojectile);
- // itemstack.shrink(1); // CraftBukkit - Handled during event processing
+ if (shrink) stack.shrink(1); // Paper - actually handle here
return stack;
}
diff --git a/src/main/java/net/minecraft/core/dispenser/ShearsDispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/ShearsDispenseItemBehavior.java
2024-04-25 00:36:49 +02:00
index 4924926327787e7564116e9d6e20d2c2e98b2229..fbed5d57db0c0e79996f85571b9af0071fa953c7 100644
--- a/src/main/java/net/minecraft/core/dispenser/ShearsDispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/ShearsDispenseItemBehavior.java
2024-04-25 00:36:49 +02:00
@@ -38,7 +38,7 @@ public class ShearsDispenseItemBehavior extends OptionalDispenseItemBehavior {
ServerLevel worldserver = pointer.level();
// CraftBukkit start
org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldserver, pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack); // Paper - ignore stack size on damageable items
2023-12-06 17:21:56 +01:00
BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
if (!DispenserBlock.eventFired) {
diff --git a/src/main/java/net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java b/src/main/java/net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java
index f84987c36a16df19286d6f1badfb1ffb9cc7e770..6f2adf2334e35e8a617a4ced0c1af2abf32bbd8d 100644
--- a/src/main/java/net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java
@@ -34,7 +34,7 @@ public class ShulkerBoxDispenseBehavior extends OptionalDispenseItemBehavior {
// CraftBukkit start
org.bukkit.block.Block bukkitBlock = CraftBlock.at(pointer.level(), pointer.pos());
- CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack.copyWithCount(1)); // Paper - single item in event
BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
if (!DispenserBlock.eventFired) {
diff --git a/src/main/java/net/minecraft/world/item/ArmorItem.java b/src/main/java/net/minecraft/world/item/ArmorItem.java
2024-04-25 00:36:49 +02:00
index f1cee3266e95094dd1afd501c96e4beaa3d71796..e766397aae3f73548b290b0809b9d1ca0967ea39 100644
--- a/src/main/java/net/minecraft/world/item/ArmorItem.java
+++ b/src/main/java/net/minecraft/world/item/ArmorItem.java
2024-04-25 00:36:49 +02:00
@@ -64,7 +64,7 @@ public class ArmorItem extends Item implements Equipable {
} else {
LivingEntity entityliving = (LivingEntity) list.get(0);
EquipmentSlot enumitemslot = Mob.getEquipmentSlotForItem(armor);
- ItemStack itemstack1 = armor.split(1);
+ ItemStack itemstack1 = armor.copyWithCount(1); // Paper - shrink below and single item in event
// CraftBukkit start
Level world = pointer.level();
org.bukkit.block.Block block = CraftBlock.at(world, pointer.pos());
2024-04-25 00:36:49 +02:00
@@ -76,12 +76,13 @@ public class ArmorItem extends Item implements Equipable {
}
if (event.isCancelled()) {
- armor.grow(1);
+ // armor.grow(1); // Paper - shrink below
return false;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- armor.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2024-04-25 00:36:49 +02:00
@@ -98,6 +99,7 @@ public class ArmorItem extends Item implements Equipable {
((Mob) entityliving).setPersistenceRequired();
}
+ if (shrink) armor.shrink(1); // Paper
return true;
}
}
diff --git a/src/main/java/net/minecraft/world/item/MinecartItem.java b/src/main/java/net/minecraft/world/item/MinecartItem.java
2024-04-25 00:36:49 +02:00
index 727319e86aa77b5a67b4c4f03b1e9aba9fe6bcde..66074445d3908b9bb1c8d70e1e27d057720ec8e5 100644
--- a/src/main/java/net/minecraft/world/item/MinecartItem.java
+++ b/src/main/java/net/minecraft/world/item/MinecartItem.java
2024-04-25 00:36:49 +02:00
@@ -66,7 +66,7 @@ public class MinecartItem extends Item {
// CraftBukkit start
// EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, d0, d1 + d3, d2, ((ItemMinecart) itemstack.getItem()).type);
- ItemStack itemstack1 = stack.split(1);
+ ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink below and single item in event
org.bukkit.block.Block block2 = CraftBlock.at(worldserver, pointer.pos());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
2024-04-25 00:36:49 +02:00
@@ -76,12 +76,13 @@ public class MinecartItem extends Item {
}
if (event.isCancelled()) {
- stack.grow(1);
+ // stack.grow(1); // Paper - shrink below
return stack;
}
+ boolean shrink = true; // Paper
if (!event.getItem().equals(craftItem)) {
- stack.grow(1);
+ shrink = false; // Paper - shrink below
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
2024-04-25 00:36:49 +02:00
@@ -94,8 +95,7 @@ public class MinecartItem extends Item {
2023-12-06 17:21:56 +01:00
itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
AbstractMinecart entityminecartabstract = AbstractMinecart.createMinecart(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), ((MinecartItem) itemstack1.getItem()).type, itemstack1, (Player) null);
- if (!worldserver.addFreshEntity(entityminecartabstract)) stack.grow(1);
- // itemstack.shrink(1); // CraftBukkit - handled during event processing
+ if (worldserver.addFreshEntity(entityminecartabstract) && shrink) stack.shrink(1); // Paper - actually handle here
// CraftBukkit end
return stack;
}