@@ -61,6 +61,7 @@ import net.minecraft.block.ShapeContext
6161import net.minecraft.block.pattern.CachedBlockPosition
6262import net.minecraft.client.network.ClientPlayerEntity
6363import net.minecraft.entity.Entity
64+ import net.minecraft.item.BlockItem
6465import net.minecraft.item.ItemPlacementContext
6566import net.minecraft.item.ItemStack
6667import net.minecraft.util.Hand
@@ -122,14 +123,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
122123
123124 val validHits = scanShape(pov, shape, pos, setOf (side), preProcessing) ? : return
124125
125- val swapStack = getSwapStack() ? : return
126- if (! swapStack.item.isEnabled(world.enabledFeatures)) {
127- result(PlaceResult .BlockFeatureDisabled (pos, swapStack))
128- supervisorScope.cancel()
129- return
130- }
131-
132- selectHitPos(validHits, fakePlayer, swapStack)
126+ selectHitPos(validHits, fakePlayer, targetState.getStack(pos).blockItem, supervisorScope)
133127 }
134128
135129 private fun AutomatedSafeContext.getSwapStack (): ItemStack ? {
@@ -149,17 +143,18 @@ class PlaceSim private constructor(simInfo: ISimInfo)
149143 private suspend fun AutomatedSafeContext.selectHitPos (
150144 validHits : Collection <CheckedHit >,
151145 fakePlayer : ClientPlayerEntity ,
152- swapStack : ItemStack
146+ item : BlockItem ,
147+ supervisorScope : CoroutineScope
153148 ) {
154149 buildConfig.pointSelection.select(validHits)?.let { checkedHit ->
155150 val hitResult = checkedHit.hit.blockResult ? : return
156151
157- val context = swapStack.blockItem .getPlacementContext(
152+ val context = item .getPlacementContext(
158153 ItemPlacementContext (
159154 world,
160155 fakePlayer,
161156 Hand .MAIN_HAND ,
162- swapStack ,
157+ item.defaultStack ,
163158 hitResult,
164159 )
165160 ) ? : run {
@@ -173,7 +168,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
173168 }
174169
175170 val cachePos = CachedBlockPosition (context.world, context.blockPos, false )
176- if (! player.abilities.allowModifyWorld && ! swapStack .canPlaceOn(cachePos)) {
171+ if (! player.abilities.allowModifyWorld && ! item.defaultStack .canPlaceOn(cachePos)) {
177172 result(PlaceResult .IllegalUsage (pos))
178173 return
179174 }
@@ -189,6 +184,13 @@ class PlaceSim private constructor(simInfo: ISimInfo)
189184 lookInDirection(PlaceDirection .fromRotation(rotatePlaceTest.rotation))
190185 } else lookAt(rotatePlaceTest.rotation, 0.001 )
191186
187+ val swapStack = getSwapStack() ? : return
188+ if (! swapStack.item.isEnabled(world.enabledFeatures)) {
189+ result(PlaceResult .BlockFeatureDisabled (pos, swapStack))
190+ supervisorScope.cancel()
191+ return
192+ }
193+
192194 val placeContext = PlaceContext (
193195 hitResult,
194196 RotationRequest (rotationRequest, this @PlaceSim),
0 commit comments