Skip to content

Commit 39167e9

Browse files
committed
Life maintenance mode for building
1 parent 6ebfb10 commit 39167e9

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/main/kotlin/com/lambda/module/modules/player/AutoEat.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.lambda.module.modules.player
1919

2020
import com.lambda.config.groups.EatConfig.Companion.reasonEating
2121
import com.lambda.config.groups.EatSettings
22+
import com.lambda.config.groups.InventorySettings
2223
import com.lambda.event.events.TickEvent
2324
import com.lambda.event.listener.SafeListener.Companion.listen
2425
import com.lambda.module.Module
@@ -34,18 +35,20 @@ object AutoEat : Module(
3435
tag = ModuleTag.PLAYER,
3536
) {
3637
private enum class Group(override val displayName: String) : NamedEnum {
37-
FOOD("Food"),
38+
Eating("Eating"),
39+
Inventory("Inventory")
3840
}
3941

40-
private val eat = EatSettings(this, Group.FOOD)
42+
private val eat = EatSettings(this, Group.Eating)
43+
private val inventory = InventorySettings(this, Group.Inventory)
4144
private var eatTask: EatTask? = null
4245

4346
init {
4447
listen<TickEvent.Pre> {
4548
val reason = reasonEating(eat)
4649
if (eatTask != null || !reason.shouldEat()) return@listen
4750

48-
val task = eat(eat)
51+
val task = eat(eat, inventory)
4952
task.finally { eatTask = null }
5053
task.run()
5154
eatTask = task

src/main/kotlin/com/lambda/module/modules/player/HighwayTools.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ object HighwayTools : Module(
148148
inventory = inventory,
149149
hotbar = hotbar,
150150
eat = eat,
151+
lifeMaintenance = true,
151152
).run()
152153
}
153154

src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,17 @@ import net.minecraft.entity.ItemEntity
6363
import net.minecraft.util.math.BlockPos
6464
import java.util.concurrent.ConcurrentLinkedQueue
6565

66-
class BuildTask @Ta5kBuilder constructor(
66+
class BuildTask private constructor(
6767
private val blueprint: Blueprint,
68-
private val finishOnDone: Boolean = true,
69-
private val collectDrops: Boolean = TaskFlowModule.build.collectDrops,
70-
private val build: BuildConfig = TaskFlowModule.build,
71-
private val rotation: RotationConfig = TaskFlowModule.rotation,
72-
private val interactionConfig: InteractionConfig = TaskFlowModule.interaction,
73-
private val inventory: InventoryConfig = TaskFlowModule.inventory,
74-
private val hotbar: HotbarConfig = TaskFlowModule.hotbar,
75-
private val eat: EatConfig = TaskFlowModule.eat,
68+
private val finishOnDone: Boolean,
69+
private val collectDrops: Boolean,
70+
private val build: BuildConfig,
71+
private val rotation: RotationConfig,
72+
private val interactionConfig: InteractionConfig,
73+
private val inventory: InventoryConfig,
74+
private val hotbar: HotbarConfig,
75+
private val eat: EatConfig,
76+
private val lifeMaintenance: Boolean,
7677
) : Task<Structure>() {
7778
override val name: String get() = "Building $blueprint with ${(breaks / (age / 20.0 + 0.001)).string} b/s ${(placements / (age / 20.0 + 0.001)).string} p/s"
7879

@@ -98,9 +99,8 @@ class BuildTask @Ta5kBuilder constructor(
9899

99100
init {
100101
listen<TickEvent.Pre> {
101-
// val parentEating = (parent as? BuildTask)?.eatTask != null
102102
when {
103-
eatTask == null && reasonEating(eat).shouldEat() -> {
103+
lifeMaintenance && eatTask == null && reasonEating(eat).shouldEat() -> {
104104
eatTask = eat(eat)
105105
eatTask?.finally {
106106
eatTask = null
@@ -255,8 +255,9 @@ class BuildTask @Ta5kBuilder constructor(
255255
inventory: InventoryConfig = TaskFlowModule.inventory,
256256
hotbar: HotbarConfig = TaskFlowModule.hotbar,
257257
eat: EatConfig = TaskFlowModule.eat,
258+
lifeMaintenance: Boolean = false,
258259
blueprint: () -> Blueprint,
259-
) = BuildTask(blueprint(), finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat)
260+
) = BuildTask(blueprint(), finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat, lifeMaintenance)
260261

261262
@Ta5kBuilder
262263
fun Structure.build(
@@ -268,7 +269,8 @@ class BuildTask @Ta5kBuilder constructor(
268269
inventory: InventoryConfig = TaskFlowModule.inventory,
269270
hotbar: HotbarConfig = TaskFlowModule.hotbar,
270271
eat: EatConfig = TaskFlowModule.eat,
271-
) = BuildTask(toBlueprint(), finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat)
272+
lifeMaintenance: Boolean = false,
273+
) = BuildTask(toBlueprint(), finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat, lifeMaintenance)
272274

273275
@Ta5kBuilder
274276
fun Blueprint.build(
@@ -280,7 +282,8 @@ class BuildTask @Ta5kBuilder constructor(
280282
inventory: InventoryConfig = TaskFlowModule.inventory,
281283
hotbar: HotbarConfig = TaskFlowModule.hotbar,
282284
eat: EatConfig = TaskFlowModule.eat,
283-
) = BuildTask(this, finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat)
285+
lifeMaintenance: Boolean = false,
286+
) = BuildTask(this, finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat, lifeMaintenance)
284287

285288
@Ta5kBuilder
286289
fun breakAndCollectBlock(
@@ -293,9 +296,10 @@ class BuildTask @Ta5kBuilder constructor(
293296
inventory: InventoryConfig = TaskFlowModule.inventory,
294297
hotbar: HotbarConfig = TaskFlowModule.hotbar,
295298
eat: EatConfig = TaskFlowModule.eat,
299+
lifeMaintenance: Boolean = false,
296300
) = BuildTask(
297301
blockPos.toStructure(TargetState.Air).toBlueprint(),
298-
finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat
302+
finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat, lifeMaintenance
299303
)
300304

301305
@Ta5kBuilder
@@ -309,9 +313,10 @@ class BuildTask @Ta5kBuilder constructor(
309313
inventory: InventoryConfig = TaskFlowModule.inventory,
310314
hotbar: HotbarConfig = TaskFlowModule.hotbar,
311315
eat: EatConfig = TaskFlowModule.eat,
316+
lifeMaintenance: Boolean = false,
312317
) = BuildTask(
313318
blockPos.toStructure(TargetState.Air).toBlueprint(),
314-
finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat
319+
finishOnDone, collectDrops, build, rotation, interact, inventory, hotbar, eat, lifeMaintenance
315320
)
316321
}
317322
}

0 commit comments

Comments
 (0)