aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/world/level/block/WeightedPressurePlateBlock.java.patch
blob: 735972bb4769a1b468c8aa3cea6df94e2225aa1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
--- a/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
+++ b/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
@@ -6,43 +6,64 @@
 import net.minecraft.core.BlockPos;
 import net.minecraft.util.Mth;
 import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.player.Player;
 import net.minecraft.world.level.Level;
 import net.minecraft.world.level.block.state.BlockBehaviour;
-import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.IBlockData;
 import net.minecraft.world.level.block.state.StateDefinition;
 import net.minecraft.world.level.block.state.properties.BlockSetType;
 import net.minecraft.world.level.block.state.properties.BlockStateProperties;
 import net.minecraft.world.level.block.state.properties.IntegerProperty;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
 
 public class WeightedPressurePlateBlock extends BasePressurePlateBlock {
 
     public static final MapCodec<WeightedPressurePlateBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
-        return instance.group(Codec.intRange(1, 1024).fieldOf("max_weight").forGetter((weightedpressureplateblock) -> {
-            return weightedpressureplateblock.maxWeight;
-        }), BlockSetType.CODEC.fieldOf("block_set_type").forGetter((weightedpressureplateblock) -> {
-            return weightedpressureplateblock.type;
+        return instance.group(Codec.intRange(1, 1024).fieldOf("max_weight").forGetter((blockpressureplateweighted) -> {
+            return blockpressureplateweighted.maxWeight;
+        }), BlockSetType.CODEC.fieldOf("block_set_type").forGetter((blockpressureplateweighted) -> {
+            return blockpressureplateweighted.type;
         }), propertiesCodec()).apply(instance, WeightedPressurePlateBlock::new);
     });
     public static final IntegerProperty POWER = BlockStateProperties.POWER;
     private final int maxWeight;
 
     @Override
-    @Override
     public MapCodec<WeightedPressurePlateBlock> codec() {
         return WeightedPressurePlateBlock.CODEC;
     }
 
-    protected WeightedPressurePlateBlock(int i, BlockSetType blocksettype, BlockBehaviour.Properties blockbehaviour_properties) {
-        super(blockbehaviour_properties, blocksettype);
-        this.registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any()).setValue(WeightedPressurePlateBlock.POWER, 0));
+    protected WeightedPressurePlateBlock(int i, BlockSetType blocksettype, BlockBehaviour.Properties blockbase_info) {
+        super(blockbase_info, blocksettype);
+        this.registerDefaultState((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(WeightedPressurePlateBlock.POWER, 0));
         this.maxWeight = i;
     }
 
     @Override
-    @Override
-    protected int getSignalStrength(Level level, BlockPos blockpos) {
-        int i = Math.min(getEntityCount(level, WeightedPressurePlateBlock.TOUCH_AABB.move(blockpos), Entity.class), this.maxWeight);
+    protected int getSignalStrength(Level level, BlockPos pos) {
+        // CraftBukkit start
+        // int i = Math.min(getEntityCount(world, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition), Entity.class), this.maxWeight);
+        int i = 0;
+        for (Entity entity : getEntities(level, WeightedPressurePlateBlock.TOUCH_AABB.move(pos), Entity.class)) {
+            org.bukkit.event.Cancellable cancellable;
 
+            if (entity instanceof Player) {
+                cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((Player) entity, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null);
+            } else {
+                cancellable = new EntityInteractEvent(entity.getBukkitEntity(), level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+                level.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;
 
@@ -53,26 +74,22 @@
     }
 
     @Override
-    @Override
-    protected int getSignalForState(BlockState blockstate) {
-        return (Integer) blockstate.getValue(WeightedPressurePlateBlock.POWER);
+    protected int getSignalForState(IBlockData state) {
+        return (Integer) state.getValue(WeightedPressurePlateBlock.POWER);
     }
 
     @Override
-    @Override
-    protected BlockState setSignalForState(BlockState blockstate, int i) {
-        return (BlockState) blockstate.setValue(WeightedPressurePlateBlock.POWER, i);
+    protected IBlockData setSignalForState(IBlockData state, int strength) {
+        return (IBlockData) state.setValue(WeightedPressurePlateBlock.POWER, strength);
     }
 
     @Override
-    @Override
     protected int getPressedTime() {
         return 10;
     }
 
     @Override
-    @Override
-    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> statedefinition_builder) {
-        statedefinition_builder.add(WeightedPressurePlateBlock.POWER);
+    protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
+        builder.add(WeightedPressurePlateBlock.POWER);
     }
 }