@@ -62,7 +62,6 @@ import com.lambda.util.BlockUtils.isEmpty
6262import com.lambda.util.BlockUtils.isNotEmpty
6363import com.lambda.util.BlockUtils.vecOf
6464import com.lambda.util.Communication.warn
65- import com.lambda.util.item.ItemStackUtils.equal
6665import com.lambda.util.math.distSq
6766import com.lambda.util.player.SlotUtils.hotbar
6867import 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