aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/world/level/block/BasePressurePlateBlock.java.patch
blob: 771b25481b196594f404b2be236fed26f1ab2c57 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
--- a/net/minecraft/world/level/block/BasePressurePlateBlock.java
+++ b/net/minecraft/world/level/block/BasePressurePlateBlock.java
@@ -15,12 +15,13 @@
 import net.minecraft.world.level.LevelAccessor;
 import net.minecraft.world.level.LevelReader;
 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.properties.BlockSetType;
 import net.minecraft.world.level.gameevent.GameEvent;
 import net.minecraft.world.phys.AABB;
 import net.minecraft.world.phys.shapes.CollisionContext;
 import net.minecraft.world.phys.shapes.VoxelShape;
+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
 
 public abstract class BasePressurePlateBlock extends Block {
 
@@ -29,19 +30,17 @@
     protected static final AABB TOUCH_AABB = new AABB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.25D, 0.9375D);
     protected final BlockSetType type;
 
-    protected BasePressurePlateBlock(BlockBehaviour.Properties blockbehaviour_properties, BlockSetType blocksettype) {
-        super(blockbehaviour_properties.sound(blocksettype.soundType()));
-        this.type = blocksettype;
+    protected BasePressurePlateBlock(BlockBehaviour.Properties properties, BlockSetType type) {
+        super(properties.sound(type.soundType()));
+        this.type = type;
     }
 
     @Override
-    @Override
     protected abstract MapCodec<? extends BasePressurePlateBlock> codec();
 
     @Override
-    @Override
-    public VoxelShape getShape(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, CollisionContext collisioncontext) {
-        return this.getSignalForState(blockstate) > 0 ? BasePressurePlateBlock.PRESSED_AABB : BasePressurePlateBlock.AABB;
+    public VoxelShape getShape(IBlockData state, BlockGetter level, BlockPos pos, CollisionContext context) {
+        return this.getSignalForState(state) > 0 ? BasePressurePlateBlock.PRESSED_AABB : BasePressurePlateBlock.AABB;
     }
 
     protected int getPressedTime() {
@@ -49,120 +48,130 @@
     }
 
     @Override
-    @Override
-    public boolean isPossibleToRespawnInThis(BlockState blockstate) {
+    public boolean isPossibleToRespawnInThis(IBlockData state) {
         return true;
     }
 
     @Override
-    @Override
-    public BlockState updateShape(BlockState blockstate, Direction direction, BlockState blockstate1, LevelAccessor levelaccessor, BlockPos blockpos, BlockPos blockpos1) {
-        return direction == Direction.DOWN && !blockstate.canSurvive(levelaccessor, blockpos) ? Blocks.AIR.defaultBlockState() : super.updateShape(blockstate, direction, blockstate1, levelaccessor, blockpos, blockpos1);
+    public IBlockData updateShape(IBlockData state, Direction facing, IBlockData facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
+        return facing == Direction.DOWN && !state.canSurvive(level, currentPos) ? Blocks.AIR.defaultBlockState() : super.updateShape(state, facing, facingState, level, currentPos, facingPos);
     }
 
     @Override
-    @Override
-    public boolean canSurvive(BlockState blockstate, LevelReader levelreader, BlockPos blockpos) {
-        BlockPos blockpos1 = blockpos.below();
+    public boolean canSurvive(IBlockData state, LevelReader level, BlockPos pos) {
+        BlockPos blockposition1 = pos.below();
 
-        return canSupportRigidBlock(levelreader, blockpos1) || canSupportCenter(levelreader, blockpos1, Direction.UP);
+        return canSupportRigidBlock(level, blockposition1) || canSupportCenter(level, blockposition1, Direction.UP);
     }
 
     @Override
-    @Override
-    public void tick(BlockState blockstate, ServerLevel serverlevel, BlockPos blockpos, RandomSource randomsource) {
-        int i = this.getSignalForState(blockstate);
+    public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) {
+        int i = this.getSignalForState(state);
 
         if (i > 0) {
-            this.checkPressed((Entity) null, serverlevel, blockpos, blockstate, i);
+            this.checkPressed((Entity) null, level, pos, state, i);
         }
 
     }
 
     @Override
-    @Override
-    public void entityInside(BlockState blockstate, Level level, BlockPos blockpos, Entity entity) {
+    public void entityInside(IBlockData state, Level level, BlockPos pos, Entity entity) {
         if (!level.isClientSide) {
-            int i = this.getSignalForState(blockstate);
+            int i = this.getSignalForState(state);
 
             if (i == 0) {
-                this.checkPressed(entity, level, blockpos, blockstate, i);
+                this.checkPressed(entity, level, pos, state, i);
             }
 
         }
     }
 
-    private void checkPressed(@Nullable Entity entity, Level level, BlockPos blockpos, BlockState blockstate, int i) {
-        int j = this.getSignalStrength(level, blockpos);
-        boolean flag = i > 0;
+    private void checkPressed(@Nullable Entity entity, Level level, BlockPos pos, IBlockData state, int currentSignal) {
+        int j = this.getSignalStrength(level, pos);
+        boolean flag = currentSignal > 0;
         boolean flag1 = j > 0;
 
-        if (i != j) {
-            BlockState blockstate1 = this.setSignalForState(blockstate, j);
+        // CraftBukkit start - Interact Pressure Plate
+        org.bukkit.World bworld = level.getWorld();
+        org.bukkit.plugin.PluginManager manager = level.getCraftServer().getPluginManager();
 
-            level.setBlock(blockpos, blockstate1, 2);
-            this.updateNeighbours(level, blockpos);
-            level.setBlocksDirty(blockpos, blockstate, blockstate1);
+        if (flag != flag1) {
+            BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), currentSignal, j);
+            manager.callEvent(eventRedstone);
+
+            flag1 = eventRedstone.getNewCurrent() > 0;
+            j = eventRedstone.getNewCurrent();
         }
+        // CraftBukkit end
 
+        if (currentSignal != j) {
+            IBlockData iblockdata1 = this.setSignalForState(state, j);
+
+            level.setBlock(pos, iblockdata1, 2);
+            this.updateNeighbours(level, pos);
+            level.setBlocksDirty(pos, state, iblockdata1);
+        }
+
         if (!flag1 && flag) {
-            level.playSound((Player) null, blockpos, this.type.pressurePlateClickOff(), SoundSource.BLOCKS);
-            level.gameEvent(entity, GameEvent.BLOCK_DEACTIVATE, blockpos);
+            level.playSound((Player) null, pos, this.type.pressurePlateClickOff(), SoundSource.BLOCKS);
+            level.gameEvent(entity, GameEvent.BLOCK_DEACTIVATE, pos);
         } else if (flag1 && !flag) {
-            level.playSound((Player) null, blockpos, this.type.pressurePlateClickOn(), SoundSource.BLOCKS);
-            level.gameEvent(entity, GameEvent.BLOCK_ACTIVATE, blockpos);
+            level.playSound((Player) null, pos, this.type.pressurePlateClickOn(), SoundSource.BLOCKS);
+            level.gameEvent(entity, GameEvent.BLOCK_ACTIVATE, pos);
         }
 
         if (flag1) {
-            level.scheduleTick(new BlockPos(blockpos), (Block) this, this.getPressedTime());
+            level.scheduleTick(new BlockPos(pos), (Block) this, this.getPressedTime());
         }
 
     }
 
     @Override
-    @Override
-    public void onRemove(BlockState blockstate, Level level, BlockPos blockpos, BlockState blockstate1, boolean flag) {
-        if (!flag && !blockstate.is(blockstate1.getBlock())) {
-            if (this.getSignalForState(blockstate) > 0) {
-                this.updateNeighbours(level, blockpos);
+    public void onRemove(IBlockData state, Level level, BlockPos pos, IBlockData newState, boolean isMoving) {
+        if (!isMoving && !state.is(newState.getBlock())) {
+            if (this.getSignalForState(state) > 0) {
+                this.updateNeighbours(level, pos);
             }
 
-            super.onRemove(blockstate, level, blockpos, blockstate1, flag);
+            super.onRemove(state, level, pos, newState, isMoving);
         }
     }
 
-    protected void updateNeighbours(Level level, BlockPos blockpos) {
-        level.updateNeighborsAt(blockpos, this);
-        level.updateNeighborsAt(blockpos.below(), this);
+    protected void updateNeighbours(Level level, BlockPos pos) {
+        level.updateNeighborsAt(pos, this);
+        level.updateNeighborsAt(pos.below(), this);
     }
 
     @Override
-    @Override
-    public int getSignal(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, Direction direction) {
-        return this.getSignalForState(blockstate);
+    public int getSignal(IBlockData blockState, BlockGetter blockAccess, BlockPos pos, Direction side) {
+        return this.getSignalForState(blockState);
     }
 
     @Override
-    @Override
-    public int getDirectSignal(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, Direction direction) {
-        return direction == Direction.UP ? this.getSignalForState(blockstate) : 0;
+    public int getDirectSignal(IBlockData blockState, BlockGetter blockAccess, BlockPos pos, Direction side) {
+        return side == Direction.UP ? this.getSignalForState(blockState) : 0;
     }
 
     @Override
-    @Override
-    public boolean isSignalSource(BlockState blockstate) {
+    public boolean isSignalSource(IBlockData state) {
         return true;
     }
 
-    protected static int getEntityCount(Level level, AABB aabb, Class<? extends Entity> oclass) {
-        return level.getEntitiesOfClass(oclass, aabb, EntitySelector.NO_SPECTATORS.and((entity) -> {
+    protected static int getEntityCount(Level level, AABB box, Class<? extends Entity> entityClass) {
+        // CraftBukkit start
+        return getEntities(level, box, entityClass).size();
+    }
+
+    protected static <T extends Entity> java.util.List<T> getEntities(Level world, AABB axisalignedbb, Class<T> oclass) {
+        // CraftBukkit end
+        return world.getEntitiesOfClass(oclass, axisalignedbb, EntitySelector.NO_SPECTATORS.and((entity) -> {
             return !entity.isIgnoringBlockTriggers();
-        })).size();
+        })); // CraftBukkit
     }
 
     protected abstract int getSignalStrength(Level level, BlockPos pos);
 
-    protected abstract int getSignalForState(BlockState state);
+    protected abstract int getSignalForState(IBlockData state);
 
-    protected abstract BlockState setSignalForState(BlockState state, int signal);
+    protected abstract IBlockData setSignalForState(IBlockData state, int signal);
 }