mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-17 05:41:26 +01:00
68e86d7297
Updated Upstream (Bukkit/CraftBukkit) 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: f02baa38 PR-988: Add World#getIntersectingChunks(BoundingBox) 9321d665 Move getItemInUse up to LivingEntity 819eef73 PR-959: Add access to current item's remaining ticks c4fdadb0 SPIGOT-7601: Add AbstractArrow#getItem be8261ca Add support for Java 22 26119676 PR-979: Add more translation keys 66753362 PR-985: Correct book maximum pages and characters per page documentation c8be92fa PR-980: Improve getArmorContents() documentation f1120ee2 PR-983: Expose riptide velocity to PlayerRiptideEvent CraftBukkit Changes: dfaa89bbe PR-1369: Add World#getIntersectingChunks(BoundingBox) 51bbab2b9 Move getItemInUse up to LivingEntity 668e09602 PR-1331: Add access to current item's remaining ticks a639406d1 SPIGOT-7601: Add AbstractArrow#getItem 0398930fc SPIGOT-7602: Allow opening in-world horse and related inventories ffd15611c SPIGOT-7608: Allow empty lists to morph to any PDT list 2188dcfa9 Add support for Java 22 45d6a609f SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime" 06d915943 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime ca3bc3707 PR-1361: Add more translation keys 366c3ca80 SPIGOT-7600: EntityChangeBlockEvent is not fired for frog eggs 06d0f9ba8 SPIGOT-7593: Fix sapling growth physics / client-side updates 45c2608e4 PR-1366: Expose riptide velocity to PlayerRiptideEvent 29b6bb79b SPIGOT-7587: Remove fixes for now-resolved MC-142590 and MC-109346
319 lines
19 KiB
Diff
319 lines
19 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Mon, 9 Aug 2021 20:45:46 -0700
|
|
Subject: [PATCH] Fire EntityChangeBlockEvent in more places
|
|
|
|
Co-authored-by: ChristopheG <61288881+chrisgdt@users.noreply.github.com>
|
|
Co-authored-by: maxcom1 <46265094+maxcom1@users.noreply.github.com>
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LightningBolt.java b/src/main/java/net/minecraft/world/entity/LightningBolt.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LightningBolt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LightningBolt.java
|
|
@@ -0,0 +0,0 @@ public class LightningBolt extends Entity {
|
|
}
|
|
|
|
this.powerLightningRod();
|
|
- LightningBolt.clearCopperOnLightningStrike(this.level(), this.getStrikePosition());
|
|
+ LightningBolt.clearCopperOnLightningStrike(this.level(), this.getStrikePosition(), this); // Paper - Call EntityChangeBlockEvent
|
|
this.gameEvent(GameEvent.LIGHTNING_STRIKE);
|
|
}
|
|
}
|
|
@@ -0,0 +0,0 @@ public class LightningBolt extends Entity {
|
|
}
|
|
}
|
|
|
|
- private static void clearCopperOnLightningStrike(Level world, BlockPos pos) {
|
|
+ private static void clearCopperOnLightningStrike(Level world, BlockPos pos, Entity lightning) { // Paper - Call EntityChangeBlockEvent
|
|
BlockState iblockdata = world.getBlockState(pos);
|
|
BlockPos blockposition1;
|
|
BlockState iblockdata1;
|
|
@@ -0,0 +0,0 @@ public class LightningBolt extends Entity {
|
|
}
|
|
|
|
if (iblockdata1.getBlock() instanceof WeatheringCopper) {
|
|
- world.setBlockAndUpdate(blockposition1, WeatheringCopper.getFirst(world.getBlockState(blockposition1)));
|
|
+ // Paper start - Call EntityChangeBlockEvent
|
|
+ BlockState newBlock = WeatheringCopper.getFirst(world.getBlockState(blockposition1));
|
|
+ if (CraftEventFactory.callEntityChangeBlockEvent(lightning, blockposition1, newBlock)) {
|
|
+ world.setBlockAndUpdate(blockposition1, newBlock);
|
|
+ }
|
|
+ // Paper end - Call EntityChangeBlockEvent
|
|
BlockPos.MutableBlockPos blockposition_mutableblockposition = pos.mutable();
|
|
int i = world.random.nextInt(3) + 3;
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
int k = world.random.nextInt(8) + 1;
|
|
|
|
- LightningBolt.randomWalkCleaningCopper(world, blockposition1, blockposition_mutableblockposition, k);
|
|
+ LightningBolt.randomWalkCleaningCopper(world, blockposition1, blockposition_mutableblockposition, k, lightning); // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
- private static void randomWalkCleaningCopper(Level world, BlockPos pos, BlockPos.MutableBlockPos mutablePos, int count) {
|
|
+ private static void randomWalkCleaningCopper(Level world, BlockPos pos, BlockPos.MutableBlockPos mutablePos, int count, Entity lightning) { // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent
|
|
mutablePos.set(pos);
|
|
|
|
for (int j = 0; j < count; ++j) {
|
|
- Optional<BlockPos> optional = LightningBolt.randomStepCleaningCopper(world, mutablePos);
|
|
+ Optional<BlockPos> optional = LightningBolt.randomStepCleaningCopper(world, mutablePos, lightning); // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent
|
|
|
|
if (optional.isEmpty()) {
|
|
break;
|
|
@@ -0,0 +0,0 @@ public class LightningBolt extends Entity {
|
|
|
|
}
|
|
|
|
- private static Optional<BlockPos> randomStepCleaningCopper(Level world, BlockPos pos) {
|
|
+ private static Optional<BlockPos> randomStepCleaningCopper(Level world, BlockPos pos, Entity lightning) { // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent
|
|
Iterator iterator = BlockPos.randomInCube(world.random, 10, pos, 1).iterator();
|
|
|
|
BlockPos blockposition1;
|
|
@@ -0,0 +0,0 @@ public class LightningBolt extends Entity {
|
|
|
|
BlockPos blockposition1Final = blockposition1; // CraftBukkit - decompile error
|
|
WeatheringCopper.getPrevious(iblockdata).ifPresent((iblockdata1) -> {
|
|
+ if (CraftEventFactory.callEntityChangeBlockEvent(lightning, blockposition1Final, iblockdata1)) // Paper - call EntityChangeBlockEvent
|
|
world.setBlockAndUpdate(blockposition1Final, iblockdata1); // CraftBukkit - decompile error
|
|
});
|
|
world.levelEvent(3002, blockposition1, -1);
|
|
diff --git a/src/main/java/net/minecraft/world/item/AxeItem.java b/src/main/java/net/minecraft/world/item/AxeItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/AxeItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/AxeItem.java
|
|
@@ -0,0 +0,0 @@ public class AxeItem extends DiggerItem {
|
|
return InteractionResult.PASS;
|
|
} else {
|
|
ItemStack itemStack = context.getItemInHand();
|
|
+ // Paper start - EntityChangeBlockEvent
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, blockPos, optional.get())) {
|
|
+ return InteractionResult.PASS;
|
|
+ }
|
|
+ // Paper end
|
|
if (player instanceof ServerPlayer) {
|
|
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer)player, blockPos, itemStack);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/item/EnderEyeItem.java b/src/main/java/net/minecraft/world/item/EnderEyeItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/EnderEyeItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/EnderEyeItem.java
|
|
@@ -0,0 +0,0 @@ public class EnderEyeItem extends Item {
|
|
return InteractionResult.SUCCESS;
|
|
} else {
|
|
BlockState iblockdata1 = (BlockState) iblockdata.setValue(EndPortalFrameBlock.HAS_EYE, true);
|
|
+ // Paper start
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(context.getPlayer(), blockposition, iblockdata1)) {
|
|
+ return InteractionResult.PASS;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
Block.pushEntitiesUp(iblockdata, iblockdata1, world, blockposition);
|
|
world.setBlock(blockposition, iblockdata1, 2);
|
|
diff --git a/src/main/java/net/minecraft/world/item/HoneycombItem.java b/src/main/java/net/minecraft/world/item/HoneycombItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/HoneycombItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/HoneycombItem.java
|
|
@@ -0,0 +0,0 @@ public class HoneycombItem extends Item implements SignApplicator {
|
|
return getWaxed(blockState).map((state) -> {
|
|
Player player = context.getPlayer();
|
|
ItemStack itemStack = context.getItemInHand();
|
|
+ // Paper start - EntityChangeBlockEvent
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, blockPos, state)) {
|
|
+ if (!player.isCreative()) {
|
|
+ player.containerMenu.sendAllDataToRemote();
|
|
+ }
|
|
+ return InteractionResult.PASS;
|
|
+ }
|
|
+ // Paper end
|
|
if (player instanceof ServerPlayer) {
|
|
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer)player, blockPos, itemStack);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/item/PotionItem.java b/src/main/java/net/minecraft/world/item/PotionItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/PotionItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/PotionItem.java
|
|
@@ -0,0 +0,0 @@ public class PotionItem extends Item {
|
|
BlockState iblockdata = world.getBlockState(blockposition);
|
|
|
|
if (context.getClickedFace() != Direction.DOWN && iblockdata.is(BlockTags.CONVERTABLE_TO_MUD) && PotionUtils.getPotion(itemstack) == Potions.WATER) {
|
|
+ // Paper start
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entityhuman, blockposition, Blocks.MUD.defaultBlockState())) {
|
|
+ entityhuman.containerMenu.sendAllDataToRemote();
|
|
+ return InteractionResult.PASS;
|
|
+ }
|
|
+ // Paper end
|
|
world.playSound((Player) null, blockposition, SoundEvents.GENERIC_SPLASH, SoundSource.BLOCKS, 1.0F, 1.0F);
|
|
entityhuman.setItemInHand(context.getHand(), ItemUtils.createFilledResult(itemstack, entityhuman, new ItemStack(Items.GLASS_BOTTLE)));
|
|
entityhuman.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
|
|
diff --git a/src/main/java/net/minecraft/world/item/ShovelItem.java b/src/main/java/net/minecraft/world/item/ShovelItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/ShovelItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/ShovelItem.java
|
|
@@ -0,0 +0,0 @@ public class ShovelItem extends DiggerItem {
|
|
Player player = context.getPlayer();
|
|
BlockState blockState2 = FLATTENABLES.get(blockState.getBlock());
|
|
BlockState blockState3 = null;
|
|
+ Runnable afterAction = null; // Paper
|
|
if (blockState2 != null && level.getBlockState(blockPos.above()).isAir()) {
|
|
- level.playSound(player, blockPos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
|
|
+ afterAction = () -> level.playSound(player, blockPos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); // Paper
|
|
blockState3 = blockState2;
|
|
} else if (blockState.getBlock() instanceof CampfireBlock && blockState.getValue(CampfireBlock.LIT)) {
|
|
+ afterAction = () -> { // Paper
|
|
if (!level.isClientSide()) {
|
|
level.levelEvent((Player)null, 1009, blockPos, 0);
|
|
}
|
|
|
|
CampfireBlock.dowse(context.getPlayer(), level, blockPos, blockState);
|
|
+ }; // Paper
|
|
blockState3 = blockState.setValue(CampfireBlock.LIT, Boolean.valueOf(false));
|
|
}
|
|
|
|
if (blockState3 != null) {
|
|
if (!level.isClientSide) {
|
|
+ // Paper start
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(context.getPlayer(), blockPos, blockState3)) {
|
|
+ return InteractionResult.PASS;
|
|
+ }
|
|
+ afterAction.run();
|
|
+ // Paper end
|
|
level.setBlock(blockPos, blockState3, 11);
|
|
level.gameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Context.of(player, blockState3));
|
|
if (player != null) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/CakeBlock.java b/src/main/java/net/minecraft/world/level/block/CakeBlock.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/CakeBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/CakeBlock.java
|
|
@@ -0,0 +0,0 @@ public class CakeBlock extends Block {
|
|
Block block = Block.byItem(item);
|
|
|
|
if (block instanceof CandleBlock) {
|
|
+ // Paper start - call change block event
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, pos, CandleCakeBlock.byCandle(block))) {
|
|
+ player.containerMenu.sendAllDataToRemote(); // update inv because candle could decrease
|
|
+ return InteractionResult.PASS;
|
|
+ }
|
|
+ // Paper end - call change block event
|
|
if (!player.isCreative()) {
|
|
itemstack.shrink(1);
|
|
}
|
|
@@ -0,0 +0,0 @@ public class CakeBlock extends Block {
|
|
if (!player.canEat(false)) {
|
|
return InteractionResult.PASS;
|
|
} else {
|
|
+ // Paper start - call change block event
|
|
+ int i = state.getValue(CakeBlock.BITES);
|
|
+ final BlockState newState = i < MAX_BITES ? state.setValue(CakeBlock.BITES, i + 1) : world.getFluidState(pos).createLegacyBlock();
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, pos, newState)) {
|
|
+ ((net.minecraft.server.level.ServerPlayer) player).getBukkitEntity().sendHealthUpdate();
|
|
+ return InteractionResult.PASS; // return a non-consume result to cake blocks don't drop their candles
|
|
+ }
|
|
+ // Paper end - call change block event
|
|
player.awardStat(Stats.EAT_CAKE_SLICE);
|
|
// CraftBukkit start
|
|
// entityhuman.getFoodData().eat(2, 0.1F);
|
|
@@ -0,0 +0,0 @@ public class CakeBlock extends Block {
|
|
|
|
((net.minecraft.server.level.ServerPlayer) player).getBukkitEntity().sendHealthUpdate();
|
|
// CraftBukkit end
|
|
- int i = (Integer) state.getValue(CakeBlock.BITES);
|
|
+ // Paper - move up
|
|
|
|
world.gameEvent((Entity) player, GameEvent.EAT, pos);
|
|
if (i < 6) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
|
|
@@ -0,0 +0,0 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
if (i < 8 && ComposterBlock.COMPOSTABLES.containsKey(itemstack.getItem())) {
|
|
if (i < 7 && !world.isClientSide) {
|
|
BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, itemstack);
|
|
+ // Paper start - handle cancelled events
|
|
+ if (iblockdata1 == null) {
|
|
+ return InteractionResult.PASS;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
|
|
player.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
|
|
@@ -0,0 +0,0 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
if (i < 7 && ComposterBlock.COMPOSTABLES.containsKey(stack.getItem())) {
|
|
// CraftBukkit start
|
|
double rand = world.getRandom().nextDouble();
|
|
- BlockState iblockdata1 = ComposterBlock.addItem(user, state, DummyGeneratorAccess.INSTANCE, pos, stack, rand);
|
|
- if (state == iblockdata1 || !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(user, pos, iblockdata1)) {
|
|
+ BlockState iblockdata1 = null; // Paper
|
|
+ if (false && (state == iblockdata1 || !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(user, pos, iblockdata1))) { // Paper - move event call into addItem
|
|
return state;
|
|
}
|
|
iblockdata1 = ComposterBlock.addItem(user, state, world, pos, stack, rand);
|
|
+ // Paper start - handle cancelled events
|
|
+ if (iblockdata1 == null) {
|
|
+ return state;
|
|
+ }
|
|
+ // Paper end
|
|
// CraftBukkit end
|
|
|
|
stack.shrink(1);
|
|
@@ -0,0 +0,0 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
return iblockdata1;
|
|
}
|
|
|
|
+ @Nullable // Paper
|
|
static BlockState addItem(@Nullable Entity user, BlockState state, LevelAccessor world, BlockPos pos, ItemStack stack) {
|
|
// CraftBukkit start
|
|
return ComposterBlock.addItem(user, state, world, pos, stack, world.getRandom().nextDouble());
|
|
}
|
|
|
|
+ @Nullable // Paper - make it nullable
|
|
static BlockState addItem(@Nullable Entity entity, BlockState iblockdata, LevelAccessor generatoraccess, BlockPos blockposition, ItemStack itemstack, double rand) {
|
|
// CraftBukkit end
|
|
int i = (Integer) iblockdata.getValue(ComposterBlock.LEVEL);
|
|
@@ -0,0 +0,0 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
} else {
|
|
int j = i + 1;
|
|
BlockState iblockdata1 = (BlockState) iblockdata.setValue(ComposterBlock.LEVEL, j);
|
|
+ // Paper start - move the EntityChangeBlockEvent here to avoid conflict later for the compost events
|
|
+ if (entity != null && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1)) {
|
|
+ return null;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
generatoraccess.setBlock(blockposition, iblockdata1, 3);
|
|
generatoraccess.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.Context.of(entity, iblockdata1));
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
|
|
@@ -0,0 +0,0 @@ public class BeehiveBlockEntity extends BlockEntity {
|
|
--j;
|
|
}
|
|
|
|
- world.setBlockAndUpdate(blockposition, (BlockState) iblockdata.setValue(BeehiveBlock.HONEY_LEVEL, i + j));
|
|
+ // Paper start - Fire EntityChangeBlockEvent in more places
|
|
+ BlockState newBlockState = iblockdata.setValue(BeehiveBlock.HONEY_LEVEL, i + j);
|
|
+
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entitybee, blockposition, newBlockState)) {
|
|
+ world.setBlockAndUpdate(blockposition, newBlockState);
|
|
+ }
|
|
+ // Paper end - Fire EntityChangeBlockEvent in more places
|
|
}
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
|
|
@@ -0,0 +0,0 @@ public class DummyGeneratorAccess implements WorldGenLevel {
|
|
|
|
@Override
|
|
public void gameEvent(GameEvent event, Vec3 emitterPos, GameEvent.Context emitter) {
|
|
- // Used by BlockComposter
|
|
+ // Used by ComposterBlock
|
|
}
|
|
|
|
@Override
|