@@ -49,7 +49,6 @@ import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
4949import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action
5050import net.minecraft.screen.slot.SlotActionType
5151import net.minecraft.sound.SoundCategory
52- import net.minecraft.text.Text
5352import net.minecraft.util.math.BlockPos
5453import net.minecraft.util.math.Direction
5554
@@ -89,6 +88,7 @@ class PacketBreakBlock @Ta5kBuilder constructor(
8988 private var toolStack: ItemStack ? = null
9089 private var toolSlot: Int = - 1
9190
91+ private var startedBreaking = false
9292 private var progress = 0.0f
9393 private var soundCooldown = 0.0f
9494
@@ -134,6 +134,7 @@ class PacketBreakBlock @Ta5kBuilder constructor(
134134 if (! collectDrop) {
135135 breakBlock()
136136 success(itemDrop)
137+ return @listen
137138 }
138139
139140 if (! world.entities.contains(itemDrop)) {
@@ -223,7 +224,7 @@ class PacketBreakBlock @Ta5kBuilder constructor(
223224 return true
224225 }
225226
226- if (progress == 0.0f ) return attackBlock()
227+ if (! startedBreaking ) return attackBlock()
227228
228229 val blockState: BlockState = world.getBlockState(blockPos)
229230 if (blockState.isAir) {
@@ -271,19 +272,15 @@ class PacketBreakBlock @Ta5kBuilder constructor(
271272 }
272273
273274 if (breakingTexture) {
274- world.setBlockBreakingInfo(
275- player.id,
276- blockPos,
277- getBlockBreakingProgress()
278- )
275+ setBreakingTextureStage()
279276 }
280277
281278 return true
282279 }
283280
284281 private fun SafeContext.getBlockBreakingProgress (): Int =
285- if (progress > 0.0F )
286- ((progress / breakThreshold) * 10.0F ).toInt()
282+ if (progress > 0.0f )
283+ ((progress / breakThreshold) * 10.0f ).toInt()
287284 else
288285 - 1
289286
@@ -302,7 +299,7 @@ class PacketBreakBlock @Ta5kBuilder constructor(
302299
303300 return true
304301 }
305- if (progress != 0.0f ) return false
302+ if (startedBreaking ) return false
306303
307304 val blockState: BlockState = world.getBlockState(blockPos)
308305 var pendingUpdateManager = world.pendingUpdateManager.incrementSequence()
@@ -316,17 +313,15 @@ class PacketBreakBlock @Ta5kBuilder constructor(
316313 onBlockBreak()
317314 startBreakPacket(blockPos, side, sequence)
318315 return true
316+ } else {
317+ startedBreaking = true
319318 }
320319
321320 if (sounds)
322321 soundCooldown = 0.0f
323322
324323 if (breakingTexture) {
325- world.setBlockBreakingInfo(
326- player.id,
327- blockPos,
328- this @attackBlock.getBlockBreakingProgress()
329- )
324+ setBreakingTextureStage()
330325 }
331326 abortBreakPacket(blockPos, side, sequence)
332327 stopBreakPacket(blockPos, side, sequence + 1 )
@@ -350,6 +345,9 @@ class PacketBreakBlock @Ta5kBuilder constructor(
350345
351346 private fun SafeContext.breakBlock () {
352347 interaction.breakBlock(blockPos)
348+ if (breakingTexture) {
349+ setBreakingTextureStage(- 1 )
350+ }
353351 }
354352
355353 private fun SafeContext.updateToolInformation () {
@@ -361,6 +359,14 @@ class PacketBreakBlock @Ta5kBuilder constructor(
361359 toolSlot = player.inventory.getSlotWithStack(toolStack)
362360 }
363361
362+ private fun SafeContext.setBreakingTextureStage (stage : Int = getBlockBreakingProgress()) {
363+ world.setBlockBreakingInfo(
364+ player.id,
365+ blockPos,
366+ stage
367+ )
368+ }
369+
364370 private fun SafeContext.swing () =
365371 player.swingHand(player.activeHand)
366372
0 commit comments