forked from PaperMC/Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call BlockRedstoneEvent for more interactions
- Loading branch information
1 parent
8de7e35
commit c546c62
Showing
32 changed files
with
323 additions
and
319 deletions.
There are no files selected for viewing
50 changes: 31 additions & 19 deletions
50
paper-api/src/main/java/org/bukkit/event/block/BlockRedstoneEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,70 @@ | ||
package org.bukkit.event.block; | ||
|
||
import com.google.common.base.Preconditions; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.HandlerList; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.checkerframework.common.value.qual.IntRange; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jspecify.annotations.NullMarked; | ||
|
||
/** | ||
* Called when a redstone current changes | ||
* Called when a redstone current changes. | ||
* <p> | ||
* It includes the relevant mutation of the {@code powered} and {@code power} | ||
* properties even if the block is not able to produce a redstone signal. | ||
* For the {@code powered} property, a high state will be considered as | ||
* a current of 15 and a low state as 0. Setting the new current to a different | ||
* value will prevent most action in this case. | ||
*/ | ||
@NullMarked | ||
public class BlockRedstoneEvent extends BlockEvent { | ||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
||
private final int oldCurrent; | ||
private int newCurrent; | ||
|
||
public BlockRedstoneEvent(@NotNull final Block block, final int oldCurrent, final int newCurrent) { | ||
@ApiStatus.Internal | ||
public BlockRedstoneEvent(final Block block, final int oldCurrent, final int newCurrent) { | ||
super(block); | ||
this.oldCurrent = oldCurrent; | ||
this.newCurrent = newCurrent; | ||
} | ||
|
||
/** | ||
* Gets the old current of this block | ||
* Gets the old current of this block. | ||
* | ||
* @return The previous current | ||
* @return the previous current | ||
*/ | ||
public int getOldCurrent() { | ||
return oldCurrent; | ||
public @IntRange(from = 0, to = 15) int getOldCurrent() { | ||
return this.oldCurrent; | ||
} | ||
|
||
/** | ||
* Gets the new current of this block | ||
* Gets the new current of this block. | ||
* | ||
* @return The new current | ||
* @return the new current | ||
*/ | ||
public int getNewCurrent() { | ||
return newCurrent; | ||
public @IntRange(from = 0, to = 15) int getNewCurrent() { | ||
return this.newCurrent; | ||
} | ||
|
||
/** | ||
* Sets the new current of this block | ||
* Sets the new current of this block. | ||
* | ||
* @param newCurrent The new current to set | ||
* @param newCurrent the new current to set | ||
*/ | ||
public void setNewCurrent(int newCurrent) { | ||
public void setNewCurrent(@IntRange(from = 0, to = 15) int newCurrent) { | ||
Preconditions.checkArgument(newCurrent >= 0 && newCurrent <= 15, "New current must be a redstone signal between 0 and 15 (was %s)", newCurrent); | ||
this.newCurrent = newCurrent; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
return HANDLER_LIST; | ||
} | ||
|
||
@NotNull | ||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
return HANDLER_LIST; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,10 @@ Co-authored-by: egg82 <[email protected]> | |
|
||
diff --git a/io/papermc/paper/redstone/RedstoneWireTurbo.java b/io/papermc/paper/redstone/RedstoneWireTurbo.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..ff747a1ecdf3c888bca0d69de4f85dcd810b6139 | ||
index 0000000000000000000000000000000000000000..759211f717ad117b4d4ab00445a811eccba30915 | ||
--- /dev/null | ||
+++ b/io/papermc/paper/redstone/RedstoneWireTurbo.java | ||
@@ -0,0 +1,954 @@ | ||
@@ -0,0 +1,951 @@ | ||
+package io.papermc.paper.redstone; | ||
+ | ||
+import java.util.List; | ||
|
@@ -36,8 +36,7 @@ index 0000000000000000000000000000000000000000..ff747a1ecdf3c888bca0d69de4f85dcd | |
+import net.minecraft.world.level.block.Block; | ||
+import net.minecraft.world.level.block.RedStoneWireBlock; | ||
+import net.minecraft.world.level.block.state.BlockState; | ||
+import org.bukkit.craftbukkit.block.CraftBlock; | ||
+import org.bukkit.event.block.BlockRedstoneEvent; | ||
+import org.bukkit.craftbukkit.event.CraftEventFactory; | ||
+ | ||
+import com.google.common.collect.Lists; | ||
+import com.google.common.collect.Maps; | ||
|
@@ -917,9 +916,7 @@ index 0000000000000000000000000000000000000000..ff747a1ecdf3c888bca0d69de4f85dcd | |
+ // egg82's amendment | ||
+ // Adding Bukkit's BlockRedstoneEvent - er.. event. | ||
+ if (i != j) { | ||
+ BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(worldIn, upd.self), i, j); | ||
+ worldIn.getCraftServer().getPluginManager().callEvent(event); | ||
+ j = event.getNewCurrent(); | ||
+ j = CraftEventFactory.callRedstoneChange(worldIn, upd.self, i, j).getNewCurrent(); | ||
+ } | ||
+ | ||
+ if (i != j) { | ||
|
@@ -978,10 +975,10 @@ index 0000000000000000000000000000000000000000..ff747a1ecdf3c888bca0d69de4f85dcd | |
+ } | ||
+} | ||
diff --git a/net/minecraft/world/level/block/RedStoneWireBlock.java b/net/minecraft/world/level/block/RedStoneWireBlock.java | ||
index 84e6c986917128d4488afa23d29c689cadb4f55d..f02232ce97779db0d12a5d5da1d767326d78ea4c 100644 | ||
index 84e6c986917128d4488afa23d29c689cadb4f55d..ebabc60f1be221536ba082d606fac3dd20a069da 100644 | ||
--- a/net/minecraft/world/level/block/RedStoneWireBlock.java | ||
+++ b/net/minecraft/world/level/block/RedStoneWireBlock.java | ||
@@ -290,6 +290,60 @@ public class RedStoneWireBlock extends Block { | ||
@@ -290,6 +290,57 @@ public class RedStoneWireBlock extends Block { | ||
return state.isFaceSturdy(level, pos, Direction.UP) || state.is(Blocks.HOPPER); | ||
} | ||
|
||
|
@@ -1021,10 +1018,7 @@ index 84e6c986917128d4488afa23d29c689cadb4f55d..f02232ce97779db0d12a5d5da1d76732 | |
+ int oldPower = state.getValue(POWER); | ||
+ int newPower = ((DefaultRedstoneWireEvaluator) evaluator).calculateTargetStrength(level, pos); | ||
+ if (oldPower != newPower) { | ||
+ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), oldPower, newPower); | ||
+ level.getCraftServer().getPluginManager().callEvent(event); | ||
+ | ||
+ newPower = event.getNewCurrent(); | ||
+ newPower = org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(level, pos, oldPower, newPower).getNewCurrent(); | ||
+ | ||
+ if (level.getBlockState(pos) == state) { | ||
+ state = state.setValue(POWER, newPower); | ||
|
@@ -1042,7 +1036,7 @@ index 84e6c986917128d4488afa23d29c689cadb4f55d..f02232ce97779db0d12a5d5da1d76732 | |
private void updatePowerStrength(Level level, BlockPos pos, BlockState state, @Nullable Orientation orientation, boolean updateShape) { | ||
if (useExperimentalEvaluator(level)) { | ||
new ExperimentalRedstoneWireEvaluator(this).updatePowerStrength(level, pos, state, orientation, updateShape); | ||
@@ -318,7 +372,7 @@ public class RedStoneWireBlock extends Block { | ||
@@ -318,7 +369,7 @@ public class RedStoneWireBlock extends Block { | ||
@Override | ||
protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) { | ||
if (!oldState.is(state.getBlock()) && !level.isClientSide) { | ||
|
@@ -1051,7 +1045,7 @@ index 84e6c986917128d4488afa23d29c689cadb4f55d..f02232ce97779db0d12a5d5da1d76732 | |
|
||
for (Direction direction : Direction.Plane.VERTICAL) { | ||
level.updateNeighborsAt(pos.relative(direction), this); | ||
@@ -337,7 +391,7 @@ public class RedStoneWireBlock extends Block { | ||
@@ -337,7 +388,7 @@ public class RedStoneWireBlock extends Block { | ||
level.updateNeighborsAt(pos.relative(direction), this); | ||
} | ||
|
||
|
@@ -1060,7 +1054,7 @@ index 84e6c986917128d4488afa23d29c689cadb4f55d..f02232ce97779db0d12a5d5da1d76732 | |
this.updateNeighborsOfNeighboringWires(level, pos); | ||
} | ||
} | ||
@@ -363,7 +417,7 @@ public class RedStoneWireBlock extends Block { | ||
@@ -363,7 +414,7 @@ public class RedStoneWireBlock extends Block { | ||
if (!level.isClientSide) { | ||
if (neighborBlock != this || !useExperimentalEvaluator(level)) { | ||
if (state.canSurvive(level, pos)) { | ||
|
@@ -1070,10 +1064,10 @@ index 84e6c986917128d4488afa23d29c689cadb4f55d..f02232ce97779db0d12a5d5da1d76732 | |
dropResources(state, level, pos); | ||
level.removeBlock(pos, false); | ||
diff --git a/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java b/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java | ||
index 380fc51a252022195e178daccd8aa53dd1d71a2e..2d77780b6727f82ffc3cb216ca5f2d6483496cfd 100644 | ||
index d5e8e5fbcd6f3429ff081da6cd08acfc40091765..71ec6c89f1254ed625ddf7da96c32fcd2a0f6ea3 100644 | ||
--- a/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java | ||
+++ b/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java | ||
@@ -44,7 +44,7 @@ public class DefaultRedstoneWireEvaluator extends RedstoneWireEvaluator { | ||
@@ -41,7 +41,7 @@ public class DefaultRedstoneWireEvaluator extends RedstoneWireEvaluator { | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
paper-server/patches/sources/net/minecraft/world/level/block/AbstractSkullBlock.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- a/net/minecraft/world/level/block/AbstractSkullBlock.java | ||
+++ b/net/minecraft/world/level/block/AbstractSkullBlock.java | ||
@@ -75,6 +_,11 @@ | ||
if (!level.isClientSide) { | ||
boolean hasNeighborSignal = level.hasNeighborSignal(pos); | ||
if (hasNeighborSignal != state.getValue(POWERED)) { | ||
+ // Paper start - Call BlockRedstoneEvent | ||
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBinaryRedstoneChange(level, pos, hasNeighborSignal)) { | ||
+ return; | ||
+ } | ||
+ // Paper end - Call BlockRedstoneEvent | ||
level.setBlock(pos, state.setValue(POWERED, Boolean.valueOf(hasNeighborSignal)), 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
paper-server/patches/sources/net/minecraft/world/level/block/BellBlock.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.