mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
77a5779e24
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2ec53f49 PR-1050: Fix empty result check for Complex Recipes 10671012 PR-1044: Add CrafterCraftEvent 4d87ffe0 Use correct method in JavaDoc ae5e5817 SPIGOT-7850: Add API for Bogged shear state 46b6d445 SPIGOT-7837: Support data pack banner patterns d5d0cefc Fix JavaDoc error b3c2b83d PR-1036: Add API for InventoryView derivatives 1fe2c75a SPIGOT-7809: Add ShieldMeta CraftBukkit Changes: 8ee6fd1b8 SPIGOT-7857: Improve ItemMeta block data deserialization 8f26c30c6 SPIGOT-7857: Fix spurious internal NBT tag when deserializing BlockStateMeta 759061b93 SPIGOT-7855: Fire does not spread or burn blocks 00fc9fb64 SPIGOT-7853: AnvilInventory#getRepairCost() always returns 0 7501e2e04 PR-1450: Add CrafterCraftEvent 8c51673e7 SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel d53d0d0b1 PR-1456: Fix inverted logic in CraftCrafterView#setSlotDisabled 682a678c8 SPIGOT-7850: Add API for Bogged shear state fccf5243a SPIGOT-7837: Support data pack banner patterns 9c3bd4390 PR-1431: Add API for InventoryView derivatives 0cc6acbc4 SPIGOT-7849: Fix FoodComponent serialize with "using-converts-to" using null 2c5474952 Don't rely on tags for CraftItemMetas 20d107e46 SPIGOT-7846: Fix ItemMeta for hanging signs 76f59e315 Remove redundant clone in Dropper InventoryMoveItemEvent e61a53d25 SPIGOT-7817: Call InventoryMoveItemEvent for Crafters 894682e2d SPIGOT-7839: Remove redundant Java version checks 2c12b2187 SPIGOT-7809: Add ShieldMeta and fix setting shield base colours Spigot Changes: fb8fb722 Rebuild patches 34bd42b7 SPIGOT-7835: Fix issue with custom hopper settings
113 lines
8.6 KiB
Diff
113 lines
8.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Mon, 12 Dec 2022 12:14:03 -0800
|
|
Subject: [PATCH] Properly track the changed item from dispense events
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
|
|
index 0c0b8a49b3342cd015381c6a93fab23c32cd32e6..60d3319016beb4f60cbc26dde165f64cf7577602 100644
|
|
--- a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
|
|
+++ b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
|
|
@@ -134,10 +134,14 @@ public interface DispenseItemBehavior {
|
|
idispensebehavior.dispense(pointer, eventStack);
|
|
return stack;
|
|
}
|
|
+ // Paper start - track changed items in the dispense event
|
|
+ itemstack1 = CraftItemStack.unwrap(event.getItem()); // unwrap is safe because the stack won't be modified
|
|
+ entitytypes = ((SpawnEggItem) itemstack1.getItem()).getType(itemstack1);
|
|
+ // Paper end - track changed item from dispense event
|
|
}
|
|
|
|
try {
|
|
- entitytypes.spawn(pointer.level(), stack, (Player) null, pointer.pos().relative(enumdirection), MobSpawnType.DISPENSER, enumdirection != Direction.UP, false);
|
|
+ entitytypes.spawn(pointer.level(), itemstack1, (Player) null, pointer.pos().relative(enumdirection), MobSpawnType.DISPENSER, enumdirection != Direction.UP, false); // Paper - track changed item in dispense event
|
|
} catch (Exception exception) {
|
|
DispenseItemBehavior.LOGGER.error("Error while dispensing spawn egg from dispenser at {}", pointer.pos(), exception); // CraftBukkit - decompile error
|
|
return ItemStack.EMPTY;
|
|
@@ -192,9 +196,10 @@ public interface DispenseItemBehavior {
|
|
}
|
|
// CraftBukkit end
|
|
|
|
+ final ItemStack newStack = CraftItemStack.unwrap(event.getItem()); // Paper - use event itemstack (unwrap is fine here because the stack won't be modified)
|
|
Consumer<ArmorStand> consumer = EntityType.appendDefaultStackConfig((entityarmorstand) -> {
|
|
entityarmorstand.setYRot(enumdirection.toYRot());
|
|
- }, worldserver, stack, (Player) null);
|
|
+ }, worldserver, newStack, (Player) null); // Paper - track changed items in the dispense event
|
|
ArmorStand entityarmorstand = (ArmorStand) EntityType.ARMOR_STAND.spawn(worldserver, consumer, blockposition, MobSpawnType.DISPENSER, false, false);
|
|
|
|
if (entityarmorstand != null) {
|
|
@@ -244,7 +249,7 @@ public interface DispenseItemBehavior {
|
|
return stack;
|
|
}
|
|
}
|
|
- ((Saddleable) list.get(0)).equipSaddle(itemstack1, SoundSource.BLOCKS);
|
|
+ ((Saddleable) list.get(0)).equipSaddle(CraftItemStack.asNMSCopy(event.getItem()), SoundSource.BLOCKS); // Paper - track changed items in dispense event
|
|
// CraftBukkit end
|
|
if (shrink) stack.shrink(1); // Paper - actually handle here
|
|
this.setSuccess(true);
|
|
@@ -414,6 +419,7 @@ public interface DispenseItemBehavior {
|
|
int y = blockposition.getY();
|
|
int z = blockposition.getZ();
|
|
BlockState iblockdata = worldserver.getBlockState(blockposition);
|
|
+ ItemStack dispensedItem = stack; // Paper - track changed item from the dispense event
|
|
// Paper start - correctly check if the bucket place will succeed
|
|
/* Taken from SolidBucketItem#emptyContents */
|
|
boolean willEmptyContentsSolidBucketItem = dispensiblecontaineritem instanceof net.minecraft.world.item.SolidBucketItem && worldserver.isInWorldBounds(blockposition) && iblockdata.isAir();
|
|
@@ -443,12 +449,15 @@ public interface DispenseItemBehavior {
|
|
}
|
|
}
|
|
|
|
- dispensiblecontaineritem = (DispensibleContainerItem) CraftItemStack.asNMSCopy(event.getItem()).getItem();
|
|
+ // Paper start - track changed item from dispense event
|
|
+ dispensedItem = CraftItemStack.unwrap(event.getItem()); // unwrap is safe here as the stack isn't mutated
|
|
+ dispensiblecontaineritem = (DispensibleContainerItem) dispensedItem.getItem();
|
|
+ // Paper end - track changed item from dispense event
|
|
}
|
|
// CraftBukkit end
|
|
|
|
if (dispensiblecontaineritem.emptyContents((Player) null, worldserver, blockposition, (BlockHitResult) null)) {
|
|
- dispensiblecontaineritem.checkExtraContent((Player) null, worldserver, stack, blockposition);
|
|
+ dispensiblecontaineritem.checkExtraContent((Player) null, worldserver, dispensedItem, blockposition); // Paper - track changed item from dispense event
|
|
return this.consumeWithRemainder(pointer, stack, new ItemStack(Items.BUCKET));
|
|
} else {
|
|
return this.defaultDispenseItemBehavior.dispense(pointer, stack);
|
|
diff --git a/src/main/java/net/minecraft/core/dispenser/ProjectileDispenseBehavior.java b/src/main/java/net/minecraft/core/dispenser/ProjectileDispenseBehavior.java
|
|
index 985954030654d521291cccbfc3ca49b67ee4357d..e37d2d29f3ba67cfe28abe4847a3dca07121f0be 100644
|
|
--- a/src/main/java/net/minecraft/core/dispenser/ProjectileDispenseBehavior.java
|
|
+++ b/src/main/java/net/minecraft/core/dispenser/ProjectileDispenseBehavior.java
|
|
@@ -36,7 +36,7 @@ public class ProjectileDispenseBehavior extends DefaultDispenseItemBehavior {
|
|
ServerLevel worldserver = pointer.level();
|
|
Direction enumdirection = (Direction) pointer.state().getValue(DispenserBlock.FACING);
|
|
Position iposition = this.dispenseConfig.positionFunction().getDispensePosition(pointer, enumdirection);
|
|
- Projectile iprojectile = this.projectileItem.asProjectile(worldserver, iposition, stack, enumdirection);
|
|
+ // Paper - move down
|
|
|
|
// CraftBukkit start
|
|
// this.projectileItem.shoot(iprojectile, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty());
|
|
@@ -66,6 +66,7 @@ public class ProjectileDispenseBehavior extends DefaultDispenseItemBehavior {
|
|
}
|
|
}
|
|
|
|
+ Projectile iprojectile = this.projectileItem.asProjectile(worldserver, iposition, CraftItemStack.unwrap(event.getItem()), enumdirection); // Paper - move from above and track changed items in the dispense event; unwrap is safe here because all uses of the stack make their own copies
|
|
this.projectileItem.shoot(iprojectile, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty());
|
|
((Entity) iprojectile).projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(pointer.blockEntity());
|
|
// CraftBukkit end
|
|
diff --git a/src/main/java/net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java b/src/main/java/net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java
|
|
index 6f2adf2334e35e8a617a4ced0c1af2abf32bbd8d..cb308808906a8cdb127df8284e106e00553473ca 100644
|
|
--- a/src/main/java/net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java
|
|
+++ b/src/main/java/net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java
|
|
@@ -57,7 +57,12 @@ public class ShulkerBoxDispenseBehavior extends OptionalDispenseItemBehavior {
|
|
// CraftBukkit end
|
|
|
|
try {
|
|
- this.setSuccess(((BlockItem) item).place(new DirectionalPlaceContext(pointer.level(), blockposition, enumdirection, stack, enumdirection1)).consumesAction());
|
|
+ // Paper start - track changed items in the dispense event
|
|
+ this.setSuccess(((BlockItem) item).place(new DirectionalPlaceContext(pointer.level(), blockposition, enumdirection, CraftItemStack.asNMSCopy(event.getItem()), enumdirection1)).consumesAction());
|
|
+ if (this.isSuccess()) {
|
|
+ stack.shrink(1); // vanilla shrink is in the place function above, manually handle it here
|
|
+ }
|
|
+ // Paper end - track changed items in the dispense event
|
|
} catch (Exception exception) {
|
|
ShulkerBoxDispenseBehavior.LOGGER.error("Error trying to place shulker box at {}", blockposition, exception);
|
|
}
|