|
91 | 91 | final BlockPos pos, final ServerboundPlayerActionPacket.Action action, final Direction direction, final int maxY, final int sequence |
92 | 92 | ) { |
93 | 93 | if (!this.player.isWithinBlockInteractionRange(pos, 1.0)) { |
94 | | -+ if (true) return; // Paper - Don't allow digging into unloaded chunks; Don't notify if unreasonably far away |
95 | | - this.debugLogging(pos, false, sequence, "too far"); |
96 | | - } else if (pos.getY() > maxY) { |
97 | | - this.player.connection.send(new ClientboundBlockUpdatePacket(pos, this.level.getBlockState(pos))); |
98 | | -@@ -178,16 +_,35 @@ |
| 94 | ++ if (true) return; // Paper - Don't allow digging into unloaded chunks; Don't notify if unreasonably far away // TODO - snapshot - revisit now that there is logic involved here |
| 95 | + if (this.isDestroyingBlock && action == ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK) { |
| 96 | + this.abortDestroyBlock(pos, sequence); |
| 97 | + } |
| 98 | +@@ -182,16 +_,35 @@ |
99 | 99 | } |
100 | 100 |
|
101 | 101 | if (!this.level.mayInteract(this.player, pos)) { |
|
133 | 133 | if (this.player.blockActionRestricted(this.level, pos, this.gameModeForPlayer)) { |
134 | 134 | this.player.connection.send(new ClientboundBlockUpdatePacket(pos, this.level.getBlockState(pos))); |
135 | 135 | this.debugLogging(pos, false, sequence, "block action restricted"); |
136 | | -@@ -197,7 +_,7 @@ |
| 136 | +@@ -201,7 +_,7 @@ |
137 | 137 | this.destroyProgressStart = this.gameTicks; |
138 | 138 | float progress = 1.0F; |
139 | 139 | BlockState blockState = this.level.getBlockState(pos); |
|
142 | 142 | EnchantmentHelper.onHitBlock( |
143 | 143 | this.level, |
144 | 144 | this.player.getMainHandItem(), |
145 | | -@@ -212,6 +_,23 @@ |
| 145 | +@@ -216,6 +_,23 @@ |
146 | 146 | progress = blockState.getDestroyProgress(this.player, this.player.level(), pos); |
147 | 147 | } |
148 | 148 |
|
|
166 | 166 | if (!blockState.isAir() && progress >= 1.0F) { |
167 | 167 | this.destroyAndAck(pos, sequence, "insta mine"); |
168 | 168 | } else { |
169 | | -@@ -255,14 +_,22 @@ |
170 | | - this.debugLogging(pos, true, sequence, "stopped destroying"); |
171 | | - } else if (action == ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK) { |
172 | | - this.isDestroyingBlock = false; |
173 | | -- if (!Objects.equals(this.destroyPos, pos)) { |
174 | | -- LOGGER.warn("Mismatch in destroy block pos: {} {}", this.destroyPos, pos); |
175 | | -+ // Paper start - Don't allow digging into unloaded chunks |
176 | | -+ if (!Objects.equals(this.destroyPos, pos) && !BlockPos.ZERO.equals(this.destroyPos)) { // Paper |
177 | | -+ ServerPlayerGameMode.LOGGER.debug("Mismatch in destroy block pos: {} {}", this.destroyPos, pos); // CraftBukkit - SPIGOT-5457 sent by client when interact event cancelled |
178 | | -+ BlockState destroyState = this.level.getBlockStateIfLoaded(this.destroyPos); // Don't load unloaded chunks for stale records here |
179 | | -+ if (destroyState != null) { |
180 | | - this.level.destroyBlockProgress(this.player.getId(), this.destroyPos, -1); |
181 | | - this.debugLogging(pos, true, sequence, "aborted mismatched destroying"); |
182 | | -+ } |
183 | | -+ this.destroyPos = BlockPos.ZERO; |
184 | | -+ // Paper end - Don't allow digging into unloaded chunks |
185 | | - } |
| 169 | +@@ -265,14 +_,22 @@ |
186 | 170 |
|
187 | | - this.level.destroyBlockProgress(this.player.getId(), pos, -1); |
188 | | - this.debugLogging(pos, true, sequence, "aborted destroying"); |
189 | | -+ |
190 | | -+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDamageAbortEvent(this.player, pos, this.player.getInventory().getSelectedItem()); // CraftBukkit |
191 | | - } |
| 171 | + private void abortDestroyBlock(final BlockPos pos, final int sequence) { |
| 172 | + this.isDestroyingBlock = false; |
| 173 | +- if (!Objects.equals(this.destroyPos, pos)) { |
| 174 | +- LOGGER.warn("Mismatch in destroy block pos: {} {}", this.destroyPos, pos); |
| 175 | ++ // Paper start - Don't allow digging into unloaded chunks |
| 176 | ++ if (!Objects.equals(this.destroyPos, pos) && !BlockPos.ZERO.equals(this.destroyPos)) { // Paper |
| 177 | ++ ServerPlayerGameMode.LOGGER.debug("Mismatch in destroy block pos: {} {}", this.destroyPos, pos); // CraftBukkit - SPIGOT-5457 sent by client when interact event cancelled |
| 178 | ++ BlockState destroyState = this.level.getBlockStateIfLoaded(this.destroyPos); // Don't load unloaded chunks for stale records here |
| 179 | ++ if (destroyState != null) { |
| 180 | + this.level.destroyBlockProgress(this.player.getId(), this.destroyPos, -1); |
| 181 | + this.debugLogging(pos, true, sequence, "aborted mismatched destroying"); |
| 182 | ++ } |
| 183 | ++ this.destroyPos = BlockPos.ZERO; |
| 184 | ++ // Paper end - Don't allow digging into unloaded chunks |
192 | 185 | } |
| 186 | + |
| 187 | + this.level.destroyBlockProgress(this.player.getId(), pos, -1); |
| 188 | + this.debugLogging(pos, true, sequence, "aborted destroying"); |
| 189 | ++ |
| 190 | ++ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDamageAbortEvent(this.player, pos, this.player.getInventory().getSelectedItem()); // CraftBukkit |
193 | 191 | } |
194 | | -@@ -278,13 +_,53 @@ |
| 192 | + |
| 193 | + public void destroyAndAck(final BlockPos pos, final int sequence, final String exitId) { |
| 194 | +@@ -286,13 +_,53 @@ |
195 | 195 |
|
196 | 196 | public boolean destroyBlock(final BlockPos pos) { |
197 | 197 | BlockState state = this.level.getBlockState(pos); |
|
248 | 248 | this.level.sendBlockUpdated(pos, state, state, Block.UPDATE_ALL); |
249 | 249 | return false; |
250 | 250 | } |
251 | | -@@ -293,6 +_,10 @@ |
| 251 | +@@ -301,6 +_,10 @@ |
252 | 252 | return false; |
253 | 253 | } |
254 | 254 |
|
|
259 | 259 | BlockState adjustedState = block.playerWillDestroy(this.level, pos, state, this.player); |
260 | 260 | boolean changed = this.level.removeBlock(pos, false); |
261 | 261 | if (SharedConstants.DEBUG_BLOCK_BREAK) { |
262 | | -@@ -303,17 +_,38 @@ |
| 262 | +@@ -311,17 +_,38 @@ |
263 | 263 | block.destroy(this.level, pos, adjustedState); |
264 | 264 | } |
265 | 265 |
|
|
305 | 305 |
|
306 | 306 | return true; |
307 | 307 | } |
308 | | -@@ -329,6 +_,7 @@ |
| 308 | +@@ -337,6 +_,7 @@ |
309 | 309 |
|
310 | 310 | int oldCount = itemStack.getCount(); |
311 | 311 | int oldDamage = itemStack.getDamageValue(); |
312 | 312 | + final ItemStack stackBeforeUse = itemStack.copy(); // Paper - Store stack before use for interact prediction check |
313 | 313 | InteractionResult result = itemStack.use(level, player, hand); |
314 | 314 | ItemStack resultStack; |
315 | 315 | if (result instanceof InteractionResult.Success success) { |
316 | | -@@ -357,25 +_,70 @@ |
| 316 | +@@ -365,25 +_,70 @@ |
317 | 317 | } |
318 | 318 |
|
319 | 319 | if (!player.isUsingItem()) { |
|
387 | 387 | return InteractionResult.CONSUME; |
388 | 388 | } |
389 | 389 |
|
390 | | -@@ -416,7 +_,7 @@ |
| 390 | +@@ -424,7 +_,7 @@ |
391 | 391 | } |
392 | 392 | } |
393 | 393 |
|
|
396 | 396 | UseOnContext context = new UseOnContext(player, hand, hitResult); |
397 | 397 | InteractionResult result; |
398 | 398 | if (player.hasInfiniteMaterials()) { |
399 | | -@@ -439,6 +_,11 @@ |
| 399 | +@@ -447,6 +_,11 @@ |
400 | 400 |
|
401 | 401 | return result; |
402 | 402 | } else { |
|
0 commit comments