Skip to content

Commit fcc8860

Browse files
committed
allow use of the rest of the hotbar for placing
1 parent 140a17f commit fcc8860

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import java.awt.Color
3535
data class PlaceContext(
3636
override val result: BlockHitResult,
3737
override val rotation: RotationRequest,
38-
override val hotbarIndex: Int,
38+
override var hotbarIndex: Int,
3939
override val blockPos: BlockPos,
4040
override val cachedState: BlockState,
4141
override val expectedState: BlockState,

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import com.lambda.util.BlockUtils.isEmpty
6262
import com.lambda.util.BlockUtils.isNotEmpty
6363
import com.lambda.util.BlockUtils.vecOf
6464
import com.lambda.util.Communication.warn
65-
import com.lambda.util.item.ItemStackUtils.equal
6665
import com.lambda.util.math.distSq
6766
import com.lambda.util.player.SlotUtils.hotbar
6867
import com.lambda.util.player.copyPlayer
@@ -545,17 +544,19 @@ object BuildSimulator {
545544
currentDirIsValid
546545
)
547546

548-
val currentHandStack = player.getStackInHand(Hand.MAIN_HAND)
549-
if (targetState is TargetState.Stack && !targetState.itemStack.equal(currentHandStack)) {
550-
acc.add(BuildResult.WrongStack(pos, placeContext, targetState.itemStack, inventory))
551-
return@forEach
547+
val selection = optimalStack.item.select()
548+
val hotbarSelection = selectContainer { ofAnyType(MaterialContainer.Rank.HOTBAR) }
549+
val containerStacks = selection.containerWithMaterial(inventory, hotbarSelection).firstOrNull()?.stacks ?: run {
550+
acc.add(BuildResult.WrongItemSelection(pos, placeContext, optimalStack.item.select(), player.mainHandStack, inventory))
551+
return acc
552552
}
553-
554-
if (optimalStack.item != currentHandStack.item) {
555-
acc.add(BuildResult.WrongItemSelection(pos, placeContext, optimalStack.item.select(), currentHandStack, inventory))
556-
return@forEach
553+
val stack = selection.filterStacks(containerStacks).run {
554+
firstOrNull { player.inventory.getSlotWithStack(it) == player.inventory.selectedSlot }
555+
?: first()
557556
}
558557

558+
placeContext.hotbarIndex = player.inventory.getSlotWithStack(stack)
559+
559560
acc.add(PlaceResult.Place(pos, placeContext))
560561
}
561562
}
@@ -716,7 +717,7 @@ object BuildSimulator {
716717
)
717718

718719
val silentSwapSelection = selectContainer {
719-
matches(stackSelection) and ofAnyType(MaterialContainer.Rank.HOTBAR)
720+
ofAnyType(MaterialContainer.Rank.HOTBAR)
720721
}
721722

722723
val swapCandidates = stackSelection.containerWithMaterial(inventory, silentSwapSelection)

0 commit comments

Comments
 (0)