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 #11791

Merged
merged 1 commit into from
Dec 26, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,21 +1,65 @@
--- a/net/minecraft/world/level/block/TripWireHookBlock.java
+++ b/net/minecraft/world/level/block/TripWireHookBlock.java
@@ -173,9 +_,18 @@
@@ -127,10 +_,10 @@
if (optionalValue.isPresent()) {
Direction direction = optionalValue.get();
boolean flag = hookState.getOptionalValue(ATTACHED).orElse(false);
- boolean flag1 = hookState.getOptionalValue(POWERED).orElse(false);
+ boolean flag1 = hookState.getOptionalValue(POWERED).orElse(false); // Paper - diff on change, for event below
Block block = hookState.getBlock();
boolean flag2 = !attaching;
- boolean flag3 = false;
+ boolean flag3 = false; // Paper - diff on change, for event below
int i = 0;
BlockState[] blockStates = new BlockState[42];

@@ -166,21 +_,48 @@
flag2 &= i > 1;
flag3 &= flag2;
BlockState blockState1 = block.defaultBlockState().trySetValue(ATTACHED, Boolean.valueOf(flag2)).trySetValue(POWERED, Boolean.valueOf(flag3));
+ boolean cancelledEmitterHook = false, cancelledReceiverHook = false; // Paper - Call BlockRedstoneEvent
+ boolean wasPowered = flag1, willBePowered = flag3; // Paper - OBFHELPER
Lulu13022002 marked this conversation as resolved.
Show resolved Hide resolved
if (i > 0) {
BlockPos blockPosx = pos.relative(direction, i);
+ // Paper start - Call BlockRedstoneEvent
+ if (wasPowered != willBePowered) {
+ int newCurrent = willBePowered ? 15 : 0;
+ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(
+ org.bukkit.craftbukkit.block.CraftBlock.at(level, blockPosx), wasPowered ? 15 : 0, newCurrent
+ );
+ event.callEvent();
+ cancelledReceiverHook = event.getNewCurrent() != newCurrent;
+ }
+ if (!cancelledReceiverHook) { // always trigger two events even when the first hook current change is cancelled
+ // Paper end - Call BlockRedstoneEvent
Direction opposite = direction.getOpposite();
level.setBlock(blockPosx, blockState1.setValue(FACING, opposite), 3);
notifyNeighbors(block, level, blockPosx, opposite);
emitState(level, blockPosx, flag2, flag3, flag, flag1);
}
+ // CraftBukkit start
+ org.bukkit.event.block.BlockRedstoneEvent eventRedstone = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), 15, 0);
+ level.getCraftServer().getPluginManager().callEvent(eventRedstone);
+
+ if (eventRedstone.getNewCurrent() > 0) {
+ return;
- }
+ } // Paper - Call BlockRedstoneEvent
+ }
+ // Paper start - Call BlockRedstoneEvent
+ if (wasPowered != willBePowered) {
+ int newCurrent = willBePowered ? 15 : 0;
+ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(
+ org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), wasPowered ? 15 : 0, newCurrent
+ );
+ event.callEvent();
+ cancelledEmitterHook = event.getNewCurrent() != newCurrent;
+ }
+ // CraftBukkit end
+ // Paper end - Call BlockRedstoneEvent

+ if (!cancelledEmitterHook) { // Paper - Call BlockRedstoneEvent
emitState(level, pos, flag2, flag3, flag, flag1);
if (!attaching) {
+ if (level.getBlockState(pos).is(Blocks.TRIPWIRE_HOOK)) // Paper - Validate tripwire hook placement before update
level.setBlock(pos, blockState1.setValue(FACING, direction), 3);
if (shouldNotifyNeighbours) {
notifyNeighbors(block, level, pos, direction);
}
}
+ } // Paper - Call BlockRedstoneEvent

if (flag != flag2) {
for (int i2 = 1; i2 < i; i2++) {
Loading