Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24746e4

Browse files
BaitinqAvanatiker
andauthored
InventoryManager: Mending help mode (#458)
* InventoryManager: Add "helpMend" setting This setting helps you mend items while being AFK (made thinking about AFK fishing) by replacing the offhand item with low HP items of the same type that have the mending enchantment. * Cleanup Co-authored-by: Constructor <[email protected]>
1 parent 414581b commit 24746e4

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/main/kotlin/com/lambda/client/module/modules/player/InventoryManager.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import com.lambda.client.setting.settings.impl.collection.CollectionSetting
1212
import com.lambda.client.util.TickTimer
1313
import com.lambda.client.util.TimeUnit
1414
import com.lambda.client.util.items.*
15+
import com.lambda.client.util.text.MessageSendHelper
1516
import com.lambda.client.util.threads.safeListener
1617
import net.minecraft.client.gui.inventory.GuiContainer
18+
import net.minecraft.enchantment.EnchantmentHelper
19+
import net.minecraft.init.Enchantments
1720
import net.minecraft.inventory.Slot
1821
import net.minecraft.item.ItemStack
1922
import net.minecraftforge.fml.common.gameevent.TickEvent
@@ -43,10 +46,11 @@ object InventoryManager : Module(
4346
private val fullOnly by setting("Only At Full", false, { autoEject })
4447
private val pauseMovement by setting("Pause Movement", true)
4548
private val delay by setting("Delay Ticks", 1, 0..20, 1, unit = " ticks")
49+
private val helpMend by setting("Help Mend", false, description = "Helps mending items by replacing the offhand item with low HP items of the same type")
4650
val ejectList = setting(CollectionSetting("Eject List", defaultEjectList))
4751

4852
enum class State {
49-
IDLE, SAVING_ITEM, REFILLING_BUILDING, REFILLING, EJECTING
53+
IDLE, SAVING_ITEM, HELPING_MEND, REFILLING_BUILDING, REFILLING, EJECTING
5054
}
5155

5256
private var currentState = State.IDLE
@@ -78,6 +82,7 @@ object InventoryManager : Module(
7882

7983
when (currentState) {
8084
State.SAVING_ITEM -> saveItem()
85+
State.HELPING_MEND -> helpMend()
8186
State.REFILLING_BUILDING -> refillBuilding()
8287
State.REFILLING -> refill()
8388
State.EJECTING -> eject()
@@ -91,6 +96,7 @@ object InventoryManager : Module(
9196
private fun SafeClientEvent.setState() {
9297
currentState = when {
9398
saveItemCheck() -> State.SAVING_ITEM
99+
helpMendCheck() -> State.HELPING_MEND
94100
refillBuildingCheck() -> State.REFILLING_BUILDING
95101
refillCheck() -> State.REFILLING
96102
ejectCheck() -> State.EJECTING
@@ -111,6 +117,12 @@ object InventoryManager : Module(
111117
return itemSaver && checkDamage(player.heldItemMainhand)
112118
}
113119

120+
private fun SafeClientEvent.helpMendCheck() : Boolean {
121+
return helpMend
122+
&& (player.heldItemOffhand.itemDamage == 0
123+
|| EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, player.heldItemOffhand) == 0)
124+
}
125+
114126
private fun SafeClientEvent.refillBuildingCheck(): Boolean {
115127
if (!autoRefill || !buildingMode || buildingBlockID == 0) return false
116128

@@ -154,6 +166,17 @@ object InventoryManager : Module(
154166
}
155167
}
156168

169+
private fun SafeClientEvent.helpMend() {
170+
player.inventorySlots.filterByStack {
171+
it.item == player.heldItemOffhand.item
172+
&& EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, it) != 0
173+
&& it.itemDamage != 0
174+
}.firstOrNull()?.let {
175+
MessageSendHelper.sendChatMessage("$chatName Switching offhand to another item (Help Mend).")
176+
moveToSlot(this@InventoryManager, it, player.offhandSlot)
177+
}
178+
}
179+
157180
private fun SafeClientEvent.refillBuilding() {
158181
player.storageSlots.firstID(buildingBlockID)?.let {
159182
quickMoveSlot(this@InventoryManager, it)

0 commit comments

Comments
 (0)