Skip to content

Commit e79b342

Browse files
committed
Liquid improve and instant mine is back
1 parent 9e490ad commit e79b342

2 files changed

Lines changed: 48 additions & 54 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Adding fully automated highway building as plugin to Lambda. The tool places bui
5656
1. Get the latest Lambda release here https://github.com/lambda-client/lambda/releases
5757
2. Open Lambda menu in main menu to open plugin settings
5858
3. Press `Open Plugin Folder`
59-
4. Move plugin `HighwayTools-v9.9.jar` into the folder `.minecraft/lambda/plugins`
59+
4. Move plugin `HighwayTools-v9.9.1.jar` into the folder `.minecraft/lambda/plugins`
6060

6161
### Known issues
6262
- [x] `AutoLog` is not compatible with `AutoReconnect` > Should

src/main/kotlin/HighwayTools.kt

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ internal object HighwayTools : PluginModule(
252252
private val doneTasks = LinkedHashMap<BlockPos, BlockTask>()
253253
private var sortedTasks: List<BlockTask> = emptyList()
254254
var lastTask: BlockTask? = null; private set
255+
private var prePrimedPos = BlockPos.NULL_VECTOR
256+
private var primedPos = BlockPos.NULL_VECTOR
255257

256258
private var containerTask = BlockTask(BlockPos.ORIGIN, TaskState.DONE, Blocks.AIR, Items.AIR)
257259
private val shulkerOpenTimer = TickTimer(TimeUnit.TICKS)
@@ -296,6 +298,8 @@ internal object HighwayTools : PluginModule(
296298
startingBlockPos = player.flooredPosition
297299
currentBlockPos = startingBlockPos
298300
startingDirection = Direction.fromEntity(player)
301+
primedPos = BlockPos.NULL_VECTOR
302+
prePrimedPos = BlockPos.NULL_VECTOR
299303

300304
baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true
301305
baritoneSettingAllowBreak = BaritoneUtils.settings?.allowBreak?.value ?: true
@@ -567,6 +571,8 @@ internal object HighwayTools : PluginModule(
567571
} else {
568572
debugInfos.add(Pair("Item", "${blockTask.item.registryName}"))
569573
}
574+
if (blockTask.isOpen) debugInfos.add(Pair("Open", ""))
575+
if (blockTask.isLoaded) debugInfos.add(Pair("Loaded", ""))
570576
if (blockTask.stuckTicks > 0) debugInfos.add(Pair("Stuck", "${blockTask.stuckTicks}"))
571577

572578
debugInfos.forEachIndexed { index, pair ->
@@ -969,24 +975,8 @@ internal object HighwayTools : PluginModule(
969975
private fun SafeClientEvent.runTasks() {
970976
if (player.inventory.isEmpty) return
971977
when {
972-
pendingTasks.isEmpty() -> {
973-
if (checkDoneTasks()) doneTasks.clear()
974-
refreshData()
975-
}
976978
containerTask.taskState != TaskState.DONE -> {
977-
if (containerTask.stuckTicks > containerTask.taskState.stuckTimeout) {
978-
when (containerTask.taskState) {
979-
TaskState.PICKUP -> {
980-
player.inventorySlots.firstEmpty()?.let {
981-
// if (tryRefreshSlots) updateSlot(it.slotNumber)
982-
}
983-
containerTask.updateState(TaskState.DONE)
984-
}
985-
else -> {
986-
// Nothing
987-
}
988-
}
989-
}
979+
checkStuckTimeout(containerTask)
990980
pendingTasks.values.toList().forEach {
991981
doTask(it, true)
992982
}
@@ -1107,18 +1097,17 @@ internal object HighwayTools : PluginModule(
11071097
when (blockTask.taskState) {
11081098
TaskState.PLACE -> {
11091099
if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1
1110-
1111-
// if (tryRefreshSlots) updateSlot()
1112-
}
1113-
TaskState.BREAK -> {
1114-
// if (tryRefreshSlots) updateSlot()
1100+
getNeighbourSequence(blockTask.blockPos, placementSearch, maxReach, !illegalPlacements).firstOrNull()?.let {
1101+
playerController.processRightClickBlock(player, world, it.pos, it.side, it.hitVec, EnumHand.MAIN_HAND)
1102+
}
1103+
blockTask.updateState(TaskState.PLACED)
11151104
}
11161105
TaskState.PICKUP -> {
11171106
sendChatMessage("$chatName Can't pickup ${containerTask.item.registryName}@(${containerTask.blockPos.asString()})")
1118-
containerTask.updateState(TaskState.DONE)
1107+
blockTask.updateState(TaskState.DONE)
11191108
}
11201109
else -> {
1121-
// Nothing
1110+
blockTask.updateState(TaskState.DONE)
11221111
}
11231112
}
11241113

@@ -1163,9 +1152,6 @@ internal object HighwayTools : PluginModule(
11631152
doPlace(blockTask, updateOnly)
11641153
}
11651154
TaskState.PENDING_BREAK, TaskState.PENDING_PLACE -> {
1166-
// if (!updateOnly && debugMessages == DebugMessages.ALL) {
1167-
// sendChatMessage("$chatName Currently waiting for blockState updates...")
1168-
// }
11691155
blockTask.onStuck()
11701156
}
11711157
}
@@ -1284,6 +1270,10 @@ internal object HighwayTools : PluginModule(
12841270
when (world.getBlockState(blockTask.blockPos).block) {
12851271
Blocks.AIR -> {
12861272
totalBlocksBroken++
1273+
if (blockTask.blockPos == prePrimedPos) {
1274+
primedPos = prePrimedPos
1275+
prePrimedPos = BlockPos.NULL_VECTOR
1276+
}
12871277
simpleMovingAverageBreaks.add(System.currentTimeMillis())
12881278

12891279
when {
@@ -1319,6 +1309,7 @@ internal object HighwayTools : PluginModule(
13191309
when {
13201310
blockTask.block == currentBlock && currentBlock != Blocks.AIR -> {
13211311
totalBlocksPlaced++
1312+
prePrimedPos = blockTask.blockPos
13221313
simpleMovingAveragePlaces.add(System.currentTimeMillis())
13231314

13241315
if (dynamicDelay && extraPlaceDelay > 0) extraPlaceDelay -= 1
@@ -1487,14 +1478,21 @@ internal object HighwayTools : PluginModule(
14871478
}
14881479

14891480
private fun SafeClientEvent.placeBlock(blockTask: BlockTask) {
1490-
val neighbours = if (illegalPlacements) {
1491-
getNeighbourSequence(blockTask.blockPos, placementSearch, maxReach)
1492-
} else {
1493-
getNeighbourSequence(blockTask.blockPos, placementSearch, maxReach, true)
1494-
}
1481+
val neighbours = getNeighbourSequence(blockTask.blockPos, placementSearch, maxReach, !illegalPlacements)
14951482

14961483
when (neighbours.size) {
14971484
0 -> {
1485+
if (blockTask.taskState == TaskState.LIQUID_FLOW || blockTask.taskState == TaskState.LIQUID_SOURCE ) {
1486+
if (debugMessages == DebugMessages.ALL) {
1487+
if (!anonymizeStats) {
1488+
sendChatMessage("$chatName Can't replace Liquid@(${blockTask.blockPos})")
1489+
} else {
1490+
sendChatMessage("$chatName Can't replace Liquid")
1491+
}
1492+
}
1493+
blockTask.updateState(TaskState.DONE)
1494+
return
1495+
}
14981496
if (debugMessages == DebugMessages.ALL) {
14991497
if (!anonymizeStats) {
15001498
sendChatMessage("$chatName No neighbours found for ${blockTask.blockPos}")
@@ -1581,10 +1579,8 @@ internal object HighwayTools : PluginModule(
15811579
return
15821580
}
15831581

1584-
if (containerTask.primed && containerTask.destroy && instantMine) {
1582+
if (blockTask.blockPos == primedPos && instantMine) {
15851583
side = side.opposite
1586-
} else {
1587-
containerTask.primed
15881584
}
15891585
lastHitVec = getHitVec(blockTask.blockPos, side)
15901586
rotateTimer.reset()
@@ -1695,10 +1691,12 @@ internal object HighwayTools : PluginModule(
16951691
}
16961692

16971693
private fun SafeClientEvent.shouldBridge(): Boolean {
1698-
return world.isAirBlock(currentBlockPos.add(startingDirection.directionVec).down()) &&
1694+
return world.getBlockState(currentBlockPos.add(startingDirection.directionVec).down()).isReplaceable &&
16991695
!sortedTasks.any {
1700-
it.taskState == TaskState.PLACE &&
1701-
getNeighbourSequence(it.blockPos, placementSearch, maxReach, true).isNotEmpty()
1696+
getNeighbourSequence(it.blockPos, placementSearch, maxReach, !illegalPlacements).isNotEmpty() &&
1697+
(it.taskState == TaskState.PLACE ||
1698+
it.taskState == TaskState.LIQUID_SOURCE ||
1699+
it.taskState == TaskState.LIQUID_FLOW)
17021700
}
17031701
}
17041702

@@ -1893,8 +1891,8 @@ internal object HighwayTools : PluginModule(
18931891
}
18941892

18951893
private fun SafeClientEvent.moveToInventory(slot: Slot) {
1896-
player.hotbarSlots.firstOrNull {
1897-
slot.stack.item == it.stack.item
1894+
player.inventorySlots.firstOrNull {
1895+
slot.stack.item == it.stack.item && it.stack.count < it.slotStackLimit - slot.stack.count
18981896
}?.let {
18991897
clickSlot(player.openContainer.windowId, slot, 0, ClickType.QUICK_MOVE)
19001898
} ?: run {
@@ -1969,24 +1967,24 @@ internal object HighwayTools : PluginModule(
19691967
}
19701968
}
19711969

1972-
// private fun SafeClientEvent.updateSlot(slot: Int = player.inventory.currentItem + 36) {
1973-
// clickSlot(0, slot, 0, ClickType.PICKUP)
1974-
// connection.sendPacket(CPacketCloseWindow(0))
1975-
// runBlocking {
1976-
// onMainThreadSafe { playerController.updateController() }
1977-
// }
1978-
// }
1979-
19801970
private fun SafeClientEvent.handleLiquid(blockTask: BlockTask): Boolean {
19811971
var foundLiquid = false
19821972

19831973
for (side in EnumFacing.values()) {
1974+
if (side == EnumFacing.DOWN) continue
19841975
val neighbourPos = blockTask.blockPos.offset(side)
19851976

19861977
if (world.getBlockState(neighbourPos).block !is BlockLiquid) continue
19871978

19881979
if (player.distanceTo(neighbourPos) > maxReach) {
19891980
blockTask.updateState(TaskState.DONE)
1981+
if (debugMessages == DebugMessages.ALL) {
1982+
if (!anonymizeStats) {
1983+
sendChatMessage("$chatName Liquid@(${neighbourPos.asString()}) out of reach (${player.distanceTo(neighbourPos)})")
1984+
} else {
1985+
sendChatMessage("$chatName Liquid out of reach (${player.distanceTo(neighbourPos)})")
1986+
}
1987+
}
19901988
return true
19911989
}
19921990

@@ -2327,7 +2325,6 @@ internal object HighwayTools : PluginModule(
23272325
var itemID = 0
23282326
var destroy = false
23292327
var collect = true
2330-
var primed = false
23312328

23322329
// var isBridge = false ToDo: Implement
23332330

@@ -2368,13 +2365,10 @@ internal object HighwayTools : PluginModule(
23682365
TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> {
23692366
event.getNeighbourSequence(blockPos, placementSearch, maxReach, true).size
23702367
}
2371-
TaskState.BREAK -> {
2372-
event.getVisibleSides(blockPos).size
2373-
}
23742368
else -> 0
23752369
}
23762370

2377-
// ToDo: We need a function that makes a score out of those 3 parameters
2371+
// ToDo: Function that makes a score out of those 3 parameters
23782372
startDistance = startingBlockPos.distanceTo(blockPos)
23792373
eyeDistance = eyePos.distanceTo(blockPos)
23802374
hitVecDistance = (lastHitVec?.distanceTo(blockPos) ?: 0.0)

0 commit comments

Comments
 (0)