Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BlockRedstoneEvent for tripwire hooks #9724

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions patches/server/0879-Call-BlockRedstoneEvent-properly.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Warrior <[email protected]>
Date: Wed, 13 Sep 2023 05:46:10 +0200
Subject: [PATCH] Call BlockRedstoneEvent properly

Call BlockRedstoneEvents for lecterns

Fix BlockRedstoneEvent for tripwire hooks
Previously the event was called for any state update even non redstone related.
Now only two events are always at least fired (one per hook), more when
the events are cancelled.

Co-authored-by: Lulu13022002 <[email protected]>

diff --git a/src/main/java/net/minecraft/world/level/block/LecternBlock.java b/src/main/java/net/minecraft/world/level/block/LecternBlock.java
index 751ff3d51f8ae57f847c3acf7a7cd663a6ae1c68..405923b0e058e4a179d1aac54b6b233899e3b33e 100644
--- a/src/main/java/net/minecraft/world/level/block/LecternBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/LecternBlock.java
@@ -179,6 +179,16 @@ public class LecternBlock extends BaseEntityBlock {
}

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);
}
diff --git a/src/main/java/net/minecraft/world/level/block/TripWireHookBlock.java b/src/main/java/net/minecraft/world/level/block/TripWireHookBlock.java
index 8614fad5b3df7a6030384b108b1689bf6b9f1209..a6991039bc76cceee572b925a1f3e8e18dd27b38 100644
--- a/src/main/java/net/minecraft/world/level/block/TripWireHookBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/TripWireHookBlock.java
@@ -169,24 +169,44 @@ public class TripWireHookBlock extends Block {
flag5 &= flag4;
BlockState iblockdata3 = (BlockState) ((BlockState) block.defaultBlockState().trySetValue(TripWireHookBlock.ATTACHED, flag4)).trySetValue(TripWireHookBlock.POWERED, flag5);

+ boolean cancelledEmitterHook = false, cancelledReceiverHook = false; // Paper - Call BlockRedstoneEvent properly
+ boolean wasPowered = flag3, willBePowered = flag5; // Paper - OBFHELPER
if (j > 0) {
blockposition1 = pos.relative(enumdirection, j);
+ // Paper start - Call BlockRedstoneEvent properly
+ if (wasPowered != willBePowered) {
+ int newCurrent = willBePowered ? 15 : 0;
+ BlockRedstoneEvent redstoneEvent = new BlockRedstoneEvent(CraftBlock.at(world, blockposition1), wasPowered ? 15 : 0, newCurrent);
+ world.getCraftServer().getPluginManager().callEvent(redstoneEvent);
+ if (redstoneEvent.getNewCurrent() != newCurrent) {
+ cancelledReceiverHook = true;
+ }
+ }
+ if (!cancelledReceiverHook) { // always trigger two events even when the first hook current change is cancelled
+ // Paper end - Call BlockRedstoneEvent properly
Direction enumdirection1 = enumdirection.getOpposite();

world.setBlock(blockposition1, (BlockState) iblockdata3.setValue(TripWireHookBlock.FACING, enumdirection1), 3);
TripWireHookBlock.notifyNeighbors(block, world, blockposition1, enumdirection1);
TripWireHookBlock.emitState(world, blockposition1, flag4, flag5, flag2, flag3);
+ } // Paper - Call BlockRedstoneEvent properly
}

+ if (wasPowered != willBePowered) { // Paper - Call BlockRedstoneEvent properly
+ int newCurrent = willBePowered ? 15 : 0; // Paper - Call BlockRedstoneEvent properly
// CraftBukkit start
- BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(CraftBlock.at(world, pos), 15, 0);
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(CraftBlock.at(world, pos), wasPowered ? 15 : 0, newCurrent); // Paper - Call BlockRedstoneEvent properly
world.getCraftServer().getPluginManager().callEvent(eventRedstone);

- if (eventRedstone.getNewCurrent() > 0) {
- return;
+ // Paper start - Call BlockRedstoneEvent properly
+ if (eventRedstone.getNewCurrent() != newCurrent) {
+ cancelledEmitterHook = true;
+ }
+ // Paper end - Call BlockRedstoneEvent properly
}
// CraftBukkit end

+ if (!cancelledEmitterHook) { // Paper - Call BlockRedstoneEvent properly
TripWireHookBlock.emitState(world, pos, flag4, flag5, flag2, flag3);
if (!flag) {
if (world.getBlockState(pos).getBlock() == Blocks.TRIPWIRE_HOOK) // Paper - Validate tripwire hook placement before update
@@ -195,6 +215,7 @@ public class TripWireHookBlock extends Block {
TripWireHookBlock.notifyNeighbors(block, world, pos, enumdirection);
}
}
+ } // Paper - Call BlockRedstoneEvent properly

if (flag2 != flag4) {
for (int l = 1; l < j; ++l) {
27 changes: 0 additions & 27 deletions patches/server/0879-Call-BlockRedstoneEvents-for-lecterns.patch

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Fix tripwire disarming not working as intended
Fixes MC-129055

diff --git a/src/main/java/net/minecraft/world/level/block/TripWireHookBlock.java b/src/main/java/net/minecraft/world/level/block/TripWireHookBlock.java
index 8614fad5b3df7a6030384b108b1689bf6b9f1209..76aca266d3f3222502ff4c196228f08fcd88c5f8 100644
index a6991039bc76cceee572b925a1f3e8e18dd27b38..e8607bece6108f68b2a379e6b4aa65958b8a9861 100644
--- a/src/main/java/net/minecraft/world/level/block/TripWireHookBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/TripWireHookBlock.java
@@ -202,9 +202,8 @@ public class TripWireHookBlock extends Block {
@@ -223,9 +223,8 @@ public class TripWireHookBlock extends Block {
BlockState iblockdata4 = aiblockdata[l];

if (iblockdata4 != null) {
Expand Down
Loading