0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-25 17:26:14 +00:00
craftbukkit/nms-patches/net/minecraft/world/level/block/piston/BlockPiston.patch
2024-10-23 02:15:00 +11:00

86 lines
3.9 KiB
Diff

--- a/net/minecraft/world/level/block/piston/BlockPiston.java
+++ b/net/minecraft/world/level/block/piston/BlockPiston.java
@@ -45,6 +45,14 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import com.google.common.collect.ImmutableList;
+import java.util.AbstractList;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.block.BlockPistonRetractEvent;
+import org.bukkit.event.block.BlockPistonExtendEvent;
+// CraftBukkit end
+
public class BlockPiston extends BlockDirectional {
public static final MapCodec<BlockPiston> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -155,6 +163,18 @@
}
}
+ // CraftBukkit start
+ if (!this.isSticky) {
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ BlockPistonRetractEvent event = new BlockPistonRetractEvent(block, ImmutableList.<org.bukkit.block.Block>of(), CraftBlock.notchToBlockFace(enumdirection));
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // PAIL: checkME - what happened to setTypeAndData?
+ // CraftBukkit end
world.blockEvent(blockposition, this, b0, enumdirection.get3DDataValue());
}
@@ -335,6 +355,48 @@
IBlockData[] aiblockdata = new IBlockData[list.size() + list2.size()];
EnumDirection enumdirection1 = flag ? enumdirection : enumdirection.getOpposite();
int i = 0;
+ // CraftBukkit start
+ final org.bukkit.block.Block bblock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+
+ final List<BlockPosition> moved = pistonextendschecker.getToPush();
+ final List<BlockPosition> broken = pistonextendschecker.getToDestroy();
+
+ List<org.bukkit.block.Block> blocks = new AbstractList<org.bukkit.block.Block>() {
+
+ @Override
+ public int size() {
+ return moved.size() + broken.size();
+ }
+
+ @Override
+ public org.bukkit.block.Block get(int index) {
+ if (index >= size() || index < 0) {
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
+ BlockPosition pos = (BlockPosition) (index < moved.size() ? moved.get(index) : broken.get(index - moved.size()));
+ return bblock.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+ }
+ };
+ org.bukkit.event.block.BlockPistonEvent event;
+ if (flag) {
+ event = new BlockPistonExtendEvent(bblock, blocks, CraftBlock.notchToBlockFace(enumdirection1));
+ } else {
+ event = new BlockPistonRetractEvent(bblock, blocks, CraftBlock.notchToBlockFace(enumdirection1));
+ }
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ for (BlockPosition b : broken) {
+ world.sendBlockUpdated(b, Blocks.AIR.defaultBlockState(), world.getBlockState(b), 3);
+ }
+ for (BlockPosition b : moved) {
+ world.sendBlockUpdated(b, Blocks.AIR.defaultBlockState(), world.getBlockState(b), 3);
+ b = b.relative(enumdirection1);
+ world.sendBlockUpdated(b, Blocks.AIR.defaultBlockState(), world.getBlockState(b), 3);
+ }
+ return false;
+ }
+ // CraftBukkit end
BlockPosition blockposition3;
int j;