Skip to content

Commit 99b91a5

Browse files
committed
Grind Obsidian efficient
1 parent 20a9f52 commit 99b91a5

1 file changed

Lines changed: 29 additions & 28 deletions

File tree

src/main/kotlin/HighwayTools.kt

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ internal object HighwayTools : PluginModule(
142142
private val saveTools by setting("Save Tools", 1, 0..36, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many tools are saved")
143143
private val saveEnder by setting("Save Ender Chests", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many ender chests are saved")
144144
private val disableMode by setting("Disable Mode", DisableMode.NONE, { page == Page.STORAGE_MANAGEMENT }, description = "Choose action when bot is out of materials or tools")
145-
private val tryRefreshSlots by setting("Try refresh slot", false, { page == Page.STORAGE_MANAGEMENT }, description = "Clicks a slot on desync")
145+
// private val tryRefreshSlots by setting("Try refresh slot", false, { page == Page.STORAGE_MANAGEMENT }, description = "Clicks a slot on desync")
146146

147147
// stat settings
148148
val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat")
@@ -236,6 +236,7 @@ internal object HighwayTools : PluginModule(
236236

237237
private var containerTask = BlockTask(BlockPos.ORIGIN, TaskState.DONE, Blocks.AIR, Items.AIR)
238238
private val shulkerOpenTimer = TickTimer(TimeUnit.TICKS)
239+
private var grindCycles = 0
239240

240241
private val packetLimiterMutex = Mutex()
241242
private val packetLimiter = ArrayDeque<Long>()
@@ -868,7 +869,7 @@ internal object HighwayTools : PluginModule(
868869
when (containerTask.taskState) {
869870
TaskState.PICKUP -> {
870871
player.inventorySlots.firstEmpty()?.let {
871-
if (tryRefreshSlots) updateSlot(it.slotNumber)
872+
// if (tryRefreshSlots) updateSlot(it.slotNumber)
872873
}
873874
containerTask.updateState(TaskState.DONE)
874875
}
@@ -998,10 +999,10 @@ internal object HighwayTools : PluginModule(
998999
TaskState.PLACE -> {
9991000
if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1
10001001

1001-
if (tryRefreshSlots) updateSlot()
1002+
// if (tryRefreshSlots) updateSlot()
10021003
}
10031004
TaskState.BREAK -> {
1004-
if (tryRefreshSlots) updateSlot()
1005+
// if (tryRefreshSlots) updateSlot()
10051006
}
10061007
else -> {
10071008
// Nothing
@@ -1102,7 +1103,12 @@ internal object HighwayTools : PluginModule(
11021103
if (player.inventorySlots.firstEmpty() == null) {
11031104
getEjectSlot()?.let {
11041105
throwAllInSlot(it)
1106+
} ?: run {
1107+
sendChatMessage("Full inventory: Can't pickup Item@(${containerTask.blockPos.asString()})")
1108+
containerTask.updateState(TaskState.DONE)
11051109
}
1110+
} else {
1111+
// ToDo: Resolve ghost slot
11061112
}
11071113
containerTask.onStuck()
11081114
}
@@ -1167,8 +1173,12 @@ internal object HighwayTools : PluginModule(
11671173
blockTask.updateState(TaskState.DONE)
11681174
}
11691175
blockTask == containerTask -> {
1170-
moveState = MovementState.PICKUP
1171-
blockTask.updateState(TaskState.PICKUP)
1176+
if (containerTask.collect) {
1177+
moveState = MovementState.PICKUP
1178+
blockTask.updateState(TaskState.PICKUP)
1179+
} else {
1180+
blockTask.updateState(TaskState.DONE)
1181+
}
11721182
}
11731183
else -> {
11741184
blockTask.updateState(TaskState.PLACE)
@@ -1605,9 +1615,9 @@ internal object HighwayTools : PluginModule(
16051615
} else {
16061616
if (storageManagement && grindObsidian &&
16071617
containerTask.taskState == TaskState.DONE &&
1608-
// player.inventorySlots.countBlock(material) < saveMaterial ||
1609-
player.inventorySlots.any { it.stack.isEmpty || InventoryManager.ejectList.contains(it.stack.item.registryName.toString()) }) {
1618+
(player.inventorySlots.countBlock(material) <= saveMaterial || grindCycles > 0)) {
16101619
if (player.inventorySlots.countItem(Items.DIAMOND_PICKAXE) > saveTools) {
1620+
if (grindCycles == 0) grindCycles = player.inventorySlots.count { it.stack.isEmpty || InventoryManager.ejectList.contains(it.stack.item.registryName.toString()) } * 8 - 1
16111621
handleRestock(material.item)
16121622
} else {
16131623
handleRestock(Items.DIAMOND_PICKAXE)
@@ -1688,7 +1698,9 @@ internal object HighwayTools : PluginModule(
16881698
getRemotePos()?.let { pos ->
16891699
containerTask = BlockTask(pos, TaskState.PLACE, Blocks.ENDER_CHEST)
16901700
containerTask.destroy = true
1701+
if (grindCycles > 1) containerTask.collect = false
16911702
containerTask.itemID = Blocks.OBSIDIAN.id
1703+
grindCycles--
16921704
} ?: run {
16931705
disableNoPosition()
16941706
}
@@ -1785,8 +1797,7 @@ internal object HighwayTools : PluginModule(
17851797
player.closeScreen()
17861798
}
17871799

1788-
@JvmStatic
1789-
fun getShulkerData(stack: ItemStack, item: Item): Int {
1800+
private fun getShulkerData(stack: ItemStack, item: Item): Int {
17901801
val tagCompound = if (stack.item is ItemShulkerBox) stack.tagCompound else return 0
17911802

17921803
if (tagCompound != null && tagCompound.hasKey("BlockEntityTag", 10)) {
@@ -1823,31 +1834,20 @@ internal object HighwayTools : PluginModule(
18231834
return null
18241835
}
18251836

1826-
private fun SafeClientEvent.eject(): Boolean {
1827-
return if (player.inventorySlots.firstEmpty() == null) {
1828-
getEjectSlot()?.let {
1829-
throwAllInSlot(it)
1830-
}
1831-
false
1832-
} else {
1833-
true
1834-
}
1835-
}
1836-
18371837
private fun SafeClientEvent.getEjectSlot(): Slot? {
18381838
return player.inventorySlots.firstByStack {
18391839
!it.isEmpty &&
18401840
InventoryManager.ejectList.contains(it.item.registryName.toString())
18411841
}
18421842
}
18431843

1844-
private fun SafeClientEvent.updateSlot(slot: Int = player.inventory.currentItem + 36) {
1845-
clickSlot(0, slot, 0, ClickType.PICKUP)
1846-
connection.sendPacket(CPacketCloseWindow(0))
1847-
runBlocking {
1848-
onMainThreadSafe { playerController.updateController() }
1849-
}
1850-
}
1844+
// private fun SafeClientEvent.updateSlot(slot: Int = player.inventory.currentItem + 36) {
1845+
// clickSlot(0, slot, 0, ClickType.PICKUP)
1846+
// connection.sendPacket(CPacketCloseWindow(0))
1847+
// runBlocking {
1848+
// onMainThreadSafe { playerController.updateController() }
1849+
// }
1850+
// }
18511851

18521852
private fun SafeClientEvent.handleLiquid(blockTask: BlockTask): Boolean {
18531853
var foundLiquid = false
@@ -2192,6 +2192,7 @@ internal object HighwayTools : PluginModule(
21922192
var isOpen = false
21932193
var itemID = 0
21942194
var destroy = false
2195+
var collect = true
21952196
var primed = false
21962197

21972198
// var isBridge = false ToDo: Implement

0 commit comments

Comments
 (0)