Skip to content

Commit 7f7040c

Browse files
committed
Revert "cleaner configs idea"
This reverts commit 5de8935.
1 parent 5de8935 commit 7f7040c

File tree

23 files changed

+288
-310
lines changed

23 files changed

+288
-310
lines changed

common/src/main/kotlin/com/lambda/command/commands/BuildCommand.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import com.lambda.brigadier.argument.value
2525
import com.lambda.brigadier.executeWithResult
2626
import com.lambda.brigadier.required
2727
import com.lambda.command.LambdaCommand
28-
import com.lambda.context.DefaultConfigs
2928
import com.lambda.interaction.construction.StructureRegistry
3029
import com.lambda.interaction.construction.blueprint.Blueprint.Companion.toStructure
3130
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
@@ -62,14 +61,11 @@ object BuildCommand : LambdaCommand(
6261
.loadStructureByRelativePath(Path.of(pathString))
6362
.let { template ->
6463
info("Building structure $pathString with dimensions ${template.size.toShortString()} created by ${template.author}")
65-
DefaultConfigs.run {
66-
lastBuildTask = build(
67-
template
68-
.toStructure()
69-
.move(player.blockPos)
70-
.toBlueprint()
71-
).run()
72-
}
64+
lastBuildTask = template.toStructure()
65+
.move(player.blockPos)
66+
.toBlueprint()
67+
.build()
68+
.run()
7369

7470
return@executeWithResult success()
7571
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.context
19+
20+
import net.minecraft.client.MinecraftClient
21+
import net.minecraft.client.network.ClientPlayNetworkHandler
22+
import net.minecraft.client.network.ClientPlayerEntity
23+
import net.minecraft.client.network.ClientPlayerInteractionManager
24+
import net.minecraft.client.world.ClientWorld
25+
26+
/**
27+
* Representing an abstract context in the [MinecraftClient].
28+
*
29+
* @property mc The Minecraft client instance.
30+
* @property world The world in which the player is currently located, or `null` if the world is not available.
31+
* @property player The player entity, or `null` if the player is not available.
32+
* @property interaction The interaction manager for the player, or `null` if the interaction manager is not available.
33+
* @property connection The network handler for the player, or `null` if the network handler is not available.
34+
*/
35+
abstract class AbstractContext {
36+
val mc: MinecraftClient = MinecraftClient.getInstance()
37+
abstract val world: ClientWorld?
38+
abstract val player: ClientPlayerEntity?
39+
abstract val interaction: ClientPlayerInteractionManager?
40+
abstract val connection: ClientPlayNetworkHandler?
41+
}

common/src/main/kotlin/com/lambda/context/ClientContext.kt

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,16 @@ import net.minecraft.client.world.ClientWorld
3535
*
3636
* @function toSafe Converts the `ClientContext` to a `SafeContext` if all properties are not `null`, or returns `null` otherwise.
3737
*/
38-
open class ClientContext {
39-
val mc: MinecraftClient = MinecraftClient.getInstance()
40-
val clientWorld: ClientWorld? = mc.world
41-
val clientPlayer: ClientPlayerEntity? = mc.player
42-
val clientInteraction: ClientPlayerInteractionManager? = mc.interactionManager
43-
val clientConnection: ClientPlayNetworkHandler? = mc.networkHandler
38+
open class ClientContext : AbstractContext() {
39+
final override val world: ClientWorld? = mc.world
40+
final override val player: ClientPlayerEntity? = mc.player
41+
final override val interaction: ClientPlayerInteractionManager? = mc.interactionManager
42+
final override val connection: ClientPlayNetworkHandler? = mc.networkHandler
4443

4544
fun toSafe(): SafeContext? {
46-
if (clientWorld == null || clientPlayer == null || clientInteraction == null || clientConnection == null) {
45+
if (world == null || player == null || interaction == null || connection == null) {
4746
return null
4847
}
49-
return object : SafeContext {
50-
override val mc = this@ClientContext.mc
51-
override val world: ClientWorld = clientWorld
52-
override val player: ClientPlayerEntity = clientPlayer
53-
override val interaction: ClientPlayerInteractionManager = clientInteraction
54-
override val connection: ClientPlayNetworkHandler = clientConnection
55-
}
56-
}
57-
58-
fun toSafeConfigured(configured: Configured): ConfiguredSafeContext? {
59-
return toSafe()?.let { safeContext ->
60-
ConfiguredSafeContext(safeContext, configured)
61-
}
48+
return SafeContext(world, player, interaction, connection)
6249
}
6350
}

common/src/main/kotlin/com/lambda/context/Configured.kt

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

common/src/main/kotlin/com/lambda/context/ConfiguredSafeContext.kt

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

common/src/main/kotlin/com/lambda/context/DefaultConfigs.kt

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

common/src/main/kotlin/com/lambda/context/SafeContext.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ import net.minecraft.client.world.ClientWorld
4646
* @property interaction The interaction manager for the player.
4747
* @property connection The network handler for the player.
4848
**/
49-
interface SafeContext {
50-
val mc: MinecraftClient
51-
val world: ClientWorld
52-
val player: ClientPlayerEntity
53-
val interaction: ClientPlayerInteractionManager
54-
val connection: ClientPlayNetworkHandler
55-
}
49+
open class SafeContext internal constructor(
50+
override val world: ClientWorld,
51+
override val player: ClientPlayerEntity,
52+
override val interaction: ClientPlayerInteractionManager,
53+
override val connection: ClientPlayNetworkHandler,
54+
) : AbstractContext()

common/src/main/kotlin/com/lambda/interaction/construction/result/BreakResult.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.lambda.interaction.construction.result
2020
import baritone.api.pathing.goals.GoalBlock
2121
import baritone.api.pathing.goals.GoalInverted
2222
import com.lambda.config.groups.InventoryConfig
23-
import com.lambda.context.Configured
2423
import com.lambda.context.SafeContext
2524
import com.lambda.interaction.construction.context.BreakContext
2625
import com.lambda.interaction.material.StackSelection.Companion.selectStack
@@ -97,7 +96,7 @@ sealed class BreakResult : BuildResult() {
9796

9897
override val pausesParent get() = true
9998

100-
override fun Configured.resolve() =
99+
override fun resolve() =
101100
selectStack {
102101
isItem(badItem).not()
103102
}.transfer(MainHandContainer, inventory)

common/src/main/kotlin/com/lambda/interaction/construction/result/BuildResult.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.lambda.interaction.construction.result
2020
import baritone.api.pathing.goals.GoalBlock
2121
import baritone.api.pathing.goals.GoalNear
2222
import com.lambda.config.groups.InventoryConfig
23-
import com.lambda.context.Configured
2423
import com.lambda.context.SafeContext
2524
import com.lambda.interaction.construction.context.BuildContext
2625
import com.lambda.interaction.material.StackSelection
@@ -206,7 +205,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
206205

207206
override val pausesParent get() = true
208207

209-
override fun Configured.resolve() = neededSelection
208+
override fun resolve() = neededSelection
210209
.transfer(MainHandContainer, inventory) ?: MaterialContainer.FailureTask("Couldn't find $neededSelection anywhere.")
211210

212211
override fun SafeContext.buildRenderer() {
@@ -242,7 +241,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
242241

243242
override val pausesParent get() = true
244243

245-
override fun Configured.resolve() =
244+
override fun resolve() =
246245
neededStack.select()
247246
.transfer(MainHandContainer, inventory) ?: MaterialContainer.FailureTask("Couldn't find ${neededStack.item.name.string} anywhere.")
248247

common/src/main/kotlin/com/lambda/interaction/construction/result/PlaceResult.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.lambda.interaction.construction.result
1919

2020
import baritone.api.pathing.goals.GoalBlock
2121
import baritone.api.pathing.goals.GoalInverted
22-
import com.lambda.context.Configured
2322
import com.lambda.context.SafeContext
2423
import com.lambda.interaction.construction.context.PlaceContext
2524
import com.lambda.task.tasks.BuildTask.Companion.breakBlock
@@ -110,7 +109,7 @@ sealed class PlaceResult : BuildResult() {
110109
) : Resolvable, PlaceResult() {
111110
override val rank = Rank.PLACE_CANT_REPLACE
112111

113-
override fun Configured.resolve() = breakBlock(blockPos)
112+
override fun resolve() = breakBlock(blockPos)
114113
}
115114

116115
/**

0 commit comments

Comments
 (0)