Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.

Commit 7719ad3

Browse files
committed
[fix] Fixed AutoObsidian target stack counting
1 parent 8ba2333 commit 7719ad3

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt

+23-30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import me.zeroeightsix.kami.process.AutoObsidianProcess
77
import me.zeroeightsix.kami.setting.Settings
88
import me.zeroeightsix.kami.util.BaritoneUtils
99
import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest
10+
import me.zeroeightsix.kami.util.EntityUtils
1011
import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem
1112
import me.zeroeightsix.kami.util.InventoryUtils
1213
import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo
@@ -58,8 +59,6 @@ object AutoObsidian : Module() {
5859
private var playerPos = BlockPos(0, -1, 0)
5960
private var placingPos = BlockPos(0, -1, 0)
6061
private var shulkerBoxId = 0
61-
private var enderChestCount = -1
62-
private var obsidianCount = -1
6362
private var tickCount = 0
6463
private var openTime = 0L
6564

@@ -154,12 +153,6 @@ object AutoObsidian : Module() {
154153
}
155154
}
156155

157-
/* Updates ender chest and obsidian counts before placing and mining ender chest */
158-
if (state == State.SEARCHING) {
159-
enderChestCount = InventoryUtils.countItem(0, 35, 130)
160-
obsidianCount = countObsidian()
161-
}
162-
163156
/* Updates main state */
164157
updateMainState()
165158

@@ -172,16 +165,16 @@ object AutoObsidian : Module() {
172165
}
173166

174167
private fun updateMainState() {
175-
val placedEnderChest = enderChestCount - InventoryUtils.countItem(0, 35, 130)
176-
val targetEnderChest = (targetStacks.value * 64 - obsidianCount) / 8
168+
val obbyCount = countObby()
169+
177170
state = when {
178-
state == State.DONE && autoRefill.value && InventoryUtils.countItem(0, 35, 49) <= threshold.value -> {
171+
state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(49) <= threshold.value -> {
179172
State.SEARCHING
180173
}
181-
state == State.COLLECTING && getDroppedItem(49, 16.0f) == null -> {
174+
state == State.COLLECTING && getDroppedItem(49, 8.0f) == null -> {
182175
State.DONE
183176
}
184-
state != State.DONE && mc.world.isAirBlock(placingPos) && placedEnderChest >= targetEnderChest -> {
177+
state != State.DONE && mc.world.isAirBlock(placingPos) && obbyCount >= targetStacks.value -> {
185178
State.COLLECTING
186179
}
187180
state == State.MINING && mc.world.isAirBlock(placingPos) -> {
@@ -190,7 +183,7 @@ object AutoObsidian : Module() {
190183
state == State.PLACING && !mc.world.isAirBlock(placingPos) -> {
191184
State.PRE_MINING
192185
}
193-
state == State.SEARCHING && searchingState == SearchingState.DONE && placedEnderChest < targetEnderChest -> {
186+
state == State.SEARCHING && searchingState == SearchingState.DONE && obbyCount < targetStacks.value -> {
194187
State.PLACING
195188
}
196189
else -> state
@@ -199,20 +192,20 @@ object AutoObsidian : Module() {
199192

200193
private fun updateSearchingState() {
201194
searchingState = when {
202-
searchingState == SearchingState.PLACING && InventoryUtils.countItem(0, 35, 130) > 0 -> {
195+
searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(130) > 0 -> {
203196
SearchingState.DONE
204197
}
205-
searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> {
198+
searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 8.0f) == null -> {
206199
SearchingState.DONE
207200
}
208201
searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> {
209-
if (InventoryUtils.countItem(0, 35, 130) > 0) {
202+
if (InventoryUtils.countItemAll(130) > 0) {
210203
SearchingState.COLLECTING
211204
} else { /* In case if the shulker wasn't placed due to server lag */
212205
SearchingState.PLACING
213206
}
214207
}
215-
searchingState == SearchingState.OPENING && (InventoryUtils.countItem(0, 35, 130) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> {
208+
searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(130) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> {
216209
SearchingState.PRE_MINING
217210
}
218211
searchingState == SearchingState.PLACING && !mc.world.isAirBlock(placingPos) -> {
@@ -226,21 +219,23 @@ object AutoObsidian : Module() {
226219
}
227220
}
228221

222+
private fun countObby(): Int {
223+
val inventory = InventoryUtils.countItemAll(49)
224+
val dropped = EntityUtils.getDroppedItems(49, 8.0f).sumBy { it.item.count }
225+
return ceil((inventory + dropped) / 8.0f).toInt() / 8
226+
}
227+
229228
private fun setPlacingPos() {
230229
if (getPlacingPos().y != -1) {
231230
placingPos = getPlacingPos()
232231
} else {
233232
sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.")
234-
mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
233+
mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
235234
this.disable()
236235
return
237236
}
238237
}
239238

240-
private fun countObsidian(): Int {
241-
return ceil(InventoryUtils.countItem(0, 35, 49).toDouble() / 8.0).toInt() * 8
242-
}
243-
244239
private fun getPlacingPos(): BlockPos {
245240
val pos = playerPos
246241
var facing = EnumFacing.NORTH
@@ -271,7 +266,7 @@ object AutoObsidian : Module() {
271266
if (InventoryUtils.getSlotsHotbar(i) == null) {
272267
if (i != 234) continue else {
273268
sendChatMessage("$chatName No shulker box was found in hotbar, disabling.")
274-
mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
269+
mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
275270
this.disable()
276271
return
277272
}
@@ -299,7 +294,7 @@ object AutoObsidian : Module() {
299294
state = State.SEARCHING
300295
} else {
301296
sendChatMessage("$chatName No ender chest was found in inventory, disabling.")
302-
mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
297+
mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
303298
this.disable()
304299
return
305300
}
@@ -328,15 +323,15 @@ object AutoObsidian : Module() {
328323
val currentContainer = mc.player.openContainer
329324
var enderChestSlot = -1
330325
for (i in 0..26) {
331-
if (getIdFromItem(currentContainer.inventory[i].getItem()) == 130) {
326+
if (getIdFromItem(currentContainer.inventory[i].item) == 130) {
332327
enderChestSlot = i
333328
}
334329
}
335330
if (enderChestSlot != -1) {
336331
mc.playerController.windowClick(currentContainer.windowId, enderChestSlot, 0, ClickType.QUICK_MOVE, mc.player)
337332
} else {
338333
sendChatMessage("$chatName No ender chest was found in shulker, disabling.")
339-
mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
334+
mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
340335
this.disable()
341336
}
342337
}, delayTicks.value * 50L, TimeUnit.MILLISECONDS)
@@ -349,7 +344,7 @@ object AutoObsidian : Module() {
349344
return
350345
} else if (InventoryUtils.getSlots(0, 35, 278) == null) {
351346
sendChatMessage("$chatName No pickaxe was found in inventory, disabling.")
352-
mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
347+
mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f))
353348
this.disable()
354349
return
355350
}
@@ -379,8 +374,6 @@ object AutoObsidian : Module() {
379374
searchingState = SearchingState.PLACING
380375
playerPos = BlockPos(0, -1, 0)
381376
placingPos = BlockPos(0, -1, 0)
382-
enderChestCount = -1
383-
obsidianCount = -1
384377
tickCount = 0
385378
}
386379
/* End of tasks */

src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ object EntityUtils {
152152
return mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), entityIn.positionVector, false, true, false) == null
153153
}
154154

155-
fun getDroppedItems(itemId: Int, range: Float): ArrayList<Entity>? {
156-
val entityList = ArrayList<Entity>()
155+
fun getDroppedItems(itemId: Int, range: Float): ArrayList<EntityItem> {
156+
val entityList = ArrayList<EntityItem>()
157157
for (currentEntity in mc.world.loadedEntityList) {
158158
if (currentEntity.getDistance(mc.player) > range) continue /* Entities within specified blocks radius */
159159
if (currentEntity !is EntityItem) continue /* Entites that are dropped item */
@@ -165,7 +165,7 @@ object EntityUtils {
165165

166166
fun getDroppedItem(itemId: Int, range: Float) =
167167
getDroppedItems(itemId, range)
168-
?.minByOrNull { mc.player.getDistance(it) }
168+
.minByOrNull { mc.player.getDistance(it) }
169169
?.positionVector
170170
?.toBlockPos()
171171
}

0 commit comments

Comments
 (0)