PaperMC/patches/server/0688-Fix-new-block-data-for-EntityChangeBlockEvent.patch
Bjarne Koll 4d20922b79
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11024)
* Updated Upstream (Bukkit/CraftBukkit/Spigot)

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:
e86f4dc4 PR-1041: Improve getPlayer(String) docs to clarify it matches the name
9738f005 Fix spawner API documentation
69ebd9fd PR-1034: Add TrialSpawnerSpawnEvent
23cffd9c PR-973: Improve spawner API and add API for Trial Spawners
8bf19163 PR-1038: Clarify HumanEntity#openInventory(InventoryView) JavaDoc
1ff76351 SPIGOT-7732, SPIGOT-7786: Add freezing damage modifier
02161cb4 PR-1034: Add CreatureSpawnEvent.SpawnReason#TRIAL_SPAWNER
f9cb6f34 SPIGOT-7777: All entity potion effects are removed on death
25d548eb PR-1031: Expose Creeper igniter
ccbf0915 SPIGOT-7770: Reserve spaces in shaped recipes for blank ingredients
17f7097c Clarify ambiguity around what is API
71714f0c Remove note from InventoryView JavaDoc
aaf49731 PR-1030: Deprecate more unused methods in UnsafeValues
3a9dc689 SPIGOT-7771: Material.getDefaultAttributes always returns an empty map

CraftBukkit Changes:
c3ceeb6f7 SPIGOT-7814: Call PlayerShearEntityEvent for Bogged
97b1e4f58 Fix wolf armor not dropping from use of shears
fd2ef563a SPIGOT-7812: Revert "SPIGOT-7809: Restore shield/banner conversion for base colours"
f672c351b SPIGOT-7811: Enchantments are applied on sweeping attack even if damage event is cancelled
cfe29350b SPIGOT-7808: Fix implementation of Enchantment#getName() for bad name return
19335f69e SPIGOT-7809: Restore shield/banner conversion for base colours
ae4f5a0be SPIGOT-7805: Fix jukebox deserialization
62e3b73a4 SPIGOT-7804: Fix written book serialization
aac911d26 SPIGOT-7800, SPIGOT-7801: Keep vanilla behaviour for items dropped on player death
13ece474f PR-1429: Implement TrialSpawnerSpawnEvent
bf13e9113 PR-1354: Improve spawner API and add API for Trial Spawners
515fe49e1 Increase outdated build delay
9cd5a19a0 SPIGOT-7794: Cancelling InventoryItemMoveEvent destroys items
ce40c7b14 SPIGOT-7796: Kickplayer newlines not working
5167256ff SPIGOT-7795: Fix damage/stats ignore the invulnerable damage time
f993563ee Improve cross-world teleportation handling
ab29122cf PR-1433: HumanEntity#openInventory(InventoryView) should only support views belonging to the player
764a541c5 SPIGOT-7732: Issue with the "hurt()" method of EntityLiving and invulnerable time
820084b5f SPIGOT-7791: Skull BlockState with null profile causes NullPointerException
5e46f1c82 SPIGOT-7785: Teleporting a player at the right moment can mess up vanilla teleportation
cbd95a6b3 SPIGOT-7772: Include hidden / non-sampled players in player count
3153debc5 SPIGOT-7790: Server crashes after bee nest is forced to update
e77bb26bb SPIGOT-7788: The healing power of friendship advancement is never granted
ee3d7258a SPIGOT-7789: Fix NPE in CraftMetaFirework applyToItem
2889b3a11 PR-1429: Add CreatureSpawnEvent.SpawnReason#TRIAL_SPAWNER
cdd05bc7f SPIGOT-7777: Speed attribute stays after death; missing EntityPotionEffectEvent call
d0e6af2d4 PR-1428: Expose Creeper igniter
d01c70e93 PR-1425: Fix bytecode transformation taking care of class-to-interface compatibility.
b2b08f68c SPIGOT-7770: Fix certain shaped recipes not registering
3f8e4161f PR-1426: Deprecate more unused methods in UnsafeValues
2c9dd879e SPIGOT-7771: Material.getDefaultAttributes always returns an empty map

Spigot Changes:
491f3675 Rebuild patches
0a642bd7 Rebuild patches
8897571b Rebuild patches
cb8cf80c Fix newlines in custom restart message
1aabe506 Rebuild patches
2024-07-06 21:19:14 +02:00

215 lines
17 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: SoSeDiK <mrsosedik@gmail.com>
Date: Mon, 21 Mar 2022 20:00:53 +0200
Subject: [PATCH] Fix new block data for EntityChangeBlockEvent
Also standardizes how to handle EntityChangeBlockEvent before a removeBlock or destroyBlock
call. Always use 'state.getFluidState().createLegacyBlock()' to get the new state instead of
just using the 'air' state.
Also fixes the new block data for EntityBreakDoorEvent (a sub-event from
EntityChangeBlockEvent)
Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java b/src/main/java/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
index 6a7052cd6ec88ed4aaea2fef0ebc750060d1dec0..2ade08d1466660ee1787fa97908002ef56389712 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
@@ -108,7 +108,7 @@ public class HarvestFarmland extends Behavior<Villager> {
Block block1 = world.getBlockState(this.aboveFarmlandPos.below()).getBlock();
if (block instanceof CropBlock && ((CropBlock) block).isMaxAge(iblockdata)) {
- if (CraftEventFactory.callEntityChangeBlockEvent(entity, this.aboveFarmlandPos, Blocks.AIR.defaultBlockState())) { // CraftBukkit
+ if (CraftEventFactory.callEntityChangeBlockEvent(entity, this.aboveFarmlandPos, iblockdata.getFluidState().createLegacyBlock())) { // CraftBukkit // Paper - fix wrong block state
world.destroyBlock(this.aboveFarmlandPos, true, entity);
} // CraftBukkit
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/BreakDoorGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/BreakDoorGoal.java
index 4253b3b1263a7ae5a2f5f3a34674dfea615a81ea..784a894688f98f9d0368a36d456c5c94e1ee3695 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/BreakDoorGoal.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/BreakDoorGoal.java
@@ -72,7 +72,7 @@ public class BreakDoorGoal extends DoorInteractGoal {
if (this.breakTime == this.getDoorBreakTime() && this.isValidDifficulty(this.mob.level().getDifficulty())) {
// CraftBukkit start
- if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreakDoorEvent(this.mob, this.doorPos).isCancelled()) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreakDoorEvent(this.mob, this.doorPos, this.mob.level().getFluidState(this.doorPos).createLegacyBlock()).isCancelled()) { // Paper - fix wrong block state
this.start();
return;
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/EatBlockGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/EatBlockGoal.java
index f4bc556e245179d0a4710e5255dd289aaafdceb7..d802985f1431be4332c07f0dab88feebedea4ce2 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/EatBlockGoal.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/EatBlockGoal.java
@@ -67,8 +67,9 @@ public class EatBlockGoal extends Goal {
if (this.eatAnimationTick == this.adjustedTickDelay(4)) {
BlockPos blockposition = this.mob.blockPosition();
- if (EatBlockGoal.IS_TALL_GRASS.test(this.level.getBlockState(blockposition))) {
- if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition, Blocks.AIR.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit
+ final BlockState blockState = this.level.getBlockState(blockposition); // Paper - fix wrong block state
+ if (EatBlockGoal.IS_TALL_GRASS.test(blockState)) { // Paper - fix wrong block state
+ if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition, blockState.getFluidState().createLegacyBlock(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit // Paper - fix wrong block state
this.level.destroyBlock(blockposition, false);
}
@@ -77,7 +78,7 @@ public class EatBlockGoal extends Goal {
BlockPos blockposition1 = blockposition.below();
if (this.level.getBlockState(blockposition1).is(Blocks.GRASS_BLOCK)) {
- if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition1, Blocks.AIR.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit
+ if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition1, Blocks.DIRT.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit // Paper - Fix wrong block state
this.level.levelEvent(2001, blockposition1, Block.getId(Blocks.GRASS_BLOCK.defaultBlockState()));
this.level.setBlock(blockposition1, Blocks.DIRT.defaultBlockState(), 2);
}
diff --git a/src/main/java/net/minecraft/world/entity/animal/Rabbit.java b/src/main/java/net/minecraft/world/entity/animal/Rabbit.java
index e5bd3039ef698fcea80a270b6111c2a663e5075c..0109c8ed8bf6a053674456fa4473934e028ca418 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Rabbit.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Rabbit.java
@@ -581,7 +581,7 @@ public class Rabbit extends Animal implements VariantHolder<Rabbit.Variant> {
if (i == 0) {
// CraftBukkit start
- if (!CraftEventFactory.callEntityChangeBlockEvent(this.rabbit, blockposition, Blocks.AIR.defaultBlockState())) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this.rabbit, blockposition, iblockdata.getFluidState().createLegacyBlock())) { // Paper - fix wrong block state
return;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
index 3cd4a744c3e3aeba90f342de9dea67ef2f3de626..1b49090a466bc74d9e5f2815314955b6dfbb83dc 100644
--- a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
+++ b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
@@ -377,7 +377,7 @@ public class WitherBoss extends Monster implements PowerableMob, RangedAttackMob
if (WitherBoss.canDestroy(iblockdata)) {
// CraftBukkit start
- if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR.defaultBlockState())) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, iblockdata.getFluidState().createLegacyBlock())) { // Paper - fix wrong block state
continue;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/entity/monster/EnderMan.java b/src/main/java/net/minecraft/world/entity/monster/EnderMan.java
index 7caa5469a4daa5d0c569f446ff2d597a9f10e8ac..828c51477cd8f35d591367b30bf4feef6a250292 100644
--- a/src/main/java/net/minecraft/world/entity/monster/EnderMan.java
+++ b/src/main/java/net/minecraft/world/entity/monster/EnderMan.java
@@ -565,7 +565,7 @@ public class EnderMan extends Monster implements NeutralMob {
boolean flag = movingobjectpositionblock.getBlockPos().equals(blockposition);
if (iblockdata.is(BlockTags.ENDERMAN_HOLDABLE) && flag) {
- if (CraftEventFactory.callEntityChangeBlockEvent(this.enderman, blockposition, Blocks.AIR.defaultBlockState())) { // CraftBukkit - Place event
+ if (CraftEventFactory.callEntityChangeBlockEvent(this.enderman, blockposition, iblockdata.getFluidState().createLegacyBlock())) { // CraftBukkit - Place event // Paper - fix wrong block state
world.removeBlock(blockposition, false);
world.gameEvent((Holder) GameEvent.BLOCK_DESTROY, blockposition, GameEvent.Context.of(this.enderman, iblockdata));
this.enderman.setCarriedBlock(iblockdata.getBlock().defaultBlockState());
diff --git a/src/main/java/net/minecraft/world/entity/monster/Ravager.java b/src/main/java/net/minecraft/world/entity/monster/Ravager.java
index aa4111eef22546f8aa630228c51ef5761c9b373b..212d341425c0f93bba0376de69bea61ffcf4dbd6 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Ravager.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Ravager.java
@@ -151,7 +151,7 @@ public class Ravager extends Raider {
if (block instanceof LeavesBlock) {
// CraftBukkit start
- if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, net.minecraft.world.level.block.Blocks.AIR.defaultBlockState())) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, iblockdata.getFluidState().createLegacyBlock())) { // Paper - fix wrong block state
continue;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/entity/monster/Silverfish.java b/src/main/java/net/minecraft/world/entity/monster/Silverfish.java
index 9ff42b0ae2b82dc3092e38e1439d89b4ab554b17..860e385fc83f9787dca92efe35d21fd69c4dd635 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Silverfish.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Silverfish.java
@@ -162,7 +162,8 @@ public class Silverfish extends Monster {
if (block instanceof InfestedBlock) {
// CraftBukkit start
- if (!CraftEventFactory.callEntityChangeBlockEvent(this.silverfish, blockposition1, net.minecraft.world.level.block.Blocks.AIR.defaultBlockState())) {
+ BlockState afterState = world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) ? iblockdata.getFluidState().createLegacyBlock() : ((InfestedBlock) block).hostStateByInfested(world.getBlockState(blockposition1)); // Paper - fix wrong block state
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this.silverfish, blockposition1, afterState)) { // Paper - fix wrong block state
continue;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
index 58dc69fe319027c2b9ecfb9caf272368e81081df..5c6cb752f61c3f3c2960a337173fb7dfe86cc1d3 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
@@ -292,7 +292,7 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
if (iblockdata.is(BlockTags.FIRE)) {
// CraftBukkit start
- if (CraftEventFactory.callEntityChangeBlockEvent(this, pos, Blocks.AIR.defaultBlockState())) {
+ if (CraftEventFactory.callEntityChangeBlockEvent(this, pos, iblockdata.getFluidState().createLegacyBlock())) { // Paper - fix wrong block state
this.level().destroyBlock(pos, false, this);
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/level/block/ChorusFlowerBlock.java b/src/main/java/net/minecraft/world/level/block/ChorusFlowerBlock.java
index bb1487dd2c8e4374f75a102ab5e17ce9b2d31114..6709cb6b657a8612781c2fe4dd76ee38f329c5ba 100644
--- a/src/main/java/net/minecraft/world/level/block/ChorusFlowerBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ChorusFlowerBlock.java
@@ -284,7 +284,7 @@ public class ChorusFlowerBlock extends Block {
if (!world.isClientSide && projectile.mayInteract(world, blockposition) && projectile.mayBreak(world)) {
// CraftBukkit
- if (!CraftEventFactory.callEntityChangeBlockEvent(projectile, blockposition, Blocks.AIR.defaultBlockState())) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(projectile, blockposition, state.getFluidState().createLegacyBlock())) { // Paper - fix wrong block state
return;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/level/block/PointedDripstoneBlock.java b/src/main/java/net/minecraft/world/level/block/PointedDripstoneBlock.java
index ec9190abe3edf7c3845156bb967dddf6ae7c30ff..95cb7492ac691a8e8aa9894f701b802a7eda5446 100644
--- a/src/main/java/net/minecraft/world/level/block/PointedDripstoneBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/PointedDripstoneBlock.java
@@ -134,7 +134,7 @@ public class PointedDripstoneBlock extends Block implements Fallable, SimpleWate
if (projectile.mayInteract(world, blockposition) && projectile.mayBreak(world) && projectile instanceof ThrownTrident && projectile.getDeltaMovement().length() > 0.6D) {
// CraftBukkit start
- if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(projectile, blockposition, Blocks.AIR.defaultBlockState())) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(projectile, blockposition, state.getFluidState().createLegacyBlock())) { // Paper - fix wrong block state
return;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/level/block/TntBlock.java b/src/main/java/net/minecraft/world/level/block/TntBlock.java
index 4896ddca849646135ae101236e534ab8f59bd617..a3525ae6d83591664e1456f20d9732a8de0ec326 100644
--- a/src/main/java/net/minecraft/world/level/block/TntBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/TntBlock.java
@@ -158,7 +158,7 @@ public class TntBlock extends Block {
if (projectile.isOnFire() && projectile.mayInteract(world, blockposition)) {
// CraftBukkit start
- if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(projectile, blockposition, Blocks.AIR.defaultBlockState()) || !CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PROJECTILE, projectile, null)) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(projectile, blockposition, state.getFluidState().createLegacyBlock()) || !CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PROJECTILE, projectile, null)) { // Paper - fix wrong block state
return;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/level/block/WaterlilyBlock.java b/src/main/java/net/minecraft/world/level/block/WaterlilyBlock.java
index edc20745649b0837f1371c8d29e71fc0c8e5528f..932831bb5632ead5850842fc77192c841571162e 100644
--- a/src/main/java/net/minecraft/world/level/block/WaterlilyBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/WaterlilyBlock.java
@@ -37,7 +37,7 @@ public class WaterlilyBlock extends BushBlock {
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
if (world instanceof ServerLevel && entity instanceof Boat) {
// CraftBukkit start
- if (!CraftEventFactory.callEntityChangeBlockEvent(entity, pos, Blocks.AIR.defaultBlockState())) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, pos, state.getFluidState().createLegacyBlock())) { // Paper - fix wrong block state
return;
}
// CraftBukkit end
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 6bed9cce39eacf0f42ee4c6b007d2bdeb632b68f..4d5507e44d755588f18d992eb5f382f5f4fac273 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1365,11 +1365,11 @@ public class CraftEventFactory {
return event;
}
- public static EntityBreakDoorEvent callEntityBreakDoorEvent(Entity entity, BlockPos pos) {
+ public static EntityBreakDoorEvent callEntityBreakDoorEvent(Entity entity, BlockPos pos, net.minecraft.world.level.block.state.BlockState newState) { // Paper
org.bukkit.entity.Entity entity1 = entity.getBukkitEntity();
Block block = CraftBlock.at(entity.level(), pos);
- EntityBreakDoorEvent event = new EntityBreakDoorEvent((LivingEntity) entity1, block);
+ EntityBreakDoorEvent event = new EntityBreakDoorEvent((LivingEntity) entity1, block, newState.createCraftBlockData()); // Paper
entity1.getServer().getPluginManager().callEvent(event);
return event;