Skip to content

Commit bcb3790

Browse files
authored
check for if a position is within the bounds of a schematic before printing (#250)
1 parent a78e86f commit bcb3790

File tree

1 file changed

+10
-5
lines changed
  • src/main/kotlin/com/lambda/module/modules/player

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
package com.lambda.module.modules.player
1919

2020
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
21-
import com.lambda.config.applyEdits
2221
import com.lambda.interaction.construction.blueprint.TickingBlueprint
2322
import com.lambda.interaction.construction.verify.TargetState
24-
import com.lambda.interaction.managers.interacting.InteractConfig
2523
import com.lambda.module.Module
2624
import com.lambda.module.tag.ModuleTag
2725
import com.lambda.task.RootTask.run
@@ -38,8 +36,8 @@ object Printer : Module(
3836
description = "Automatically prints schematics",
3937
tag = ModuleTag.PLAYER
4038
) {
41-
private val range by setting("Range", 5, 1..7, 1)
42-
private val air by setting("Air", false)
39+
private val range by setting("Range", 5, 1..7, 1, description = "The range around the player to check for blocks to print")
40+
private val air by setting("Air", false, description = "Consider breaking blocks in the world that are air in the schematic.\nNote: Breaking can also be disabled in the Automation Config.")
4341

4442
private var buildTask: Task<*>? = null
4543

@@ -57,7 +55,7 @@ object Printer : Module(
5755
BlockPos.iterateOutwards(player.blockPos, range, range, range)
5856
.map { it.blockPos }
5957
.asSequence()
60-
.filter { DataManager.getRenderLayerRange().isPositionWithinRange(it) }
58+
.filter { DataManager.getRenderLayerRange().isPositionWithinRange(it) && inSchematic(it) }
6159
.associateWith { TargetState.State(schematicWorld.getBlockState(it)) }
6260
.filter { air || !it.value.blockState.isAir }
6361
}.build(finishOnDone = false).run()
@@ -66,6 +64,13 @@ object Printer : Module(
6664
onDisable { buildTask?.cancel(); buildTask = null }
6765
}
6866

67+
private fun inSchematic(pos: BlockPos): Boolean {
68+
val placementManager = DataManager.getSchematicPlacementManager()
69+
return placementManager?.getAllPlacementsTouchingChunk(pos)?.any {
70+
it.placement.isEnabled && it.bb.containsPos(pos)
71+
} ?: false
72+
}
73+
6974
private fun litematicaAvailable(): Boolean = runCatching {
7075
Class.forName("fi.dy.masa.litematica.Litematica")
7176
true

0 commit comments

Comments
 (0)