mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-25 14:00:15 +01:00
Fix BlockRedstoneEvent for tripwire hooks
This commit is contained in:
parent
b8a0541ccf
commit
735b7412bf
1 changed files with 53 additions and 9 deletions
|
@ -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
|
||||
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
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+ // 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;
|
||||
+ }
|
||||
+ // 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…
Reference in a new issue