2025-03-26 03:05:00 +11:00

78 lines
3.4 KiB
Diff

--- a/net/minecraft/world/level/block/BlockTripwire.java
+++ b/net/minecraft/world/level/block/BlockTripwire.java
@@ -29,6 +29,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.event.entity.EntityInteractEvent; // CraftBukkit
+
public class BlockTripwire extends Block {
public static final MapCodec<BlockTripwire> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -107,7 +109,7 @@
for (EnumDirection enumdirection : new EnumDirection[]{EnumDirection.SOUTH, EnumDirection.WEST}) {
int i = 1;
- while (true) {
+ for (; i < 42; i++) { // CraftBukkit - decompile error
if (i < 42) {
BlockPosition blockposition1 = blockposition.relative(enumdirection, i);
IBlockData iblockdata1 = world.getBlockState(blockposition1);
@@ -116,9 +118,12 @@
if (iblockdata1.getValue(BlockTripwireHook.FACING) == enumdirection.getOpposite()) {
BlockTripwireHook.calculateState(world, blockposition1, iblockdata1, false, true, i, iblockdata);
}
- } else if (iblockdata1.is(this)) {
- ++i;
- continue;
+ // CraftBukkit start - decompile error
+ break;
+ }
+ if (!iblockdata1.is(this)) {
+ break;
+ // CraftBukkit end
}
}
}
@@ -168,6 +173,40 @@
}
}
+ // CraftBukkit start - Call interact even when triggering connected tripwire
+ if (flag != flag1 && flag1 && (Boolean)iblockdata.getValue(ATTACHED)) {
+ org.bukkit.World bworld = world.getWorld();
+ org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager();
+ org.bukkit.block.Block block = bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ boolean allowed = false;
+
+ // If all of the events are cancelled block the tripwire trigger, else allow
+ for (Object object : list) {
+ if (object != null) {
+ org.bukkit.event.Cancellable cancellable;
+
+ if (object instanceof EntityHuman) {
+ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) object, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else if (object instanceof Entity) {
+ cancellable = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block);
+ manager.callEvent((EntityInteractEvent) cancellable);
+ } else {
+ continue;
+ }
+
+ if (!cancellable.isCancelled()) {
+ allowed = true;
+ break;
+ }
+ }
+ }
+
+ if (!allowed) {
+ return;
+ }
+ }
+ // CraftBukkit end
+
if (flag1 != flag) {
iblockdata = (IBlockData) iblockdata.setValue(BlockTripwire.POWERED, flag1);
world.setBlock(blockposition, iblockdata, 3);