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>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user