net.minecraft.world.level.redstone

This commit is contained in:
Jake Potrebic 2024-12-13 19:42:44 -08:00
parent c62af3a5b7
commit 9793846a7e
No known key found for this signature in database
GPG key ID: ECE0B3C133C016C5
7 changed files with 75 additions and 115 deletions

View file

@ -1,11 +1,11 @@
--- a/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
+++ b/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
@@ -135,7 +135,7 @@
@@ -133,7 +_,7 @@
orientation = this.orientation.withFront(direction);
}
- NeighborUpdater.executeUpdate(world, blockState, blockPos, this.sourceBlock, orientation, false);
+ NeighborUpdater.executeUpdate(world, blockState, blockPos, this.sourceBlock, orientation, false, this.sourcePos); // Paper - Add source block to BlockPhysicsEvent
- NeighborUpdater.executeUpdate(level, blockState, blockPos, this.sourceBlock, orientation, false);
+ NeighborUpdater.executeUpdate(level, blockState, blockPos, this.sourceBlock, orientation, false, this.sourcePos); // Paper - Add source block to BlockPhysicsEvent
if (this.idx < NeighborUpdater.UPDATE_ORDER.length && NeighborUpdater.UPDATE_ORDER[this.idx] == this.skipDirection) {
this.idx++;
}

View file

@ -0,0 +1,20 @@
--- a/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java
+++ b/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java
@@ -17,7 +_,16 @@
@Override
public void updatePowerStrength(Level level, BlockPos pos, BlockState state, @Nullable Orientation orientation, boolean updateShape) {
int i = this.calculateTargetStrength(level, pos);
- if (state.getValue(RedStoneWireBlock.POWER) != i) {
+ // CraftBukkit start
+ int oldPower = state.getValue(RedStoneWireBlock.POWER);
+ if (oldPower != i) {
+ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), oldPower, i);
+ level.getCraftServer().getPluginManager().callEvent(event);
+
+ i = event.getNewCurrent();
+ }
+ if (oldPower != i) {
+ // CraftBukkit end
if (level.getBlockState(pos) == state) {
level.setBlock(pos, state.setValue(RedStoneWireBlock.POWER, Integer.valueOf(i)), 2);
}

View file

@ -0,0 +1,20 @@
--- a/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java
+++ b/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java
@@ -36,7 +_,16 @@
int intValue = entry.getIntValue();
int i = unpackPower(intValue);
BlockState blockState = level.getBlockState(blockPos);
- if (blockState.is(this.wireBlock) && !blockState.getValue(RedStoneWireBlock.POWER).equals(i)) {
+ // CraftBukkit start
+ int oldPower = blockState.getValue(RedStoneWireBlock.POWER); // Paper - Call BlockRedstoneEvent properly; get the previous power from the right state
+ if (oldPower != i) {
+ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, blockPos), oldPower, i);
+ level.getCraftServer().getPluginManager().callEvent(event);
+
+ i = event.getNewCurrent();
+ }
+ if (blockState.is((net.minecraft.world.level.block.Block) this.wireBlock) && oldPower != i) {
+ // CraftBukkit end
int i1 = 2;
if (!updateShape || !flag) {
i1 |= 128;

View file

@ -0,0 +1,32 @@
--- a/net/minecraft/world/level/redstone/NeighborUpdater.java
+++ b/net/minecraft/world/level/redstone/NeighborUpdater.java
@@ -42,8 +_,29 @@
}
static void executeUpdate(Level level, BlockState state, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston) {
+ // Paper start - Add source block to BlockPhysicsEvent
+ executeUpdate(level, state, pos, neighborBlock, orientation, movedByPiston, pos);
+ }
+
+ static void executeUpdate(Level level, BlockState state, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston, BlockPos sourcePos) {
+ // Paper end - Add source block to BlockPhysicsEvent
try {
+ // CraftBukkit start
+ org.bukkit.craftbukkit.CraftWorld cworld = level.getWorld();
+ if (cworld != null) {
+ org.bukkit.event.block.BlockPhysicsEvent event = new org.bukkit.event.block.BlockPhysicsEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), org.bukkit.craftbukkit.block.data.CraftBlockData.fromData(state), org.bukkit.craftbukkit.block.CraftBlock.at(level, sourcePos)); // Paper - Add source block to BlockPhysicsEvent
+ level.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
state.handleNeighborChanged(level, pos, neighborBlock, orientation, movedByPiston);
+ // Spigot Start
+ } catch (StackOverflowError ex) {
+ level.lastPhysicsProblem = new BlockPos(pos);
+ // Spigot End
} catch (Throwable var9) {
CrashReport crashReport = CrashReport.forThrowable(var9, "Exception while updating neighbours");
CrashReportCategory crashReportCategory = crashReport.addCategory("Block being updated");

View file

@ -1,31 +0,0 @@
--- a/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java
+++ b/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java
@@ -9,6 +9,10 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.RedStoneWireBlock;
import net.minecraft.world.level.block.state.BlockState;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.block.BlockRedstoneEvent;
+// CraftBukkit end
public class DefaultRedstoneWireEvaluator extends RedstoneWireEvaluator {
@@ -20,7 +24,16 @@
public void updatePowerStrength(Level world, BlockPos pos, BlockState state, @Nullable Orientation orientation, boolean blockAdded) {
int i = this.calculateTargetStrength(world, pos);
- if ((Integer) state.getValue(RedStoneWireBlock.POWER) != i) {
+ // CraftBukkit start
+ int oldPower = state.getValue(RedStoneWireBlock.POWER);
+ if (oldPower != i) {
+ BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, pos), oldPower, i);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ i = event.getNewCurrent();
+ }
+ if (oldPower != i) {
+ // CraftBukkit end
if (world.getBlockState(pos) == state) {
world.setBlock(pos, (BlockState) state.setValue(RedStoneWireBlock.POWER, i), 2);
}

View file

@ -1,31 +0,0 @@
--- a/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java
+++ b/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java
@@ -16,6 +16,10 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.RedstoneSide;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.block.BlockRedstoneEvent;
+// CraftBukkit end
public class ExperimentalRedstoneWireEvaluator extends RedstoneWireEvaluator {
@@ -41,7 +45,16 @@
int j = ExperimentalRedstoneWireEvaluator.unpackPower(i);
BlockState iblockdata1 = world.getBlockState(blockposition1);
- if (iblockdata1.is((Block) this.wireBlock) && !((Integer) iblockdata1.getValue(RedStoneWireBlock.POWER)).equals(j)) {
+ // CraftBukkit start
+ 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);
+
+ j = event.getNewCurrent();
+ }
+ if (iblockdata1.is((Block) this.wireBlock) && oldPower != j) {
+ // CraftBukkit end
int k = 2;
if (!blockAdded || !flag1) {

View file

@ -1,50 +0,0 @@
--- a/net/minecraft/world/level/redstone/NeighborUpdater.java
+++ b/net/minecraft/world/level/redstone/NeighborUpdater.java
@@ -8,11 +8,17 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.event.block.BlockPhysicsEvent;
+// CraftBukkit end
public interface NeighborUpdater {
@@ -49,8 +55,29 @@
}
static void executeUpdate(Level world, BlockState state, BlockPos pos, Block sourceBlock, @Nullable Orientation orientation, boolean notify) {
+ // Paper start - Add source block to BlockPhysicsEvent
+ executeUpdate(world, state, pos, sourceBlock, orientation, notify, pos);
+ }
+
+ static void executeUpdate(Level world, BlockState state, BlockPos pos, Block sourceBlock, @Nullable Orientation orientation, boolean notify, BlockPos sourcePos) {
+ // Paper end - Add source block to BlockPhysicsEvent
try {
+ // CraftBukkit start
+ CraftWorld cworld = ((ServerLevel) world).getWorld();
+ if (cworld != null) {
+ BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at(world, pos), CraftBlockData.fromData(state), CraftBlock.at(world, sourcePos)); // Paper - Add source block to BlockPhysicsEvent
+ ((ServerLevel) world).getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
state.handleNeighborChanged(world, pos, sourceBlock, orientation, notify);
+ // Spigot Start
+ } catch (StackOverflowError ex) {
+ world.lastPhysicsProblem = new BlockPos(pos);
+ // Spigot End
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception while updating neighbours");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Block being updated");