13
0
geforkt von Mirrors/Paper

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>
Dieser Commit ist enthalten in:
Jake Potrebic 2021-08-09 20:45:46 -07:00
Ursprung 2aae5e2218
Commit 75c623590f
11 geänderte Dateien mit 261 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,24 @@
--- a/net/minecraft/world/effect/WeavingMobEffect.java
+++ b/net/minecraft/world/effect/WeavingMobEffect.java
@@ -25,11 +25,11 @@
@Override
public void onMobRemoved(ServerLevel world, LivingEntity entity, int amplifier, Entity.RemovalReason reason) {
if (reason == Entity.RemovalReason.KILLED && (entity instanceof Player || world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) {
- this.spawnCobwebsRandomlyAround(world, entity.getRandom(), entity.blockPosition());
+ this.spawnCobwebsRandomlyAround(world, entity.getRandom(), entity.blockPosition(), entity); // Paper - Fire EntityChangeBlockEvent in more places
}
}
- private void spawnCobwebsRandomlyAround(ServerLevel world, RandomSource random, BlockPos pos) {
+ private void spawnCobwebsRandomlyAround(ServerLevel world, RandomSource random, BlockPos pos, LivingEntity entity) { // Paper - Fire EntityChangeBlockEvent in more places
Set<BlockPos> set = Sets.newHashSet();
int i = this.maxCobwebs.applyAsInt(random);
@@ -46,6 +46,7 @@
}
for (BlockPos blockPos3 : set) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockPos3, Blocks.COBWEB.defaultBlockState())) continue; // Paper - Fire EntityChangeBlockEvent in more places
world.setBlock(blockPos3, Blocks.COBWEB.defaultBlockState(), 3);
world.levelEvent(3018, blockPos3, 0);
}

Datei anzeigen

@ -11,6 +11,15 @@
public class LightningBolt extends Entity {
@@ -94,7 +98,7 @@
}
this.powerLightningRod();
- LightningBolt.clearCopperOnLightningStrike(this.level(), this.getStrikePosition());
+ LightningBolt.clearCopperOnLightningStrike(this.level(), this.getStrikePosition(), this); // Paper - Call EntityChangeBlockEvent
this.gameEvent(GameEvent.LIGHTNING_STRIKE);
}
}
@@ -120,7 +124,7 @@
}
}
@ -59,13 +68,66 @@
}
}
@@ -247,8 +259,9 @@
@@ -190,7 +202,7 @@
}
- 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;
@@ -204,24 +216,29 @@
}
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;
@@ -232,7 +249,7 @@
}
- 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;
@@ -247,8 +264,10 @@
iblockdata = world.getBlockState(blockposition1);
} while (!(iblockdata.getBlock() instanceof WeatheringCopper));
+ BlockPos blockposition1Final = blockposition1; // CraftBukkit - decompile error
WeatheringCopper.getPrevious(iblockdata).ifPresent((iblockdata1) -> {
- world.setBlockAndUpdate(blockposition1, iblockdata1);
+ if (CraftEventFactory.callEntityChangeBlockEvent(lightning, blockposition1Final, iblockdata1)) // Paper - call EntityChangeBlockEvent
+ world.setBlockAndUpdate(blockposition1Final, iblockdata1); // CraftBukkit - decompile error
});
world.levelEvent(3002, blockposition1, -1);

Datei anzeigen

@ -0,0 +1,14 @@
--- a/net/minecraft/world/item/AxeItem.java
+++ b/net/minecraft/world/item/AxeItem.java
@@ -67,6 +67,11 @@
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);
}

Datei anzeigen

@ -1,6 +1,18 @@
--- a/net/minecraft/world/item/EnderEyeItem.java
+++ b/net/minecraft/world/item/EnderEyeItem.java
@@ -62,7 +62,27 @@
@@ -45,6 +45,11 @@
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);
@@ -62,7 +67,27 @@
}
}
@ -29,7 +41,7 @@
}
return InteractionResult.SUCCESS;
@@ -99,7 +119,11 @@
@@ -99,7 +124,11 @@
entityendersignal.setItem(itemstack);
entityendersignal.signalTo(blockposition);
world.gameEvent((Holder) GameEvent.PROJECTILE_SHOOT, entityendersignal.position(), GameEvent.Context.of((Entity) user));

Datei anzeigen

@ -0,0 +1,17 @@
--- a/net/minecraft/world/item/HoneycombItem.java
+++ b/net/minecraft/world/item/HoneycombItem.java
@@ -74,6 +74,14 @@
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 serverPlayer) {
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger(serverPlayer, blockPos, itemStack);
}

Datei anzeigen

@ -0,0 +1,15 @@
--- a/net/minecraft/world/item/PotionItem.java
+++ b/net/minecraft/world/item/PotionItem.java
@@ -42,6 +42,12 @@
PotionContents potionContents = itemStack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
BlockState blockState = level.getBlockState(blockPos);
if (context.getClickedFace() != Direction.DOWN && blockState.is(BlockTags.CONVERTABLE_TO_MUD) && potionContents.is(Potions.WATER)) {
+ // Paper start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, blockPos, Blocks.MUD.defaultBlockState())) {
+ player.containerMenu.sendAllDataToRemote();
+ return InteractionResult.PASS;
+ }
+ // Paper end
level.playSound(null, blockPos, SoundEvents.GENERIC_SPLASH, SoundSource.BLOCKS, 1.0F, 1.0F);
player.setItemInHand(context.getHand(), ItemUtils.createFilledResult(itemStack, player, new ItemStack(Items.GLASS_BOTTLE)));
player.awardStat(Stats.ITEM_USED.get(itemStack.getItem()));

Datei anzeigen

@ -0,0 +1,33 @@
--- a/net/minecraft/world/item/ShovelItem.java
+++ b/net/minecraft/world/item/ShovelItem.java
@@ -46,20 +46,29 @@
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(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) {

Datei anzeigen

@ -1,14 +1,37 @@
--- a/net/minecraft/world/level/block/CakeBlock.java
+++ b/net/minecraft/world/level/block/CakeBlock.java
@@ -98,7 +98,18 @@
@@ -66,6 +66,12 @@
if (block instanceof CandleBlock) {
CandleBlock candleblock = (CandleBlock) block;
+ // Paper start - call change block event
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, pos, CandleCakeBlock.byCandle(candleblock))) {
+ player.containerMenu.sendAllDataToRemote(); // update inv because candle could decrease
+ return InteractionResult.TRY_WITH_EMPTY_HAND;
+ }
+ // Paper end - call change block event
stack.consume(1, player);
world.playSound((Player) null, pos, SoundEvents.CAKE_ADD_CANDLE, SoundSource.BLOCKS, 1.0F, 1.0F);
world.setBlockAndUpdate(pos, CandleCakeBlock.byCandle(candleblock));
@@ -97,10 +103,29 @@
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);
- player.getFoodData().eat(2, 0.1F);
- int i = (Integer) state.getValue(CakeBlock.BITES);
+ // CraftBukkit start
+ // entityhuman.getFoodData().eat(2, 0.1F);
+ int oldFoodLevel = player.getFoodData().foodLevel;
+
+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(player, 2 + oldFoodLevel);
+
+ if (!event.isCancelled()) {
@ -17,6 +40,8 @@
+
+ ((net.minecraft.server.level.ServerPlayer) player).getBukkitEntity().sendHealthUpdate();
+ // CraftBukkit end
int i = (Integer) state.getValue(CakeBlock.BITES);
+ // Paper - move up
+
world.gameEvent((Entity) player, (Holder) GameEvent.EAT, pos);
if (i < 6) {
world.setBlock(pos, (BlockState) state.setValue(CakeBlock.BITES, i + 1), 3);

Datei anzeigen

@ -11,23 +11,40 @@
public class ComposterBlock extends Block implements WorldlyContainerHolder {
@@ -269,7 +273,14 @@
@@ -241,6 +245,11 @@
if (i < 8 && ComposterBlock.COMPOSTABLES.containsKey(stack.getItem())) {
if (i < 7 && !world.isClientSide) {
BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, stack);
+ // 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(stack.getItem()));
@@ -269,7 +278,19 @@
int i = (Integer) state.getValue(ComposterBlock.LEVEL);
if (i < 7 && ComposterBlock.COMPOSTABLES.containsKey(stack.getItem())) {
- BlockState iblockdata1 = ComposterBlock.addItem(user, state, world, pos, stack);
+ // 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);
return iblockdata1;
@@ -279,6 +290,14 @@
@@ -279,6 +300,14 @@
}
public static BlockState extractProduce(Entity user, BlockState state, Level world, BlockPos pos) {
@ -42,9 +59,11 @@
if (!world.isClientSide) {
Vec3 vec3d = Vec3.atLowerCornerWithOffset(pos, 0.5D, 1.01D, 0.5D).offsetRandom(world.random, 0.7F);
ItemEntity entityitem = new ItemEntity(world, vec3d.x(), vec3d.y(), vec3d.z(), new ItemStack(Items.BONE_MEAL));
@@ -302,19 +321,25 @@
@@ -301,20 +330,33 @@
return iblockdata1;
}
+ @Nullable // Paper
static BlockState addItem(@Nullable Entity user, BlockState state, LevelAccessor world, BlockPos pos, ItemStack stack) {
- int i = (Integer) state.getValue(ComposterBlock.LEVEL);
- float f = ComposterBlock.COMPOSTABLES.getFloat(stack.getItem());
@ -54,6 +73,7 @@
- if ((i != 0 || f <= 0.0F) && world.getRandom().nextDouble() >= (double) f) {
- return state;
+ @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);
@ -65,6 +85,11 @@
int j = i + 1;
- BlockState iblockdata1 = (BlockState) state.setValue(ComposterBlock.LEVEL, j);
+ 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
- world.setBlock(pos, iblockdata1, 3);
- world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(user, iblockdata1));
@ -76,7 +101,7 @@
}
return iblockdata1;
@@ -354,7 +379,8 @@
@@ -354,7 +396,8 @@
public WorldlyContainer getContainer(BlockState state, LevelAccessor world, BlockPos pos) {
int i = (Integer) state.getValue(ComposterBlock.LEVEL);
@ -86,7 +111,7 @@
}
public static class OutputContainer extends SimpleContainer implements WorldlyContainer {
@@ -369,6 +395,7 @@
@@ -369,6 +412,7 @@
this.state = state;
this.level = world;
this.pos = pos;
@ -94,7 +119,7 @@
}
@Override
@@ -393,8 +420,15 @@
@@ -393,8 +437,15 @@
@Override
public void setChanged() {
@ -110,7 +135,7 @@
}
}
@@ -407,6 +441,7 @@
@@ -407,6 +458,7 @@
public InputContainer(BlockState state, LevelAccessor world, BlockPos pos) {
super(1);
@ -118,7 +143,7 @@
this.state = state;
this.level = world;
this.pos = pos;
@@ -449,8 +484,9 @@
@@ -449,8 +501,9 @@
public static class EmptyContainer extends SimpleContainer implements WorldlyContainer {

Datei anzeigen

@ -156,12 +156,18 @@
if (i < 5) {
int j = world.random.nextInt(100) == 0 ? 2 : 1;
@@ -211,27 +255,29 @@
@@ -211,27 +255,35 @@
--j;
}
- world.setBlockAndUpdate(pos, (BlockState) state.setValue(BeehiveBlock.HONEY_LEVEL, i + 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
}
}
}
@ -195,7 +201,7 @@
} else {
return false;
}
@@ -256,6 +302,10 @@
@@ -256,6 +308,10 @@
if (BeehiveBlockEntity.releaseOccupant(world, pos, state, tileentitybeehive_hivebee.toOccupant(), (List) null, tileentitybeehive_releasestatus, flowerPos)) {
flag = true;
iterator.remove();
@ -206,7 +212,7 @@
}
}
}
@@ -282,7 +332,7 @@
@@ -282,7 +338,7 @@
@Override
protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registries) {
super.loadAdditional(nbt, registries);
@ -215,7 +221,7 @@
if (nbt.contains("bees")) {
BeehiveBlockEntity.Occupant.LIST_CODEC.parse(NbtOps.INSTANCE, nbt.get("bees")).resultOrPartial((s) -> {
BeehiveBlockEntity.LOGGER.error("Failed to parse bees: '{}'", s);
@@ -291,7 +341,12 @@
@@ -291,7 +347,12 @@
});
}
@ -229,7 +235,7 @@
}
@Override
@@ -301,13 +356,14 @@
@@ -301,13 +362,14 @@
if (this.hasSavedFlowerPos()) {
nbt.put("flower_pos", NbtUtils.writeBlockPos(this.savedFlowerPos));
}
@ -245,7 +251,7 @@
List<BeehiveBlockEntity.Occupant> list = (List) components.getOrDefault(DataComponents.BEES, List.of());
list.forEach(this::storeBee);
@@ -348,7 +404,7 @@
@@ -348,7 +410,7 @@
CompoundTag nbttagcompound = new CompoundTag();
entity.save(nbttagcompound);
@ -254,7 +260,7 @@
Objects.requireNonNull(nbttagcompound);
list.forEach(nbttagcompound::remove);
@@ -367,7 +423,7 @@
@@ -367,7 +429,7 @@
@Nullable
public Entity createEntity(Level world, BlockPos pos) {
CompoundTag nbttagcompound = this.entityData.copyTag();
@ -263,7 +269,7 @@
Objects.requireNonNull(nbttagcompound);
list.forEach(nbttagcompound::remove);
@@ -391,6 +447,7 @@
@@ -391,6 +453,7 @@
}
private static void setBeeReleaseData(int ticksInHive, Bee beeEntity) {
@ -271,7 +277,7 @@
int j = beeEntity.getAge();
if (j < 0) {
@@ -400,6 +457,7 @@
@@ -400,6 +463,7 @@
}
beeEntity.setInLoveTime(Math.max(0, beeEntity.getInLoveTime() - ticksInHive));

Datei anzeigen

@ -120,7 +120,7 @@ public class DummyGeneratorAccess implements WorldGenLevel {
@Override
public void gameEvent(Holder<GameEvent> event, Vec3 emitterPos, GameEvent.Context emitter) {
// Used by BlockComposter
// Used by ComposterBlock
}
@Override