PaperMC/paper-server/nms-patches/net/minecraft/world/level/block/BlockPressurePlateWeighted.patch
CraftBukkit/Spigot 40076782ed Update to Minecraft 1.19.4
By: md_5 <git@md-5.net>
2023-03-15 03:30:00 +11:00

47 lines
2.3 KiB
Diff

--- a/net/minecraft/world/level/block/BlockPressurePlateWeighted.java
+++ b/net/minecraft/world/level/block/BlockPressurePlateWeighted.java
@@ -11,6 +11,11 @@
import net.minecraft.world.level.block.state.properties.BlockSetType;
import net.minecraft.world.level.block.state.properties.BlockStateInteger;
+// CraftBukkit start
+import net.minecraft.world.entity.player.EntityHuman;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
public class BlockPressurePlateWeighted extends BlockPressurePlateAbstract {
public static final BlockStateInteger POWER = BlockProperties.POWER;
@@ -24,7 +29,31 @@
@Override
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
+ // int i = Math.min(world.getEntitiesOfClass(Entity.class, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition)).size(), this.maxWeight);
+ int i = 0;
+ 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++;
+ }
+ }
+
+ i = Math.min(i, this.maxWeight);
+ // CraftBukkit end
if (i > 0) {
float f = (float) Math.min(this.maxWeight, i) / (float) this.maxWeight;