craftbukkit/nms-patches/net/minecraft/world/level/block/BlockPressurePlateBinary.patch

57 lines
2.4 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/level/block/BlockPressurePlateBinary.java
+++ b/net/minecraft/world/level/block/BlockPressurePlateBinary.java
2023-12-06 03:40:00 +11:00
@@ -13,6 +13,11 @@
2023-06-08 01:30:00 +10:00
import net.minecraft.world.level.block.state.properties.BlockSetType;
2022-12-08 03:00:00 +11:00
import net.minecraft.world.level.block.state.properties.BlockStateBoolean;
2023-03-15 03:30:00 +11:00
+// CraftBukkit start
+import net.minecraft.world.entity.player.EntityHuman;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
public class BlockPressurePlateBinary extends BlockPressurePlateAbstract {
2023-12-06 03:40:00 +11:00
public static final MapCodec<BlockPressurePlateBinary> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -44,7 +49,7 @@
2015-02-26 22:41:06 +00:00
2023-06-08 01:30:00 +10:00
@Override
protected int getSignalStrength(World world, BlockPosition blockposition) {
- Class oclass;
+ Class<? extends Entity> oclass; // CraftBukkit
2023-12-06 03:40:00 +11:00
switch (this.type.pressurePlateSensitivity()) {
2023-06-08 01:30:00 +10:00
case EVERYTHING:
2023-12-06 03:40:00 +11:00
@@ -59,7 +64,31 @@
2023-06-08 01:30:00 +10:00
2023-12-06 03:40:00 +11:00
Class<? extends Entity> oclass1 = oclass;
2023-06-08 01:30:00 +10:00
- return getEntityCount(world, BlockPressurePlateBinary.TOUCH_AABB.move(blockposition), oclass1) > 0 ? 15 : 0;
+ // CraftBukkit start - Call interact event when turning on a pressure plate
+ for (Entity entity : getEntities(world, BlockPressurePlateBinary.TOUCH_AABB.move(blockposition), oclass)) {
+ if (this.getSignalForState(world.getBlockState(blockposition)) == 0) {
+ org.bukkit.World bworld = world.getWorld();
+ org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager();
+ org.bukkit.event.Cancellable cancellable;
+
2023-06-08 01:30:00 +10:00
+ if (entity instanceof EntityHuman) {
+ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else {
+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ manager.callEvent((EntityInteractEvent) cancellable);
+ }
+
2023-06-08 01:30:00 +10:00
+ // We only want to block turning the plate on if all events are cancelled
+ if (cancellable.isCancelled()) {
+ continue;
+ }
2023-06-08 01:30:00 +10:00
+ }
+
+ return 15;
+ }
2015-02-26 22:41:06 +00:00
+
2023-06-08 01:30:00 +10:00
+ return 0;
+ // CraftBukkit end
}
@Override