Call BlockRedstoneEvents properly

Call BlockRedstoneEvents for lecterns.
Fix previous power level for experimental redstone wire.
This commit is contained in:
Warrior 2023-09-13 05:46:10 +02:00
parent 5688b5cf50
commit d4ab21c047
2 changed files with 19 additions and 2 deletions

View File

@ -1,6 +1,23 @@
--- a/net/minecraft/world/level/block/LecternBlock.java
+++ b/net/minecraft/world/level/block/LecternBlock.java
@@ -206,11 +206,12 @@
@@ -175,6 +175,16 @@
}
private static void changePowered(Level world, BlockPos pos, BlockState state, boolean powered) {
+ // Paper start - Call BlockRedstoneEvent properly
+ final int currentRedstoneLevel = state.getValue(LecternBlock.POWERED) ? 15 : 0, targetRedstoneLevel = powered ? 15 : 0;
+ if (currentRedstoneLevel != targetRedstoneLevel) {
+ final org.bukkit.event.block.BlockRedstoneEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, pos, currentRedstoneLevel, targetRedstoneLevel);
+
+ if (event.getNewCurrent() != targetRedstoneLevel) {
+ return;
+ }
+ }
+ // Paper end - Call BlockRedstoneEvent properly
world.setBlock(pos, (BlockState) state.setValue(LecternBlock.POWERED, powered), 3);
LecternBlock.updateBelow(world, pos, state);
}
@@ -206,11 +216,12 @@
}
private void popBook(BlockState state, Level world, BlockPos pos) {

View File

@ -17,7 +17,7 @@
- if (iblockdata1.is((Block) this.wireBlock) && !((Integer) iblockdata1.getValue(RedStoneWireBlock.POWER)).equals(j)) {
+ // CraftBukkit start
+ int oldPower = state.getValue(RedStoneWireBlock.POWER);
+ int oldPower = iblockdata1.getValue(RedStoneWireBlock.POWER); // Paper - Call BlockRedstoneEvent properly; get the previous power from the right state
+ if (oldPower != j) {
+ BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, blockposition1), oldPower, j);
+ world.getCraftServer().getPluginManager().callEvent(event);