Skip to content

Commit 7e5bcf6

Browse files
committed
Revert "inventory manager start :doom:, and cleanup. Also moved the onStart call when in creative mode before onBlockBreak to keep proper order"
This reverts commit 61d6528.
1 parent 01df8aa commit 7e5bcf6

File tree

9 files changed

+58
-179
lines changed

9 files changed

+58
-179
lines changed

common/src/main/kotlin/com/lambda/config/groups/InventoryConfig.kt

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,26 @@ package com.lambda.config.groups
2020
import com.lambda.interaction.material.ContainerSelection
2121
import com.lambda.interaction.material.ContainerSelection.Companion.selectContainer
2222
import com.lambda.interaction.material.StackSelection
23+
import com.lambda.interaction.material.StackSelection.Companion.selectStack
2324
import com.lambda.interaction.material.container.MaterialContainer
24-
import com.lambda.interaction.request.RequestConfig
25-
import com.lambda.interaction.request.inventory.InventoryRequest
25+
import com.lambda.util.item.ItemUtils
2626
import net.minecraft.block.Block
27+
import net.minecraft.item.Item
28+
import net.minecraft.item.Items
29+
import net.minecraft.item.ToolItem
30+
import net.minecraft.item.ToolMaterial
31+
import net.minecraft.item.ToolMaterials
2732

28-
abstract class InventoryConfig(
29-
prio: Int
30-
) : RequestConfig<InventoryRequest>(prio) {
31-
abstract val disposables: Set<Block>
32-
abstract val swapWithDisposables: Boolean
33-
abstract val providerPriority: Priority
34-
abstract val storePriority: Priority
33+
interface InventoryConfig {
34+
val disposables: Set<Block>
35+
val swapWithDisposables: Boolean
36+
val providerPriority: Priority
37+
val storePriority: Priority
3538

36-
abstract val accessShulkerBoxes: Boolean
37-
abstract val accessEnderChest: Boolean
38-
abstract val accessChests: Boolean
39-
abstract val accessStashes: Boolean
39+
val accessShulkerBoxes: Boolean
40+
val accessEnderChest: Boolean
41+
val accessChests: Boolean
42+
val accessStashes: Boolean
4043

4144
val containerSelection: ContainerSelection get() = selectContainer {
4245
val allowedContainers = mutableSetOf<MaterialContainer.Rank>().apply {
@@ -49,6 +52,27 @@ abstract class InventoryConfig(
4952
ofAnyType(*allowedContainers.toTypedArray())
5053
}
5154

55+
val useWoodenTools: Boolean
56+
val useStoneTools: Boolean
57+
val useIronTools: Boolean
58+
val useDiamondTools: Boolean
59+
val useNetheriteTools: Boolean
60+
val useGoldTools: Boolean
61+
val useShears: Boolean
62+
val useFlintAndSteel: Boolean
63+
64+
val allowedTools get() = mutableSetOf<Item>().apply {
65+
addAll(ItemUtils.tools)
66+
if (!useWoodenTools) removeIf { it is ToolItem && it.material == ToolMaterials.WOOD }
67+
if (!useStoneTools) removeIf { it is ToolItem && it.material == ToolMaterials.STONE }
68+
if (!useIronTools) removeIf { it is ToolItem && it.material == ToolMaterials.IRON }
69+
if (!useDiamondTools) removeIf { it is ToolItem && it.material == ToolMaterials.DIAMOND }
70+
if (!useNetheriteTools) removeIf { it is ToolItem && it.material == ToolMaterials.NETHERITE }
71+
if (!useGoldTools) removeIf { it is ToolItem && it.material == ToolMaterials.GOLD }
72+
if (!useShears) removeIf { it == Items.SHEARS }
73+
if (!useFlintAndSteel) removeIf { it == Items.FLINT_AND_STEEL }
74+
}
75+
5276
enum class Priority {
5377
WithMinItems,
5478
WithMaxItems;

common/src/main/kotlin/com/lambda/config/groups/InventorySettings.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,32 @@
1818
package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
21-
import com.lambda.interaction.request.inventory.InventoryManager
22-
import com.lambda.interaction.request.inventory.InventoryRequest
2321
import com.lambda.util.item.ItemUtils
2422

2523
class InventorySettings(
2624
c: Configurable,
27-
prio: Int = 0,
2825
vis: () -> Boolean = { true },
29-
) : InventoryConfig(prio) {
26+
) : InventoryConfig {
3027
val page by c.setting("Inventory Page", Page.Container, "The page to open when the module is enabled", vis)
3128

3229
override val disposables by c.setting("Disposables", ItemUtils.defaultDisposables, "Items that will be included when checking for a free slot / are allowed to be droped when inventory is full") { vis() && page == Page.Container}
3330
override val swapWithDisposables by c.setting("Swap With Disposables", true, "Swap items with disposable ones") { vis() && page == Page.Container}
34-
override val providerPriority by c.setting("Provider Priority", Priority.WithMinItems, "What container to prefer when retrieving the item from") { vis() && page == Page.Container}
35-
override val storePriority by c.setting("Store Priority", Priority.WithMinItems, "What container to prefer when storing the item to") { vis() && page == Page.Container}
31+
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from") { vis() && page == Page.Container}
32+
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when storing the item to") { vis() && page == Page.Container}
3633

3734
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", true, "Allow access to the player's shulker boxes") { vis() && page == Page.Access}
3835
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest") { vis() && page == Page.Access}
3936
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests") { vis() && page == Page.Access}
4037
override val accessStashes by c.setting("Access Stashes", false, "Allow access to the player's stashes") { vis() && page == Page.Access}
4138

42-
override fun requestInternal(request: InventoryRequest, queueIfClosed: Boolean) {
43-
InventoryManager.request(request)
44-
}
39+
override val useWoodenTools by c.setting("Use Wooden Tools", false, "Use wooden tools to mine blocks") { vis() && page == Page.Tools}
40+
override val useStoneTools by c.setting("Use Stone Tools", false, "Use stone tools to mine blocks") { vis() && page == Page.Tools}
41+
override val useIronTools by c.setting("Use Iron Tools", false, "Use iron tools to mine blocks") { vis() && page == Page.Tools}
42+
override val useDiamondTools by c.setting("Use Diamond Tools", true, "Use diamond tools to mine blocks") { vis() && page == Page.Tools}
43+
override val useNetheriteTools by c.setting("Use Netherite Tools", true, "Use netherite tools to mine blocks") { vis() && page == Page.Tools}
44+
override val useGoldTools by c.setting("Use Gold Tools", false, "Use gold tools to mine blocks") { vis() && page == Page.Tools}
45+
override val useShears by c.setting("Use Shears", true, "Use shears to mine blocks") { vis() && page == Page.Tools}
46+
override val useFlintAndSteel by c.setting("Use Flint and Steel", true, "Use flint and steel to mine blocks?") { vis() && page == Page.Tools}
4547

4648
enum class Page {
4749
Container, Access, Tools

common/src/main/kotlin/com/lambda/event/events/UpdateManagerEvent.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ package com.lambda.event.events
2020
import com.lambda.event.Event
2121

2222
sealed class UpdateManagerEvent {
23-
data object Rotation : Event
24-
data object Inventory : Event
25-
data object Hotbar : Event
26-
data object Break : Event
27-
data object Place : Event
23+
class Rotation : Event
24+
class Hotbar : Event
25+
class Break : Event
26+
class Place : Event
2827
}

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ object BreakManager : RequestHandler<BreakRequest>(
629629

630630
if (gamemode.isCreative) {
631631
lastPosStarted = ctx.expectedPos
632-
info.request.onStart?.invoke(ctx.expectedPos)
633632
onBlockBreak(info)
633+
info.request.onStart?.invoke(ctx.expectedPos)
634634
info.startBreakPacket(world, interaction)
635635
breakCooldown = info.breakConfig.breakDelay
636636
return true
@@ -683,5 +683,5 @@ object BreakManager : RequestHandler<BreakRequest>(
683683
return inRange && correctMaterial
684684
}
685685

686-
override fun preEvent(): Event = UpdateManagerEvent.Break.post()
686+
override fun preEvent(): Event = UpdateManagerEvent.Break().post()
687687
}

common/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
4242
TickEvent.Input.Pre,
4343
TickEvent.Input.Post,
4444
TickEvent.Player.Post,
45+
// ToDo: Post interact
4546
onClose = { checkResetSwap() }
4647
) {
4748
val serverSlot get() = runSafe {
@@ -121,5 +122,5 @@ object HotbarManager : RequestHandler<HotbarRequest>(
121122
}
122123
}
123124

124-
override fun preEvent(): Event = UpdateManagerEvent.Hotbar.post()
125+
override fun preEvent(): Event = UpdateManagerEvent.Hotbar().post()
125126
}

common/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryManager.kt

Lines changed: 0 additions & 117 deletions
This file was deleted.

common/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.

common/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,5 +365,5 @@ object PlaceManager : RequestHandler<PlaceRequest>(
365365
)
366366
}
367367

368-
override fun preEvent(): Event = UpdateManagerEvent.Place.post()
368+
override fun preEvent(): Event = UpdateManagerEvent.Place().post()
369369
}

common/src/main/kotlin/com/lambda/interaction/request/rotation/RotationManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,5 @@ object RotationManager : RequestHandler<RotationRequest>(
290290
}
291291
}
292292

293-
override fun preEvent(): Event = UpdateManagerEvent.Rotation.post()
293+
override fun preEvent(): Event = UpdateManagerEvent.Rotation().post()
294294
}

0 commit comments

Comments
 (0)