Skip to content

Commit e65a2d1

Browse files
committed
toggleable break and place options in build config
1 parent bed5780 commit e65a2d1

File tree

8 files changed

+52
-41
lines changed

8 files changed

+52
-41
lines changed

src/main/kotlin/com/lambda/config/groups/BuildConfig.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import com.lambda.util.Describable
2323
import com.lambda.util.NamedEnum
2424

2525
interface BuildConfig : ISettingGroup {
26-
// General
26+
val breakBlocks: Boolean
27+
val interactBlocks: Boolean
28+
2729
val pathing: Boolean
2830
val stayInRange: Boolean
2931
val collectDrops: Boolean

src/main/kotlin/com/lambda/config/groups/BuildSettings.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class BuildSettings(
3333
Scan("Scan")
3434
}
3535

36-
// General
36+
override val breakBlocks by c.setting("Break", true, "Break blocks")
37+
override val interactBlocks by c.setting("Place / Interact", true, "Interact blocks")
38+
3739
override val pathing by c.setting("Pathing", true, "Path to blocks").group(baseGroup, Group.General).index()
3840
override val stayInRange by c.setting("Stay In Range", true, "Stay in range of blocks").group(baseGroup, Group.General).index()
3941
override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks").group(baseGroup, Group.General).index()

src/main/kotlin/com/lambda/interaction/construction/simulation/SimInfo.kt

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package com.lambda.interaction.construction.simulation
1919

2020
import com.lambda.context.Automated
2121
import com.lambda.context.AutomatedSafeContext
22-
import com.lambda.interaction.construction.simulation.processing.PreProcessingData
23-
import com.lambda.interaction.construction.simulation.processing.ProcessorRegistry.getProcessingInfo
24-
import com.lambda.interaction.construction.simulation.result.BuildResult
2522
import com.lambda.interaction.construction.simulation.checks.BasicChecker.hasBasicRequirements
2623
import com.lambda.interaction.construction.simulation.checks.BreakSim.Companion.simBreak
2724
import com.lambda.interaction.construction.simulation.checks.InteractSim.Companion.simInteraction
25+
import com.lambda.interaction.construction.simulation.processing.PreProcessingData
26+
import com.lambda.interaction.construction.simulation.processing.ProcessorRegistry.getProcessingInfo
27+
import com.lambda.interaction.construction.simulation.result.BuildResult
2828
import com.lambda.interaction.construction.verify.TargetState
2929
import com.lambda.util.BlockUtils.matches
3030
import net.minecraft.block.BlockState
@@ -68,7 +68,7 @@ interface SimInfo : Automated {
6868
pov,
6969
Stack(),
7070
concurrentResults
71-
).takeIf { it.hasBasicRequirements() }?.sim()
71+
)?.takeIf { it.hasBasicRequirements() }?.sim()
7272

7373
/**
7474
* Creates a new [SimInfo] using the current [SimInfo]'s [dependencyStack] and [concurrentResults],
@@ -89,7 +89,7 @@ interface SimInfo : Automated {
8989
pov,
9090
Stack<Sim<*>>().apply { addAll(dependencyStack) },
9191
concurrentResults
92-
).takeIf { it.hasBasicRequirements() }?.sim()
92+
)?.takeIf { it.hasBasicRequirements() }?.sim()
9393

9494
@SimDsl
9595
private fun AutomatedSafeContext.getTypedInfo(
@@ -99,31 +99,29 @@ interface SimInfo : Automated {
9999
pov: Vec3d,
100100
dependencyStack: Stack<Sim<*>>,
101101
concurrentResults: MutableSet<BuildResult>
102-
): SimInfo {
103-
if (!targetState.isEmpty()) {
104-
getProcessingInfo(state, targetState, pos)?.let { preProcessing ->
105-
return object : InteractSimInfo, Automated by this {
106-
override val pos = pos
107-
override val state = state
108-
override val targetState = targetState
109-
override val pov = pov
110-
override val dependencyStack = dependencyStack
111-
override val concurrentResults = concurrentResults
112-
override val preProcessing = preProcessing
113-
override val expectedState = preProcessing.info.expectedState
114-
override val item = preProcessing.info.item
115-
override val placing = preProcessing.info.placing
116-
117-
context(_: AutomatedSafeContext, _: Sim<*>)
118-
override suspend fun sim() = simInteraction()
102+
): SimInfo? =
103+
if (!targetState.isEmpty()) {
104+
getProcessingInfo(state, targetState, pos)?.let { preProcessing ->
105+
object : InteractSimInfo, Automated by this {
106+
override val pos = pos
107+
override val state = state
108+
override val targetState = targetState
109+
override val pov = pov
110+
override val dependencyStack = dependencyStack
111+
override val concurrentResults = concurrentResults
112+
override val preProcessing = preProcessing
113+
override val expectedState = preProcessing.info.expectedState
114+
override val item = preProcessing.info.item
115+
override val placing = preProcessing.info.placing
119116

120-
override fun AutomatedSafeContext.matchesTarget(state: BlockState, completely: Boolean) =
121-
expectedState.matches(state, if (!completely) preProcessing.info.ignore else emptySet())
122-
}
123-
}
124-
}
117+
context(_: AutomatedSafeContext, _: Sim<*>)
118+
override suspend fun sim() = simInteraction()
125119

126-
return object : BreakSimInfo, Automated by this {
120+
override fun AutomatedSafeContext.matchesTarget(state: BlockState, completely: Boolean) =
121+
expectedState.matches(state, if (!completely) preProcessing.info.ignore else emptySet())
122+
}
123+
}
124+
} else object : BreakSimInfo, Automated by this {
127125
override val pos = pos
128126
override val state = state
129127
override val targetState = targetState
@@ -134,7 +132,6 @@ interface SimInfo : Automated {
134132
context(_: AutomatedSafeContext, _: Sim<*>)
135133
override suspend fun sim() = simBreak()
136134
}
137-
}
138135
}
139136
}
140137

src/main/kotlin/com/lambda/interaction/managers/breaking/BreakManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ object BreakManager : Manager<BreakRequest>(
296296
* @see processRequest
297297
*/
298298
override fun AutomatedSafeContext.handleRequest(request: BreakRequest) {
299-
if (activeRequest != null || request.contexts.isEmpty()) return
299+
if (!request.buildConfig.breakBlocks || activeRequest != null || request.contexts.isEmpty()) return
300300
if (InteractManager.activeThisTick) return
301301

302302
activeRequest = request

src/main/kotlin/com/lambda/interaction/managers/interacting/InteractManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ object InteractManager : Manager<InteractRequest>(
113113
* @see processRequest
114114
*/
115115
override fun AutomatedSafeContext.handleRequest(request: InteractRequest) {
116-
if (activeRequest != null || request.contexts.isEmpty()) return
116+
if (!request.buildConfig.interactBlocks || activeRequest != null || request.contexts.isEmpty()) return
117117
if (BreakManager.activeThisTick) return
118118

119119
activeRequest = request

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ object FastBreak : Module(
4848
::maxBuildDependencies,
4949
::collectDrops,
5050
::blockReach,
51-
::entityReach
51+
::entityReach,
52+
::breakBlocks,
53+
::interactBlocks
5254
)
5355
::maxBuildDependencies.edit { defaultValue(0) }
5456
editTyped(

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ object PacketMine : Module(
107107
::spleefEntities,
108108
::maxBuildDependencies,
109109
::collectDrops,
110-
::entityReach
110+
::entityReach,
111+
::breakBlocks,
112+
::interactBlocks
111113
)
112114
::maxBuildDependencies.edit { defaultValue(0) }
113115
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,23 @@ class BuildTask private constructor(
125125
.filterIsInstance<Drawable>()
126126
.plus(pendingInteractions.toList())
127127

128-
val resultsNotBlocked = results
129-
.filter { result -> pendingInteractions.none { it.blockPos == result.pos } }
128+
val viableResults = results
129+
.filter { result ->
130+
val finalResult = (result as? Dependent)?.lastDependency ?: result
131+
pendingInteractions.none { it.blockPos == result.pos } &&
132+
when (finalResult) {
133+
is BreakResult -> buildConfig.breakBlocks
134+
else -> buildConfig.interactBlocks
135+
}
136+
}
130137
.sorted()
131138

132-
val bestResult = resultsNotBlocked.firstOrNull() ?: return
133-
handleResult(bestResult, resultsNotBlocked)
139+
val bestResult = viableResults.firstOrNull() ?: return
140+
handleResult(bestResult, viableResults)
134141
}
135142

136143
private fun SafeContext.handleResult(result: BuildResult, allResults: List<BuildResult>) {
137-
if (result !is Dependent && result !is Contextual && pendingInteractions.isNotEmpty())
138-
return
144+
if (result !is Dependent && result !is Contextual && pendingInteractions.isNotEmpty()) return
139145

140146
when (result) {
141147
is PreSimResult.Done,

0 commit comments

Comments
 (0)