@@ -4,7 +4,6 @@ import baritone.api.pathing.goals.Goal
44import baritone.api.pathing.goals.GoalNear
55import com.lambda.client.event.SafeClientEvent
66import com.lambda.client.event.events.BlockBreakEvent
7- import com.lambda.client.event.events.PacketEvent
87import com.lambda.client.event.events.RenderWorldEvent
98import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket
109import com.lambda.client.module.Category
@@ -23,10 +22,12 @@ import com.lambda.client.util.math.RotationUtils.getRotationTo
2322import com.lambda.client.util.math.VectorUtils
2423import com.lambda.client.util.math.VectorUtils.toVec3dCenter
2524import com.lambda.client.util.text.MessageSendHelper
26- import com.lambda.client.util.threads.*
25+ import com.lambda.client.util.threads.defaultScope
26+ import com.lambda.client.util.threads.onMainThread
27+ import com.lambda.client.util.threads.onMainThreadSafe
28+ import com.lambda.client.util.threads.safeListener
2729import com.lambda.client.util.world.*
2830import com.lambda.commons.interfaces.DisplayEnum
29- import com.lambda.event.listener.asyncListener
3031import com.lambda.event.listener.listener
3132import kotlinx.coroutines.delay
3233import kotlinx.coroutines.launch
@@ -43,10 +44,10 @@ import net.minecraft.init.Items
4344import net.minecraft.init.SoundEvents
4445import net.minecraft.inventory.ClickType
4546import net.minecraft.item.ItemShulkerBox
47+ import net.minecraft.network.play.client.CPacketAnimation
4648import net.minecraft.network.play.client.CPacketEntityAction
4749import net.minecraft.network.play.client.CPacketPlayerDigging
4850import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock
49- import net.minecraft.network.play.server.SPacketBlockChange
5051import net.minecraft.util.EnumFacing
5152import net.minecraft.util.EnumHand
5253import net.minecraft.util.math.BlockPos
@@ -56,6 +57,7 @@ import net.minecraft.world.EnumDifficulty
5657import net.minecraftforge.fml.common.gameevent.TickEvent
5758import kotlin.math.ceil
5859
60+
5961object AutoObsidian : Module(
6062 name = " AutoObsidian" ,
6163 category = Category .MISC ,
@@ -66,8 +68,6 @@ object AutoObsidian : Module(
6668 private val searchShulker by setting(" Search Shulker" , false )
6769 private val leaveEmptyShulkers by setting(" Leave Empty Shulkers" , true , { searchShulker })
6870 private val autoRefill by setting(" Auto Refill" , false , { fillMode != FillMode .INFINITE })
69- private val instantMining by setting(" Instant Mining" , true )
70- private val instantMiningDelay by setting(" Instant Mining Delay" , 10 , 1 .. 20 , 1 , { instantMining })
7171 private val threshold by setting(" Refill Threshold" , 32 , 1 .. 64 , 1 , { autoRefill && fillMode != FillMode .INFINITE })
7272 private val targetStacks by setting(" Target Stacks" , 1 , 1 .. 20 , 1 , { fillMode == FillMode .TARGET_STACKS })
7373 private val delayTicks by setting(" Delay Ticks" , 4 , 1 .. 10 , 1 )
@@ -120,7 +120,6 @@ object AutoObsidian : Module(
120120 private val rotateTimer = TickTimer (TimeUnit .TICKS )
121121 private val shulkerOpenTimer = TickTimer (TimeUnit .TICKS )
122122 private val miningTimer = TickTimer (TimeUnit .TICKS )
123- private val miningTimeoutTimer = TickTimer (TimeUnit .SECONDS )
124123
125124 private val miningMap = HashMap <BlockPos , Pair <Int , Long >>() // <BlockPos, <Breaker ID, Last Update Time>>
126125
@@ -145,30 +144,6 @@ object AutoObsidian : Module(
145144 }
146145 }
147146
148- asyncListener<PacketEvent .PostSend > {
149- if (! instantMining || it.packet !is CPacketPlayerDigging ) return @asyncListener
150-
151- if (it.packet.position != placingPos || it.packet.facing != lastMiningSide) {
152- canInstantMine = false
153- }
154- }
155-
156- safeAsyncListener<PacketEvent .Receive > {
157- if (! instantMining || it.packet !is SPacketBlockChange ) return @safeAsyncListener
158- if (it.packet.blockPosition != placingPos) return @safeAsyncListener
159-
160- val prevBlock = world.getBlockState(it.packet.blockPosition).block
161- val newBlock = it.packet.blockState.block
162-
163- if (prevBlock != newBlock) {
164- if (prevBlock != Blocks .AIR && newBlock == Blocks .AIR ) {
165- canInstantMine = true
166- }
167- miningTimer.reset()
168- miningTimeoutTimer.reset()
169- }
170- }
171-
172147 listener<RenderWorldEvent > {
173148 if (state != State .DONE ) renderer.render(clear = false , cull = true )
174149 }
@@ -585,34 +560,26 @@ object AutoObsidian : Module(
585560 val center = pos.toVec3dCenter()
586561 val diff = player.getPositionEyes(1.0f ).subtract(center)
587562 val normalizedVec = diff.normalize()
588- var side = EnumFacing .getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat())
563+ val blockState = world.getBlockState(pos)
564+
565+ val ticksNeeded = ceil((1 / (blockState.getPlayerRelativeBlockHardness(player, world, pos)))).toInt()
566+ val side = EnumFacing .getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat())
589567
590568 lastHitVec = center
591569 rotateTimer.reset()
592570
593- if (instantMining && canInstantMine) {
594- if (! miningTimer.tick(instantMiningDelay.toLong(), false )) return
595-
596- if (! miningTimeoutTimer.tick(2L , false )) {
597- side = side.opposite
598- } else {
599- canInstantMine = false
600- }
571+ if (pre) {
572+ connection.sendPacket(CPacketPlayerDigging (CPacketPlayerDigging .Action .START_DESTROY_BLOCK , pos, side))
573+ if (state != State .SEARCHING ) state = State .MINING else searchingState = SearchingState .MINING
601574 }
602575
603- defaultScope.launch {
604- delay(20L )
605- onMainThreadSafe {
606- if (pre || miningTimeoutTimer.tick(8L )) {
607- connection.sendPacket(CPacketPlayerDigging (CPacketPlayerDigging .Action .START_DESTROY_BLOCK , pos, side))
608- if (state != State .SEARCHING ) state = State .MINING else searchingState = SearchingState .MINING
609- } else {
610- connection.sendPacket(CPacketPlayerDigging (CPacketPlayerDigging .Action .STOP_DESTROY_BLOCK , pos, side))
611- }
612- player.swingArm(EnumHand .MAIN_HAND )
613- lastMiningSide = side
614- }
576+ if (miningTimer.tick(ticksNeeded, true )) {
577+ connection.sendPacket(CPacketPlayerDigging (CPacketPlayerDigging .Action .STOP_DESTROY_BLOCK , pos, side))
615578 }
579+
580+ connection.sendPacket(CPacketAnimation (EnumHand .MAIN_HAND ))
581+ player.swingArm(EnumHand .MAIN_HAND )
582+ lastMiningSide = side
616583 }
617584
618585 /* *
0 commit comments