@@ -19,7 +19,8 @@ package com.lambda.interaction.material.container.containers
1919
2020import com.lambda.Lambda.mc
2121import com.lambda.context.Automated
22- import com.lambda.context.SafeContext
22+ import com.lambda.event.events.TickEvent
23+ import com.lambda.event.listener.SafeListener.Companion.listen
2324import com.lambda.interaction.material.StackSelection
2425import com.lambda.interaction.material.container.MaterialContainer
2526import com.lambda.interaction.request.inventory.InventoryRequest.Companion.inventoryRequest
@@ -44,20 +45,22 @@ data object CreativeContainer : MaterialContainer(Rank.Creative) {
4445 class CreativeDeposit @Ta5kBuilder constructor(val selection : StackSelection , automated : Automated ) : Task<Unit>(), Automated by automated {
4546 override val name: String get() = " Removing $selection from creative inventory"
4647
47- override fun SafeContext.onStart () {
48- if (! gamemode.isCreative) {
49- // ToDo: Maybe switch gamemode?
50- throw NotInCreativeModeException ()
51- }
48+ init {
49+ listen<TickEvent .Pre > {
50+ if (! gamemode.isCreative) {
51+ // ToDo: Maybe switch gamemode?
52+ throw NotInCreativeModeException ()
53+ }
5254
53- inventoryRequest {
54- player.currentScreenHandler?.slots?.let { slots ->
55- selection.filterSlots(slots).forEach {
56- clickCreativeStack(ItemStack .EMPTY , it.id)
55+ inventoryRequest {
56+ player.currentScreenHandler?.slots?.let { slots ->
57+ selection.filterSlots(slots).forEach {
58+ clickCreativeStack(ItemStack .EMPTY , it.id)
59+ }
5760 }
58- }
59- onComplete { success() }
60- }.submit(queueIfClosed = false )
61+ onComplete { success() }
62+ }.submit(queueIfClosed = false )
63+ }
6164 }
6265 }
6366
@@ -67,24 +70,29 @@ data object CreativeContainer : MaterialContainer(Rank.Creative) {
6770 class CreativeWithdrawal @Ta5kBuilder constructor(val selection : StackSelection , automated : Automated ) : Task<Unit>(), Automated by automated {
6871 override val name: String get() = " Withdrawing $selection from creative inventory"
6972
70- override fun SafeContext.onStart () {
71- selection.optimalStack?.let { optimalStack ->
72- if (player.mainHandStack.equal(optimalStack)) return
73+ init {
74+ listen<TickEvent .Pre > {
75+ selection.optimalStack?.let { optimalStack ->
76+ if (player.mainHandStack.equal(optimalStack)) {
77+ success()
78+ return @listen
79+ }
7380
74- if (! gamemode.isCreative) {
75- // ToDo: Maybe switch gamemode?
76- throw NotInCreativeModeException ()
81+ if (! gamemode.isCreative) {
82+ // ToDo: Maybe switch gamemode?
83+ throw NotInCreativeModeException ()
84+ }
85+
86+ inventoryRequest {
87+ clickCreativeStack(optimalStack, 36 + player.inventory.selectedSlot)
88+ action { player.inventory.selectedStack = optimalStack }
89+ onComplete { success() }
90+ }.submit(queueIfClosed = false )
91+ return @listen
7792 }
7893
79- inventoryRequest {
80- clickCreativeStack(optimalStack, 36 + player.inventory.selectedSlot)
81- player.inventory.selectedStack = optimalStack
82- onComplete { success() }
83- }.submit(queueIfClosed = false )
84- return
94+ throw NoOptimalStackException ()
8595 }
86-
87- throw NoOptimalStackException ()
8896 }
8997 }
9098
0 commit comments