diff --git a/src-theme/src/integration/types.ts b/src-theme/src/integration/types.ts index 3a6cfd149c3..2c86cea7174 100644 --- a/src-theme/src/integration/types.ts +++ b/src-theme/src/integration/types.ts @@ -15,6 +15,7 @@ export interface GroupedModules { export type ModuleSetting = BlocksSetting + | ItemsSetting | KeySetting | BooleanSetting | FloatSetting @@ -35,6 +36,12 @@ export interface BlocksSetting { value: string[]; } +export interface ItemsSetting { + valueType: string; + name: string; + value: string; +} + export interface TextSetting { valueType: string; name: string; diff --git a/src-theme/src/routes/clickgui/setting/common/GenericSetting.svelte b/src-theme/src/routes/clickgui/setting/common/GenericSetting.svelte index ef5b1b6447c..013316f217f 100644 --- a/src-theme/src/routes/clickgui/setting/common/GenericSetting.svelte +++ b/src-theme/src/routes/clickgui/setting/common/GenericSetting.svelte @@ -12,6 +12,7 @@ import ColorSetting from "../ColorSetting.svelte"; import TextSetting from "../TextSetting.svelte"; import KeySetting from "../KeySetting.svelte"; + import ItemsSetting from "../items/ItemSetting.svelte"; import BlocksSetting from "../blocks/BlocksSetting.svelte"; import {slide} from "svelte/transition"; import {onMount} from "svelte"; @@ -56,6 +57,8 @@ {:else if setting.valueType === "KEY"} + {:else if setting.valueType === "ITEMS"} + {:else if setting.valueType === "BLOCKS"} {:else if setting.valueType === "TEXT_ARRAY"} @@ -64,4 +67,4 @@
Unsupported setting {setting.valueType}
{/if} -{/if} \ No newline at end of file +{/if} diff --git a/src-theme/src/routes/clickgui/setting/items/Item.svelte b/src-theme/src/routes/clickgui/setting/items/Item.svelte new file mode 100644 index 00000000000..d3449462362 --- /dev/null +++ b/src-theme/src/routes/clickgui/setting/items/Item.svelte @@ -0,0 +1,52 @@ + + + + +
dispatch("toggle", {enabled: !enabled, identifier})}> + {identifier}/ +
{name}
+
+ {#if enabled} + enabled + {:else} + disabled + {/if} +
+
+ + diff --git a/src-theme/src/routes/clickgui/setting/items/ItemSetting.svelte b/src-theme/src/routes/clickgui/setting/items/ItemSetting.svelte new file mode 100644 index 00000000000..c26bcc6ee83 --- /dev/null +++ b/src-theme/src/routes/clickgui/setting/items/ItemSetting.svelte @@ -0,0 +1,93 @@ + + +
+
{$spaceSeperatedNames ? convertToSpacedString(cSetting.name) : cSetting.name}
+ +
+ + + +
+
+ + diff --git a/src-theme/src/routes/clickgui/setting/items/VirtualList.svelte b/src-theme/src/routes/clickgui/setting/items/VirtualList.svelte new file mode 100644 index 00000000000..d41b0e5d5cf --- /dev/null +++ b/src-theme/src/routes/clickgui/setting/items/VirtualList.svelte @@ -0,0 +1,137 @@ + + + + + + + + {#each visible as row (row.index)} + + Missing template + + {/each} + + diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlanGenerator.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlanGenerator.kt index 9c4133fd34b..7b29e4d76eb 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlanGenerator.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlanGenerator.kt @@ -19,7 +19,9 @@ package net.ccbluex.liquidbounce.features.module.modules.player.invcleaner import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.items.ItemFacet +import net.ccbluex.liquidbounce.utils.client.logger import net.ccbluex.liquidbounce.utils.item.isNothing +import net.minecraft.item.Item class CleanupPlanGenerator( private val template: CleanupPlanPlacementTemplate, @@ -58,6 +60,18 @@ class CleanupPlanGenerator( processItemCategory(category, availableItems) } + availableItems.forEach { slot -> + val limit = template.itemLimitPerItem[slot.itemStack.item] ?: Int.MAX_VALUE + var itemCount = packer.usefulItems.count { it.itemStack.item == slot.itemStack.item } + packer.usefulItems.removeIf { + if (itemCount > limit) { + logger.info("removed item from useful items list") + itemCount-- + return@removeIf true + } + false + } + } // We aren't allowed to touch those, so we just consider them as useful. packer.usefulItems.addAll(this.template.forbiddenSlots) @@ -74,7 +88,7 @@ class CleanupPlanGenerator( ) { val maxItemCount = if (category.type.oneIsSufficient) { - if (this.packer.alreadyProviededFunctions.contains(category.type.providedFunction)) 0 else 1 + if (this.packer.alreadyProvidedFunctions.contains(category.type.providedFunction)) 0 else 1 } else { template.itemLimitPerCategory[category] ?: Int.MAX_VALUE } @@ -132,6 +146,7 @@ class CleanupPlanPlacementTemplate( * If an item is not in this map, there is no limit. */ val itemLimitPerCategory: Map, + val itemLimitPerItem: Map, /** * If false, slots which also contains items of that category, those items are not replaced with other items. */ diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemPacker.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemPacker.kt index 5e34ba6a742..e4901731f52 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemPacker.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemPacker.kt @@ -21,7 +21,7 @@ class ItemPacker { */ val usefulItems = HashSet() - val alreadyProviededFunctions = HashSet() + val alreadyProvidedFunctions = HashSet() /** * Takes items from the [itemsToFillIn] list until it collected [maxItemCount] items is and [requiredStackCount] @@ -61,7 +61,7 @@ class ItemPacker { usefulItems.add(filledInItemSlot) - alreadyProviededFunctions.addAll(filledInItem.providedItemFunctions) + alreadyProvidedFunctions.addAll(filledInItem.providedItemFunctions) currentItemCount += filledInItem.itemStack.count currentStackCount++ diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ModuleInventoryCleaner.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ModuleInventoryCleaner.kt index c768599eacb..2f637a1328a 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ModuleInventoryCleaner.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ModuleInventoryCleaner.kt @@ -18,15 +18,21 @@ */ package net.ccbluex.liquidbounce.features.module.modules.player.invcleaner +import net.ccbluex.liquidbounce.config.Value import net.ccbluex.liquidbounce.event.events.ScheduleInventoryActionEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.Module +import net.ccbluex.liquidbounce.utils.client.logger import net.ccbluex.liquidbounce.utils.inventory.ClickInventoryAction import net.ccbluex.liquidbounce.utils.inventory.PlayerInventoryConstraints import net.ccbluex.liquidbounce.utils.inventory.findNonEmptySlotsInInventory +import net.minecraft.block.Blocks +import net.minecraft.item.Item +import net.minecraft.item.Items import net.minecraft.screen.slot.SlotActionType import java.util.HashMap +import kotlin.math.min /** * InventoryCleaner module @@ -43,6 +49,48 @@ object ModuleInventoryCleaner : Module("InventoryCleaner", Category.PLAYER) { private val isGreedy by boolean("Greedy", true) + private var itemLimits: Map = mapOf() + private val presentSettings: MutableList>, Value>> = mutableListOf() + + private fun recount() { + val limits = mutableMapOf() + presentSettings.forEach { (itemsValue, countValue) -> + val count = countValue.get() + itemsValue.get().forEach { item -> + val limitState = limits[item] + // we just follow the lowest filter + limits[item] = if (limitState == null) { + count + } else { + min(count, limitState) + } + } + } + itemLimits = limits + } + + @Suppress("UnusedPrivateProperty") + private val addNewFilter by boolean("AddNewFilter", false).onChange { + val itemType: Value> = items("ItemsToLimit", mutableListOf()).onChanged { + recount() + } + val itemLimit: Value = int("MaxItemSlots", 0, 0..40).onChanged { + recount() + } + presentSettings.add(Pair(itemType, itemLimit)) + false + } + + @Suppress("UnusedPrivateProperty") + private val deleteFilter by boolean("DeleteFilter", false).onChange { + listOf("ItemsToLimit", "MaxItemSlots").forEach { name -> + val index = inner.indexOfFirst { it.name == name } + inner.removeAt(index) + } + recount() + false + } + private val offHandItem by enumChoice("OffHandItem", ItemSortChoice.SHIELD) private val slotItem1 by enumChoice("SlotItem-1", ItemSortChoice.WEAPON) private val slotItem2 by enumChoice("SlotItem-2", ItemSortChoice.BOW) @@ -87,6 +135,7 @@ object ModuleInventoryCleaner : Module("InventoryCleaner", Category.PLAYER) { Pair(ItemSortChoice.THROWABLES.category!!, maxThrowables), Pair(ItemCategory(ItemType.ARROW, 0), maxArrows), ), + itemLimitPerItem = itemLimits, forbiddenSlots = forbiddenSlots, isGreedy = isGreedy, )