Skip to content

Commit 3fc192b

Browse files
committed
Earlier config save catch
1 parent 2933cef commit 3fc192b

File tree

9 files changed

+31
-24
lines changed

9 files changed

+31
-24
lines changed

common/src/main/kotlin/com/lambda/config/AbstractSetting.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,6 @@ abstract class AbstractSetting<T : Any>(
104104
}
105105

106106
class ValueListener<T>(val requiresValueChange: Boolean, val execute: (from: T, to: T) -> Unit)
107+
108+
override fun toString() = "Setting $name: $value of type ${type.typeName}"
107109
}

common/src/main/kotlin/com/lambda/config/Configurable.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.lambda.config.settings.complex.BlockSetting
1717
import com.lambda.config.settings.complex.ColorSetting
1818
import com.lambda.config.settings.complex.KeyBindSetting
1919
import com.lambda.config.settings.numeric.*
20+
import com.lambda.util.Communication.logError
2021
import com.lambda.util.KeyCode
2122
import com.lambda.util.Nameable
2223
import net.minecraft.block.Block
@@ -45,7 +46,11 @@ abstract class Configurable(
4546
override fun toJson() =
4647
JsonObject().apply {
4748
settings.forEach { setting ->
48-
add(setting.name, setting.toJson())
49+
try {
50+
add(setting.name, setting.toJson())
51+
} catch (e: Exception) {
52+
logError("Failed to serialize $setting in ${this::class.simpleName}", e)
53+
}
4954
}
5055
}
5156

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import com.lambda.util.BlockUtils.vecOf
2323
import com.lambda.util.item.ItemStackUtils.equal
2424
import com.lambda.util.math.VecUtils.distSq
2525
import com.lambda.util.world.raycast.RayCastUtils.blockResult
26-
import net.minecraft.block.Block
2726
import net.minecraft.block.OperatorBlock
2827
import net.minecraft.block.pattern.CachedBlockPosition
2928
import net.minecraft.item.BlockItem
@@ -37,9 +36,7 @@ import net.minecraft.util.math.BlockPos
3736
import net.minecraft.util.math.Box
3837
import net.minecraft.util.math.Direction
3938
import net.minecraft.util.math.Vec3d
40-
import net.minecraft.util.shape.VoxelShape
4139
import kotlin.math.pow
42-
import kotlin.time.measureTime
4340

4441
object BuildSimulator {
4542
fun Blueprint.simulate(eye: Vec3d) =

common/src/main/kotlin/com/lambda/module/modules/client/TaskFlow.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.lambda.config.groups.RotationSettings
66
import com.lambda.module.Module
77
import com.lambda.module.tag.ModuleTag
88
import com.lambda.util.BlockUtils.allSigns
9-
import net.minecraft.block.Block
9+
import com.lambda.util.item.ItemUtils
1010

1111
object TaskFlow : Module(
1212
name = "TaskFlow",
@@ -30,6 +30,6 @@ object TaskFlow : Module(
3030
val taskCooldown by setting("Task Cooldown", 0, 0..10000, 10, unit = " ms") {
3131
page == Page.TASKS
3232
}
33-
// val disposables by setting("Disposables", ItemUtils.defaultDisposables)
34-
val ignoredBlocks = mutableSetOf<Block>().apply { addAll(allSigns) }
33+
val disposables by setting("Disposables", ItemUtils.defaultDisposables)
34+
val ignoredBlocks by setting("Ignored Blocks", allSigns)
3535
}

common/src/main/kotlin/com/lambda/task/Task.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import com.lambda.module.modules.client.TaskFlow
1111
import com.lambda.threading.runConcurrent
1212
import com.lambda.threading.runGameScheduled
1313
import com.lambda.threading.runSafe
14-
import com.lambda.util.BaritoneUtils
1514
import com.lambda.util.Communication.logError
1615
import com.lambda.util.Communication.warn
17-
import com.lambda.util.DynamicReflectionSerializer.dynamicString
1816
import com.lambda.util.Nameable
1917
import com.lambda.util.text.buildText
2018
import com.lambda.util.text.color

common/src/main/kotlin/com/lambda/task/tasks/BreakBlock.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.lambda.task.tasks.GoalTask.Companion.moveToGoalUntil
1919
import com.lambda.util.BaritoneUtils
2020
import com.lambda.util.BlockUtils.blockState
2121
import com.lambda.util.BlockUtils.item
22+
import com.lambda.util.item.ItemUtils.block
2223
import com.lambda.util.item.ItemUtils.defaultDisposables
2324
import com.lambda.util.player.SlotUtils.clickSlot
2425
import com.lambda.util.player.SlotUtils.hotbarAndStorage
@@ -83,7 +84,7 @@ class BreakBlock @Ta5kBuilder constructor(
8384

8485
if (player.hotbarAndStorage.none { it.isEmpty }) {
8586
player.currentScreenHandler.inventorySlots.firstOrNull {
86-
it.stack.item in defaultDisposables
87+
it.stack.item.block in TaskFlow.disposables
8788
}?.let {
8889
clickSlot(it.index, 1, SlotActionType.THROW)
8990
}

common/src/main/kotlin/com/lambda/task/tasks/InventoryTask.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import com.lambda.context.SafeContext
44
import com.lambda.event.events.TickEvent
55
import com.lambda.event.listener.SafeListener.Companion.listener
66
import com.lambda.interaction.material.StackSelection
7+
import com.lambda.module.modules.client.TaskFlow
78
import com.lambda.task.Task
9+
import com.lambda.util.item.ItemUtils.block
810
import com.lambda.util.item.ItemUtils.defaultDisposables
911
import com.lambda.util.player.SlotUtils.clickSlot
1012
import com.lambda.util.primitives.extension.containerSlots
@@ -41,7 +43,7 @@ class InventoryTask<H : ScreenHandler>(
4143
// ToDo: SWAP triangle
4244
val handler = player.currentScreenHandler
4345
handler.inventorySlots.firstOrNull {
44-
it.stack.item in defaultDisposables || it.stack.isEmpty
46+
it.stack.item.block in TaskFlow.disposables || it.stack.isEmpty
4547
}?.let { emptySlot ->
4648
clickSlot(emptySlot.id, 0, SlotActionType.SWAP)
4749
clickSlot(from.id, 0, SlotActionType.SWAP)

common/src/main/kotlin/com/lambda/util/Communication.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ object Communication {
3636
fun Any.warn(message: Text, source: Text = Text.empty()) = log(message, LogLevel.WARN, textSource = source)
3737
fun Any.logError(message: String, source: String = "") = log(LogLevel.ERROR.text(message), LogLevel.ERROR, source)
3838
fun Any.logError(message: Text, source: Text = Text.empty()) = log(message, LogLevel.ERROR, textSource = source)
39+
fun Any.logError(message: String, throwable: Throwable) = logError(message, throwable.message ?: "")
3940

4041
fun Any.toast(message: String, logLevel: LogLevel = LogLevel.INFO) {
4142
toast(logLevel.text(message), logLevel)

common/src/main/kotlin/com/lambda/util/item/ItemUtils.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lambda.util.item
22

33
import net.minecraft.block.Block
4+
import net.minecraft.block.Blocks
45
import net.minecraft.item.Item
56
import net.minecraft.item.Items
67

@@ -84,19 +85,19 @@ object ItemUtils {
8485
)
8586

8687
val defaultDisposables = setOf(
87-
Items.DIRT,
88-
Items.COBBLESTONE,
89-
Items.GRANITE,
90-
Items.DIORITE,
91-
Items.ANDESITE,
92-
Items.SANDSTONE,
93-
Items.RED_SANDSTONE,
94-
Items.NETHERRACK,
95-
Items.END_STONE,
96-
Items.STONE,
97-
Items.BASALT,
98-
Items.BLACKSTONE,
99-
Items.COBBLED_DEEPSLATE
88+
Blocks.DIRT,
89+
Blocks.COBBLESTONE,
90+
Blocks.GRANITE,
91+
Blocks.DIORITE,
92+
Blocks.ANDESITE,
93+
Blocks.SANDSTONE,
94+
Blocks.RED_SANDSTONE,
95+
Blocks.NETHERRACK,
96+
Blocks.END_STONE,
97+
Blocks.STONE,
98+
Blocks.BASALT,
99+
Blocks.BLACKSTONE,
100+
Blocks.COBBLED_DEEPSLATE
100101
)
101102

102103
val Item.block: Block get() = Block.getBlockFromItem(this)

0 commit comments

Comments
 (0)