Skip to content

Commit 97ac9bc

Browse files
chore: Move ItemSlotType to package of ItemSlot (#7598)
1 parent 70404ae commit 97ac9bc

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/cheststealer/ModuleChestStealer.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import net.ccbluex.liquidbounce.features.module.modules.player.cheststealer.feat
2828
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.CleanupPlanGenerator
2929
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.InventoryCleanupPlan
3030
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemCategorization
31-
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemSlotType
3231
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ModuleInventoryCleaner
3332
import net.ccbluex.liquidbounce.utils.inventory.CheckScreenHandlerTypeConfigurable
3433
import net.ccbluex.liquidbounce.utils.inventory.CheckScreenTitleConfigurable
@@ -231,7 +230,7 @@ object ModuleChestStealer : ClientModule("ChestStealer", Category.PLAYER) {
231230
val freeSlotsInInv = mainInventory.count { it.itemStack.isEmpty }
232231

233232
val spaceGainedThroughMerge = cleanupPlan.mergeableItems.entries.sumOf { (id, slots) ->
234-
val slotsInChest = slots.count { it.slotType == ItemSlotType.CONTAINER }
233+
val slotsInChest = slots.count { it.slotType == ItemSlot.Type.CONTAINER }
235234
val totalCount = slots.sumOf { it.itemStack.count }
236235

237236
val mergedStackCount = ceil(totalCount.toDouble() / id.item.defaultMaxStackSize.toDouble()).toInt()
@@ -255,7 +254,7 @@ object ModuleChestStealer : ClientModule("ChestStealer", Category.PLAYER) {
255254
for (i in cleanupPlan.swaps.indices) {
256255
val hotbarSwap = cleanupPlan.swaps[i]
257256
// We only care about swaps from the chest to the hotbar
258-
if (hotbarSwap.from.slotType != ItemSlotType.CONTAINER) {
257+
if (hotbarSwap.from.slotType != ItemSlot.Type.CONTAINER) {
259258
continue
260259
}
261260

src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlanGenerator.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,3 @@ class CleanupPlanPlacementTemplate(
164164
val forbiddenSlots: Set<ItemSlot>,
165165
val forbiddenSlotsToFill: Set<ItemSlot>
166166
)
167-
168-
enum class ItemSlotType {
169-
HOTBAR,
170-
OFFHAND,
171-
ARMOR,
172-
INVENTORY,
173-
174-
/**
175-
* e.g. chests
176-
*/
177-
CONTAINER,
178-
}

src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemCategorization.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class ItemCategorization(
178178
companion object {
179179
@JvmStatic
180180
private fun constructArmorPiece(item: Item, id: Int): ArmorPiece {
181-
return ArmorPiece(VirtualItemSlot(item.defaultInstance, ItemSlotType.ARMOR, id))
181+
return ArmorPiece(VirtualItemSlot(item.defaultInstance, ItemSlot.Type.ARMOR, id))
182182
}
183183

184184
/**
@@ -196,7 +196,7 @@ class ItemCategorization(
196196
/**
197197
* Sometimes there are situations where armor pieces are not the best ones with the current armor, but become
198198
* the best ones as soon as we upgrade one of the other armor pieces.
199-
* In those cases we don't want to miss out on this armor piece in the future thus we keep it.
199+
* In those cases, we don't want to miss out on this armor piece in the future thus we keep it.
200200
*/
201201
private val futureArmorToKeep: List<ItemSlot>
202202
private val armorComparator: ArmorComparator

src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ItemFacet.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.items
2121
import it.unimi.dsi.fastutil.objects.ObjectIntPair
2222
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemCategory
2323
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemFunction
24-
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemSlotType
2524
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemType
2625
import net.ccbluex.liquidbounce.utils.inventory.ItemSlot
2726
import net.ccbluex.liquidbounce.utils.item.durability
@@ -40,7 +39,7 @@ open class ItemFacet(val itemSlot: ItemSlot) : Comparable<ItemFacet> {
4039
get() = this.itemSlot.itemStack
4140

4241
val isInHotbar: Boolean
43-
get() = this.itemSlot.slotType == ItemSlotType.HOTBAR || this.itemSlot.slotType == ItemSlotType.OFFHAND
42+
get() = this.itemSlot.slotType == ItemSlot.Type.HOTBAR || this.itemSlot.slotType == ItemSlot.Type.OFFHAND
4443

4544
open fun isSignificantlyBetter(other: ItemFacet): Boolean {
4645
return false

src/main/kotlin/net/ccbluex/liquidbounce/utils/inventory/ItemSlot.kt

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package net.ccbluex.liquidbounce.utils.inventory
2020

21-
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemSlotType
2221
import net.ccbluex.liquidbounce.utils.client.SilentHotbar
2322
import net.ccbluex.liquidbounce.utils.client.mc
2423
import net.ccbluex.liquidbounce.utils.client.player
@@ -36,7 +35,7 @@ import kotlin.math.abs
3635
*/
3736
sealed interface ItemSlot {
3837
val itemStack: ItemStack
39-
val slotType: ItemSlotType
38+
val slotType: Type
4039

4140
/**
4241
* Used for example for slot click packets
@@ -73,14 +72,26 @@ sealed interface ItemSlot {
7372
@JvmField
7473
val PREFER_MORE_ITEM: Comparator<ItemSlot> = PreferStackSize.PREFER_MORE.asItemSlotComparator()
7574
}
75+
76+
enum class Type {
77+
HOTBAR,
78+
OFFHAND,
79+
ARMOR,
80+
INVENTORY,
81+
82+
/**
83+
* e.g. chests
84+
*/
85+
CONTAINER,
86+
}
7687
}
7788

7889
/**
7990
* @param id the id this slot is identified by. Two virtual slots that have the same id are considered equal.
8091
*/
8192
class VirtualItemSlot(
8293
override val itemStack: ItemStack,
83-
override val slotType: ItemSlotType,
94+
override val slotType: ItemSlot.Type,
8495
val id: Int
8596
) : ItemSlot {
8697
override fun getIdForServer(screen: AbstractContainerScreen<*>?): Nothing =
@@ -109,8 +120,8 @@ class ContainerItemSlot(val slotInContainer: Int) : ItemSlot {
109120
override val itemStack: ItemStack
110121
get() = this.screen.menu.slots[this.slotInContainer].item
111122

112-
override val slotType: ItemSlotType
113-
get() = ItemSlotType.CONTAINER
123+
override val slotType: ItemSlot.Type
124+
get() = ItemSlot.Type.CONTAINER
114125

115126
override fun getIdForServer(screen: AbstractContainerScreen<*>?): Int = this.slotInContainer
116127

@@ -151,8 +162,8 @@ open class HotbarItemSlot(val hotbarSlot: Int) : ItemSlot {
151162
override val itemStack: ItemStack
152163
get() = player.inventory.getItem(this.hotbarSlot)
153164

154-
override val slotType: ItemSlotType
155-
get() = ItemSlotType.HOTBAR
165+
override val slotType: ItemSlot.Type
166+
get() = ItemSlot.Type.HOTBAR
156167

157168
open val hotbarSlotForServer: Int = hotbarSlot
158169

@@ -207,8 +218,8 @@ class InventoryItemSlot(private val inventorySlot: Int) : ItemSlot {
207218
override val itemStack: ItemStack
208219
get() = player.inventory.getItem(9 + this.inventorySlot)
209220

210-
override val slotType: ItemSlotType
211-
get() = ItemSlotType.INVENTORY
221+
override val slotType: ItemSlot.Type
222+
get() = ItemSlot.Type.INVENTORY
212223

213224
override fun getIdForServer(screen: AbstractContainerScreen<*>?): Int {
214225
return if (screen == null) 9 + inventorySlot else screen.itemCount() - 36 + this.inventorySlot
@@ -234,8 +245,8 @@ class ArmorItemSlot(private val equipmentSlot: EquipmentSlot) : ItemSlot {
234245
override val itemStack: ItemStack
235246
get() = player.getItemBySlot(equipmentSlot)
236247

237-
override val slotType: ItemSlotType
238-
get() = ItemSlotType.ARMOR
248+
override val slotType: ItemSlot.Type
249+
get() = ItemSlot.Type.ARMOR
239250

240251
override fun getIdForServer(screen: AbstractContainerScreen<*>?) =
241252
if (screen == null) 8 - this.equipmentSlot.index else null
@@ -258,8 +269,8 @@ data object OffHandSlot : HotbarItemSlot(-1) {
258269
override val itemStack: ItemStack
259270
get() = player.offhandItem
260271

261-
override val slotType: ItemSlotType
262-
get() = ItemSlotType.OFFHAND
272+
override val slotType: ItemSlot.Type
273+
get() = ItemSlot.Type.OFFHAND
263274

264275
override val hotbarSlotForServer: Int = 40
265276

src/main/kotlin/net/ccbluex/liquidbounce/utils/item/ArmorPiece.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
*/
1919
package net.ccbluex.liquidbounce.utils.item
2020

21-
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemSlotType
2221
import net.ccbluex.liquidbounce.utils.inventory.ItemSlot
2322
import net.minecraft.world.entity.EquipmentSlot
2423

2524
/**
26-
* @see net.minecraft.item.equipment.ArmorMaterial.createAttributeModifiers
25+
* @see net.minecraft.world.item.equipment.ArmorMaterial.createAttributes
2726
*/
2827
@JvmInline
2928
value class ArmorPiece(val itemSlot: ItemSlot) {
@@ -34,9 +33,9 @@ value class ArmorPiece(val itemSlot: ItemSlot) {
3433
val inventorySlot: Int
3534
get() = 36 + entitySlotId
3635
val isAlreadyEquipped: Boolean
37-
get() = itemSlot.slotType == ItemSlotType.ARMOR
36+
get() = itemSlot.slotType == ItemSlot.Type.ARMOR
3837
val isReachableByHand: Boolean
39-
get() = itemSlot.slotType == ItemSlotType.HOTBAR
38+
get() = itemSlot.slotType == ItemSlot.Type.HOTBAR
4039

4140
val toughness: Float
4241
get() = itemSlot.itemStack.armorToughness!!.toFloat()

0 commit comments

Comments
 (0)