Skip to content

Commit 55a92ca

Browse files
committed
correctly light and put out candles
1 parent 22ecdb9 commit 55a92ca

4 files changed

Lines changed: 61 additions & 17 deletions

File tree

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/InteractSim.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import com.lambda.interaction.construction.simulation.result.BuildResult
2727
import com.lambda.interaction.construction.simulation.result.results.GenericResult
2828
import com.lambda.interaction.construction.simulation.result.results.InteractResult
2929
import com.lambda.interaction.construction.verify.TargetState
30+
import com.lambda.interaction.handlers.ContainerHandler.findContainersWithMaterial
3031
import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
3132
import com.lambda.interaction.managers.rotating.Rotation
3233
import com.lambda.interaction.managers.rotating.Rotation.Companion.rotation
3334
import com.lambda.interaction.managers.rotating.RotationManager
3435
import com.lambda.interaction.material.ContainerSelection.Companion.selectContainer
3536
import com.lambda.interaction.material.StackSelection
3637
import com.lambda.interaction.material.StackSelection.Companion.select
37-
import com.lambda.interaction.handlers.ContainerHandler.findContainersWithMaterial
3838
import com.lambda.interaction.material.container.MaterialContainer
3939
import com.lambda.util.BlockUtils.blockState
4040
import com.lambda.util.EntityUtils.getPositionsWithinHitboxXZ
@@ -60,6 +60,7 @@ import net.minecraft.entity.Entity
6060
import net.minecraft.item.BlockItem
6161
import net.minecraft.item.Item
6262
import net.minecraft.item.ItemPlacementContext
63+
import net.minecraft.item.Items
6364
import net.minecraft.screen.slot.Slot
6465
import net.minecraft.state.property.Properties
6566
import net.minecraft.util.Hand
@@ -210,7 +211,7 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
210211
supervisorScope.cancel()
211212
return null
212213
}
213-
val stackSelection = item?.select()
214+
val stackSelection = item?.select()?.apply { if (item == Items.AIR) count = 0 }
214215
?: StackSelection.selectStack(0, sorter = compareByDescending { it.inventoryIndex == player.inventory.selectedSlot })
215216
val containerSelection = selectContainer { ofAnyType(MaterialContainer.Rank.Hotbar) }
216217
val container = stackSelection.findContainersWithMaterial(containerSelection).firstOrNull() ?: run {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2026 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.interaction.construction.simulation.processing.preprocessors.property.placement.post
19+
20+
import com.lambda.context.SafeContext
21+
import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator
22+
import com.lambda.interaction.construction.simulation.processing.PropertyPostProcessor
23+
import net.minecraft.block.BlockState
24+
import net.minecraft.item.Items
25+
import net.minecraft.state.property.Properties
26+
import net.minecraft.util.math.BlockPos
27+
28+
@Suppress("unused")
29+
object CandlePostProcessor : PropertyPostProcessor {
30+
override fun acceptsState(state: BlockState, targetState: BlockState) =
31+
Properties.CANDLES in targetState && Properties.LIT in targetState &&
32+
state.block == targetState.block &&
33+
state.get(Properties.CANDLES) == targetState.get(Properties.CANDLES) &&
34+
state.get(Properties.LIT) != targetState.get(Properties.LIT)
35+
36+
context(safeContext: SafeContext)
37+
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) {
38+
setPlacing(false)
39+
setSneak(false)
40+
if (state.get(Properties.LIT)) setItem(Items.AIR)
41+
else setItem(Items.FLINT_AND_STEEL)
42+
}
43+
}

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/post/StandardInteractPostProcessor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ object StandardInteractPostProcessor : PropertyPostProcessor {
3737
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) {
3838
setItem(null)
3939
setPlacing(false)
40+
setSneak(false)
4041
}
4142

4243
fun BlockState.canBeModifiedByHand() =

src/main/kotlin/com/lambda/util/PlayerBuildLayerUtils.kt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ object PlayerBuildLayerUtils {
3232

3333
if (flattenMode == FlattenMode.Staircase) {
3434
val up = pos.up()
35-
if ((blockState(up).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up) == !baritoneSelectionInverted)))
36-
|| (blockState(up.east()).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up.east()) == !baritoneSelectionInverted)))
37-
|| (blockState(up.south()).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up.south()) == !baritoneSelectionInverted)))
38-
|| (blockState(up.west()).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up.west()) == !baritoneSelectionInverted)))
39-
|| (blockState(up.north()).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up.north()) == !baritoneSelectionInverted)))
40-
) { return false }
35+
if ((blockState(up).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up) == !baritoneSelectionInverted))) ||
36+
(blockState(up.east()).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up.east()) == !baritoneSelectionInverted))) ||
37+
(blockState(up.south()).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up.south()) == !baritoneSelectionInverted))) ||
38+
(blockState(up.west()).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up.west()) == !baritoneSelectionInverted))) ||
39+
(blockState(up.north()).isNotEmpty && (!baritoneSelection || (isInBaritoneSelection(up.north()) == !baritoneSelectionInverted)))
40+
) { return false }
4141
}
4242

4343
val flattenY = player.y.ceilToInt()
@@ -46,8 +46,7 @@ object PlayerBuildLayerUtils {
4646
if (sneakLowersFlatten && player.isSneaking) flattenY - 1
4747
else flattenY
4848

49-
if (!flattenMode.isSmart && pos.y < flattenLevel)
50-
return false
49+
if (!flattenMode.isSmart && pos.y < flattenLevel) return false
5150

5251
if (pos == player.supportingBlockPos) return false
5352

@@ -60,19 +59,19 @@ object PlayerBuildLayerUtils {
6059

6160
val zeroedPos = pos.add(-playerPos.x, -flattenY, -playerPos.z)
6261

63-
return (zeroedPos.x < 0 && smartFlattenDir == Direction.EAST)
64-
|| (zeroedPos.z < 0 && smartFlattenDir == Direction.SOUTH)
65-
|| (zeroedPos.x > 0 && smartFlattenDir == Direction.WEST)
66-
|| (zeroedPos.z > 0 && smartFlattenDir == Direction.NORTH)
62+
return (zeroedPos.x < 0 && smartFlattenDir == Direction.EAST) ||
63+
(zeroedPos.z < 0 && smartFlattenDir == Direction.SOUTH) ||
64+
(zeroedPos.x > 0 && smartFlattenDir == Direction.WEST) ||
65+
(zeroedPos.z > 0 && smartFlattenDir == Direction.NORTH)
6766
}
6867

6968
fun isInBaritoneSelection(pos: BlockPos) =
7069
BaritoneHandler.primary?.selectionManager?.selections?.any {
7170
val min = it.min()
7271
val max = it.max()
73-
pos.x >= min.x && pos.x <= max.x
74-
&& pos.y >= min.y && pos.y <= max.y
75-
&& pos.z >= min.z && pos.z <= max.z
72+
pos.x >= min.x && pos.x <= max.x &&
73+
pos.y >= min.y && pos.y <= max.y &&
74+
pos.z >= min.z && pos.z <= max.z
7675
} ?: false
7776

7877
fun inSchematic(pos: BlockPos): Boolean {

0 commit comments

Comments
 (0)