Skip to content

Commit 3a0f7d0

Browse files
committed
use index's instead of doubleBreakBlock booleans
1 parent 9eb8160 commit 3a0f7d0

File tree

1 file changed

+32
-40
lines changed
  • common/src/main/kotlin/com/lambda/module/modules/player

1 file changed

+32
-40
lines changed

common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ object PacketMine : Module(
278278
runBetweenHandlers(ProgressStage.EndPre, ProgressStage.EndPost, pos, { lastValidBestTool }) {
279279
packetStopBreak(pos)
280280

281-
onBlockBreak(doubleBreakBlock = false)
281+
onBlockBreak(index = 0)
282282
}
283283
return@forEach
284284
}
285285

286286
doubleBreakSwapTo(bestTool)
287-
onBlockBreak(doubleBreakBlock = true)
287+
onBlockBreak(index = 1)
288288
}
289289

290290
BreakState.ReBreaking -> {
@@ -294,7 +294,7 @@ object PacketMine : Module(
294294
}
295295

296296
if (isOutOfRange(pos.toCenterPos()) || !reBreak.isEnabled()) {
297-
nullifyCurrentBreakingBlock(false)
297+
nullifyCurrentBreakingBlock(0)
298298
return@forEach
299299
}
300300

@@ -324,22 +324,22 @@ object PacketMine : Module(
324324
if (breakType == BreakType.Primary) {
325325
runHandlers(ProgressStage.EndPost, pos, lastValidBestTool)
326326
}
327-
onBlockBreak(doubleBreakBlock = breakType == BreakType.Double)
327+
onBlockBreak(index = breakType.index)
328328
return@forEach
329329
}
330330

331331
if (System.currentTimeMillis() - timeCompleted < timeoutDelay * 1000) return@forEach
332332

333333
val primary = breakType == BreakType.Primary
334334

335-
if (!primary) nullifyCurrentBreakingBlock(true)
335+
if (!primary) nullifyCurrentBreakingBlock(1)
336336
if (breakNextQueueBlock()) return@forEach
337337

338338
if (primary) {
339339
runHandlers(ProgressStage.TimedOut, pos, lastValidBestTool)
340340
}
341341

342-
nullifyCurrentBreakingBlock(breakType == BreakType.Double)
342+
nullifyCurrentBreakingBlock(breakType.index)
343343
}
344344
}
345345
}
@@ -365,7 +365,7 @@ object PacketMine : Module(
365365
}
366366
}
367367

368-
onBlockBreak(packetReceiveBreak = true, doubleBreakBlock = breakType == BreakType.Double)
368+
onBlockBreak(packetReceiveBreak = true, index = breakType.index)
369369
}
370370
}
371371
}
@@ -861,12 +861,10 @@ object PacketMine : Module(
861861
private fun SafeContext.isOutOfRange(vec: Vec3d) =
862862
player.eyePos.distanceTo(vec) > range
863863

864-
private fun SafeContext.onBlockBreak(packetReceiveBreak: Boolean = false, doubleBreakBlock: Boolean = false) {
865-
val block = if (doubleBreakBlock) 1 else 0
866-
867-
currentMiningBlock[block]?.apply {
864+
private fun SafeContext.onBlockBreak(packetReceiveBreak: Boolean = false, index: Int = 0) {
865+
currentMiningBlock[index]?.apply {
868866
if (!isOutOfRange(pos.toCenterPos()) || packetReceiveBreak) {
869-
checkClientSideBreak(packetReceiveBreak, pos, doubleBreakBlock = doubleBreakBlock)
867+
checkClientSideBreak(packetReceiveBreak, pos, index = index)
870868
}
871869

872870
if (timeCompleted == -1L) {
@@ -879,13 +877,13 @@ object PacketMine : Module(
879877
}
880878

881879
if (breakType == BreakType.Double && (breakState == BreakState.AwaitingResponse || !validateBreak)) {
882-
nullifyCurrentBreakingBlock(true)
880+
nullifyCurrentBreakingBlock(1)
883881
}
884882

885883
breaksPerTickCounter++
886884

887885
queueBreakStartCounter = queueBreakDelay
888-
if (breakNextQueueBlock(doubleBreakBlock = doubleBreakBlock)) return
886+
if (breakNextQueueBlock(index = index)) return
889887

890888
if (reBreak.isEnabled() && !isOutOfRange(pos.toCenterPos()) && breakType == BreakType.Primary) {
891889
if (breakState != BreakState.ReBreaking) {
@@ -896,45 +894,39 @@ object PacketMine : Module(
896894
return
897895
}
898896

899-
nullifyCurrentBreakingBlock(doubleBreakBlock)
897+
nullifyCurrentBreakingBlock(index)
900898
}
901899
}
902900

903-
private fun SafeContext.nullifyCurrentBreakingBlock(doubleBreakBlock: Boolean) {
904-
val block = if (doubleBreakBlock) 1 else 0
905-
906-
if (!doubleBreakBlock) {
907-
currentMiningBlock[block]?.apply {
901+
private fun SafeContext.nullifyCurrentBreakingBlock(index: Int) {
902+
if (index == 0) {
903+
currentMiningBlock[index]?.apply {
908904
if (breakingAnimation) world.setBlockBreakingInfo(player.id, pos, -1)
909905
runHandlers(ProgressStage.TimedOut, pos, lastValidBestTool)
910906
}
911907
}
912908

913-
currentMiningBlock[block] = null
909+
currentMiningBlock[index] = null
914910
}
915911

916-
private fun isStateBroken(previousState: BlockState?, activeState: BlockState): Boolean {
917-
previousState?.let { previous ->
918-
if (isStateEmpty(previous)) return false
912+
private fun isStateBroken(previousState: BlockState, newState: BlockState): Boolean {
913+
if (isStateEmpty(previousState)) return false
919914

920-
return activeState.isAir || (
921-
activeState.fluidState.fluid is WaterFluid
922-
&& !activeState.properties.contains(Properties.WATERLOGGED)
923-
&& previous.properties.contains(Properties.WATERLOGGED)
924-
&& previous.get(Properties.WATERLOGGED)
925-
)
926-
} ?: return false
915+
return (newState.isAir && previousState.fluidState.isEmpty)
916+
|| (
917+
!newState.fluidState.isEmpty
918+
&& !previousState.fluidState.isEmpty
919+
)
927920
}
928921

929922
private fun isStateEmpty(state: BlockState) =
930923
state.isAir || (
931-
(!state.properties.contains(Properties.WATERLOGGED)
932-
|| !state.get(Properties.WATERLOGGED))
924+
!state.properties.contains(Properties.WATERLOGGED)
933925
&& !state.fluidState.isEmpty
934926
)
935927

936-
private fun SafeContext.checkClientSideBreak(packetReceiveBreak: Boolean, pos: BlockPos, doubleBreakBlock: Boolean = false) {
937-
if (packetReceiveBreak || (!validateBreak && !doubleBreakBlock)) {
928+
private fun SafeContext.checkClientSideBreak(packetReceiveBreak: Boolean, pos: BlockPos, index: Int = 0) {
929+
if (packetReceiveBreak || (!validateBreak && index == 0)) {
938930
interaction.breakBlock(pos)
939931
}
940932
}
@@ -963,18 +955,18 @@ object PacketMine : Module(
963955
&& currentMiningBlock[1]?.pos != pos
964956
&& !blockQueue.contains(pos)
965957

966-
private fun SafeContext.breakNextQueueBlock(doubleBreakBlock: Boolean = false): Boolean {
958+
private fun SafeContext.breakNextQueueBlock(index: Int = 0): Boolean {
967959
if (!queueBlocks || currentMiningBlock.any { it?.timeCompleted == -1L }) return false
968960

969961
var startedBreakingAtLeastOne = false
970962

971963
while (true) {
972964
filterBlockQueueUntilNextPossible()?.let { block ->
973-
currentMiningBlock[1]?.run {
965+
if (currentMiningBlock[1] != null) {
974966
return startedBreakingAtLeastOne
975967
}
976968

977-
val requiresAnotherTickDelay = doubleBreakBlock && !validateBreak && queueBreakDelay <= 0 && doubleBreak
969+
val requiresAnotherTickDelay = index == 1 && !validateBreak && queueBreakDelay <= 0 && doubleBreak
978970

979971
if (queueBreakStartCounter > 0 || breaksPerTickCounter >= 1 || requiresAnotherTickDelay) {
980972
if (requiresAnotherTickDelay) queueBreakStartCounter++
@@ -1369,7 +1361,7 @@ object PacketMine : Module(
13691361
Breaking, ReBreaking, AwaitingResponse
13701362
}
13711363

1372-
private enum class BreakType {
1373-
Primary, Double;
1364+
private enum class BreakType(val index: Int) {
1365+
Primary(0), Double(1);
13741366
}
13751367
}

0 commit comments

Comments
 (0)