aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0896-Fix-inconsistencies-in-dispense-events-regarding-sta.patch
blob: f318df5bb341b3495120fed1eddba4b9f8116528 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
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/AbstractProjectileDispenseBehavior.java b/src/main/java/net/minecraft/core/dispenser/AbstractProjectileDispenseBehavior.java
index e22d71c371952e91b838d10206d3dcdf9dc8716d..155bd3d6d9c7d3cac7fd04de8210301251d1e17a 100644
--- a/src/main/java/net/minecraft/core/dispenser/AbstractProjectileDispenseBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/AbstractProjectileDispenseBehavior.java
@@ -27,7 +27,7 @@ public abstract class AbstractProjectileDispenseBehavior extends DefaultDispense
 
         // CraftBukkit start
         // iprojectile.shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), this.getPower(), this.getUncertainty());
-        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);
 
@@ -37,12 +37,13 @@ public abstract class AbstractProjectileDispenseBehavior extends DefaultDispense
         }
 
         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());
@@ -56,7 +57,7 @@ public abstract class AbstractProjectileDispenseBehavior extends DefaultDispense
         ((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/BoatDispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java
index eb3b91a49d7831d7a3cbbee9323723956d3d3e00..80dbeb0a988c749feaaba26ce5ad93c181d88a5d 100644
--- a/src/main/java/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/BoatDispenseItemBehavior.java
@@ -57,7 +57,7 @@ public class BoatDispenseItemBehavior extends DefaultDispenseItemBehavior {
 
         // 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);
 
@@ -67,12 +67,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());
@@ -87,8 +88,7 @@ public class BoatDispenseItemBehavior extends DefaultDispenseItemBehavior {
 
         ((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
index f9ab6d4f6e7f430d41b79227e74136a3e980f340..c0baec6ae9bd90410f47aa04d7c7704233375d1a 100644
--- a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
@@ -217,7 +217,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);
 
@@ -227,12 +227,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());
@@ -249,7 +250,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
                 pointer.level().gameEvent((Entity) null, GameEvent.ENTITY_PLACE, pointer.pos());
                 return stack;
@@ -271,7 +272,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);
 
@@ -281,12 +282,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());
@@ -303,7 +305,7 @@ public interface DispenseItemBehavior {
                 ArmorStand entityarmorstand = (ArmorStand) EntityType.ARMOR_STAND.spawn(worldserver, stack.getTag(), consumer, blockposition, MobSpawnType.DISPENSER, false, false);
 
                 if (entityarmorstand != null) {
-                    // itemstack.shrink(1); // CraftBukkit - Handled during event processing
+                    if (shrink) stack.shrink(1); // Paper - actually handle here
                 }
 
                 return stack;
@@ -325,7 +327,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
                     Level world = pointer.level();
                     org.bukkit.block.Block block = CraftBlock.at(world, pointer.pos());
                     CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
@@ -336,12 +338,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());
@@ -352,7 +355,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 {
@@ -380,7 +383,7 @@ public interface DispenseItemBehavior {
                 } while (!entityhorseabstract.isArmor(stack) || entityhorseabstract.isWearingArmor() || !entityhorseabstract.isTamed());
 
                 // CraftBukkit start
-                ItemStack itemstack1 = stack.split(1);
+                ItemStack itemstack1 = stack.copyWithCount(1); // Paper - shrink below and single item in event
                 Level world = pointer.level();
                 org.bukkit.block.Block block = CraftBlock.at(world, pointer.pos());
                 CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
@@ -391,12 +394,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());
@@ -406,6 +410,7 @@ public interface DispenseItemBehavior {
                     }
                 }
 
+                if (shrink) stack.shrink(1); // Paper - shrink here
                 entityhorseabstract.getSlot(401).set(CraftItemStack.asNMSCopy(event.getItem()));
                 // CraftBukkit end
                 this.setSuccess(true);
@@ -452,7 +457,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
                 Level world = pointer.level();
                 org.bukkit.block.Block block = CraftBlock.at(world, pointer.pos());
                 CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
@@ -463,10 +468,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 just for less confusion)
                     return stack;
                 }
 
+                boolean shrink = true; // Paper
                 if (!event.getItem().equals(craftItem)) {
+                    shrink = false; // Paper - shrink below (this was actually missing and should be here, added it commented out just for less confusion)
                     // Chain to handler for new item
                     ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
                     DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
@@ -478,7 +486,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;
             }
@@ -489,7 +497,7 @@ public interface DispenseItemBehavior {
                 Direction enumdirection = (Direction) pointer.state().getValue(DispenserBlock.FACING);
                 // 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);
 
@@ -499,12 +507,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());
@@ -521,7 +530,7 @@ public interface DispenseItemBehavior {
 
                 entityfireworks.shoot((double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), 0.5F, 1.0F);
                 pointer.level().addFreshEntity(entityfireworks);
-                // itemstack.shrink(1); // Handled during event processing
+                if (shrink) stack.shrink(1); // Paper - actually handle here
                 // CraftBukkit end
                 return stack;
             }
@@ -546,7 +555,7 @@ public interface DispenseItemBehavior {
                 double d5 = randomsource.triangle((double) enumdirection.getStepZ(), 0.11485000000000001D);
 
                 // 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);
 
@@ -556,12 +565,13 @@ public interface DispenseItemBehavior {
                 }
 
                 if (event.isCancelled()) {
-                    stack.grow(1);
+                    // stack.grow(1); // Paper - shrink at end
                     return stack;
                 }
 
+                boolean shrink = true; // Paper
                 if (!event.getItem().equals(craftItem)) {
-                    stack.grow(1);
+                    shrink = false; // Paper - shrink at end
                     // Chain to handler for new item
                     ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
                     DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
@@ -576,7 +586,7 @@ public interface DispenseItemBehavior {
                 entitysmallfireball.projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(pointer.blockEntity());
 
                 worldserver.addFreshEntity(entitysmallfireball);
-                // itemstack.shrink(1); // Handled during event processing
+                if (shrink) stack.shrink(1); // Paper - actually handle here
                 // CraftBukkit end
                 return stack;
             }
@@ -620,7 +630,7 @@ public interface DispenseItemBehavior {
                 BlockState iblockdata = worldserver.getBlockState(blockposition);
                 if (iblockdata.isAir() || iblockdata.canBeReplaced() || (dispensiblecontaineritem instanceof BucketItem && iblockdata.getBlock() instanceof LiquidBlockContainer && ((LiquidBlockContainer) iblockdata.getBlock()).canPlaceLiquid((Player) null, worldserver, blockposition, iblockdata, ((BucketItem) dispensiblecontaineritem).content))) {
                     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) {
@@ -694,7 +704,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) {
@@ -802,7 +812,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) {
@@ -868,7 +878,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);
 
@@ -878,12 +888,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());
@@ -899,7 +910,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);
                 worldserver.gameEvent((Entity) null, GameEvent.ENTITY_PLACE, blockposition);
-                // itemstack.shrink(1); // CraftBukkit - handled above
+                if (shrink) stack.shrink(1); // Paper - actually handle here
                 return stack;
             }
         });
@@ -926,7 +937,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) {
@@ -975,7 +986,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) {
@@ -1048,7 +1059,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) {
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
index a745dc02ae25bcf10cee954b6e53f8b106fd045d..42d87800a328f71c5127ce5599ca4c71cc9bb1cd 100644
--- a/src/main/java/net/minecraft/world/item/ArmorItem.java
+++ b/src/main/java/net/minecraft/world/item/ArmorItem.java
@@ -62,7 +62,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());
@@ -74,12 +74,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());
@@ -96,6 +97,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
index 496900fc805e7e3f6206777c9c9b0260839dd9b0..a33395dc5a94d89b5ab273c7832813b6ff9ea3b7 100644
--- a/src/main/java/net/minecraft/world/item/MinecartItem.java
+++ b/src/main/java/net/minecraft/world/item/MinecartItem.java
@@ -64,7 +64,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);
 
@@ -74,12 +74,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());
@@ -96,8 +97,7 @@ public class MinecartItem extends Item {
                 entityminecartabstract.setCustomName(stack.getHoverName());
             }
 
-            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;
         }