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

48 lines
2.3 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/level/block/BlockPressurePlateWeighted.java
+++ b/net/minecraft/world/level/block/BlockPressurePlateWeighted.java
2023-03-15 03:30:00 +11:00
@@ -11,6 +11,11 @@
import net.minecraft.world.level.block.state.properties.BlockSetType;
2021-03-16 09:00:00 +11:00
import net.minecraft.world.level.block.state.properties.BlockStateInteger;
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 BlockPressurePlateWeighted extends BlockPressurePlateAbstract {
2021-06-11 15:00:00 +10:00
public static final BlockStateInteger POWER = BlockProperties.POWER;
2023-03-15 03:30:00 +11:00
@@ -24,7 +29,31 @@
2019-04-23 12:00:00 +10:00
@Override
2021-11-22 09:00:00 +11:00
protected int getSignalStrength(World world, BlockPosition blockposition) {
- int i = Math.min(world.getEntitiesOfClass(Entity.class, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition)).size(), this.maxWeight);
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ // int i = Math.min(world.getEntitiesOfClass(Entity.class, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition)).size(), this.maxWeight);
+ int i = 0;
2021-11-22 09:00:00 +11:00
+ java.util.Iterator iterator = world.getEntitiesOfClass(Entity.class, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition)).iterator();
+
+ while (iterator.hasNext()) {
+ Entity entity = (Entity) iterator.next();
+
+ org.bukkit.event.Cancellable cancellable;
+
+ 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(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+ }
+
+ // We only want to block turning the plate on if all events are cancelled
+ if (!cancellable.isCancelled()) {
+ i++;
+ }
+ }
+
2021-06-11 15:00:00 +10:00
+ i = Math.min(i, this.maxWeight);
+ // CraftBukkit end
if (i > 0) {
2021-06-11 15:00:00 +10:00
float f = (float) Math.min(this.maxWeight, i) / (float) this.maxWeight;