@@ -28,7 +28,6 @@ import com.lambda.interaction.construction.simulation.Sim
2828import com.lambda.interaction.construction.simulation.SimDsl
2929import com.lambda.interaction.construction.simulation.SimInfo
3030import com.lambda.interaction.construction.simulation.checks.BreakSim.Companion.simBreak
31- import com.lambda.interaction.construction.simulation.checks.PlaceSim.RotatePlaceTest.Companion.rotatePlaceTest
3231import com.lambda.interaction.construction.verify.TargetState
3332import com.lambda.interaction.material.ContainerSelection.Companion.selectContainer
3433import com.lambda.interaction.material.StackSelection.Companion.select
@@ -64,9 +63,11 @@ import net.minecraft.entity.Entity
6463import net.minecraft.item.BlockItem
6564import net.minecraft.item.ItemPlacementContext
6665import net.minecraft.item.ItemStack
66+ import net.minecraft.state.property.Properties
6767import net.minecraft.util.Hand
6868import net.minecraft.util.math.BlockPos
6969import net.minecraft.util.math.Direction
70+ import net.minecraft.util.math.RotationPropertyHelper
7071import net.minecraft.util.shape.VoxelShapes
7172
7273class PlaceSim private constructor(simInfo : ISimInfo )
@@ -93,8 +94,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
9394 launch {
9495 val neighborPos = pos.offset(side)
9596 val neighborSide = side.opposite
96- if (! placeConfig.airPlace.isEnabled)
97- testBlock(neighborPos, neighborSide, this @supervisorScope)
97+ testBlock(neighborPos, neighborSide, this @supervisorScope)
9898 testBlock(pos, side, this @supervisorScope)
9999 }
100100 }
@@ -180,9 +180,9 @@ class PlaceSim private constructor(simInfo: ISimInfo)
180180
181181 val rotatePlaceTest = simRotatePlace(fakePlayer, checkedHit, context) ? : return
182182
183- val rotationRequest = if (placeConfig.axisRotate) {
183+ val rotationRequest = if (placeConfig.axisRotate && (targetState as ? TargetState . State )?.blockState?.contains( Properties . ROTATION ) != true )
184184 lookInDirection(PlaceDirection .fromRotation(rotatePlaceTest.rotation))
185- } else lookAt(rotatePlaceTest.rotation, 0.001 )
185+ else lookAt(rotatePlaceTest.rotation, 0.001 )
186186
187187 val swapStack = getSwapStack() ? : return
188188 if (! swapStack.item.isEnabled(world.enabledFeatures)) {
@@ -215,39 +215,53 @@ class PlaceSim private constructor(simInfo: ISimInfo)
215215 context : ItemPlacementContext
216216 ): RotatePlaceTest ? {
217217 fakePlayer.rotation = RotationManager .serverRotation
218- val currentDirIsValid = testPlaceState(context).testResult == PlaceTestResult . Success
218+ val currentDirIsValid = testPlaceState(context) != null
219219
220220 if (! placeConfig.axisRotate) {
221221 fakePlayer.rotation = checkedHit.targetRotation
222- return rotatePlaceTest( testPlaceState(context), currentDirIsValid, fakePlayer.rotation)
222+ return testPlaceState(context)?. let { RotatePlaceTest (it , currentDirIsValid, fakePlayer.rotation) }
223223 }
224224
225225 fakePlayer.rotation = player.rotation
226- testPlaceState(context).takeIf { it.testResult == PlaceTestResult .Success }?.let { playerRotTest ->
227- return rotatePlaceTest(playerRotTest, currentDirIsValid, fakePlayer.rotation)
226+ testPlaceState(context)?.let { playerRotTest ->
227+ return RotatePlaceTest (playerRotTest, currentDirIsValid, fakePlayer.rotation)
228+ }
229+
230+ (targetState as ? TargetState .State )?.blockState?.let { targetState ->
231+ if (Properties .ROTATION !in targetState) return @let
232+ val rotation = targetState.get(Properties .ROTATION )
233+ fakePlayer.yaw = RotationPropertyHelper .toDegrees(rotation)
234+ listOf (rotation, rotation + 8 ).forEach { yaw ->
235+ listOf (90f , 0f , - 90f ).forEach { pitch ->
236+ fakePlayer.rotation = Rotation (RotationPropertyHelper .toDegrees(yaw), pitch)
237+ testPlaceState(context)?.let { axisRotateTest ->
238+ return RotatePlaceTest (axisRotateTest, currentDirIsValid, fakePlayer.rotation)
239+ }
240+ }
241+ }
228242 }
229243
230244 PlaceDirection .entries.asReversed().forEach direction@{ direction ->
231245 fakePlayer.rotation = direction.rotation
232- testPlaceState(context). takeIf { it.testResult == PlaceTestResult . Success } ?.let { axisRotateTest ->
233- return rotatePlaceTest (axisRotateTest, currentDirIsValid, fakePlayer.rotation)
246+ testPlaceState(context)?.let { axisRotateTest ->
247+ return RotatePlaceTest (axisRotateTest, currentDirIsValid, fakePlayer.rotation)
234248 }
235249 }
236250
237251 return null
238252 }
239253
240- private suspend fun AutomatedSafeContext.testPlaceState (context : ItemPlacementContext ): PlaceTest {
254+ private suspend fun AutomatedSafeContext.testPlaceState (context : ItemPlacementContext ): BlockState ? {
241255 val resultState = context.stack.blockItem.getPlacementState(context)
242256 ? : run {
243257 handleEntityBlockage(context)
244- return PlaceTest (state, PlaceTestResult . BlockedByEntity )
258+ return null
245259 }
246260
247261 return if (! matchesTarget(resultState, false )) {
248262 result(PlaceResult .NoIntegrity (pos, resultState, context, (targetState as ? TargetState .State )?.blockState))
249- PlaceTest (resultState, PlaceTestResult . NoIntegrity )
250- } else PlaceTest ( resultState, PlaceTestResult . Success )
263+ null
264+ } else resultState
251265 }
252266
253267 private suspend fun AutomatedSafeContext.handleEntityBlockage (context : ItemPlacementContext ): List <Entity > {
@@ -286,26 +300,5 @@ class PlaceSim private constructor(simInfo: ISimInfo)
286300 return collidingEntities
287301 }
288302
289- private class RotatePlaceTest private constructor(
290- val resultState : BlockState ,
291- val currentDirIsValid : Boolean ,
292- val rotation : Rotation
293- ) {
294- companion object {
295- fun rotatePlaceTest (
296- placeTest : PlaceTest ,
297- currentDirIsValid : Boolean ,
298- rotation : Rotation
299- ): RotatePlaceTest ? {
300- return if (placeTest.testResult != PlaceTestResult .Success ) null
301- else RotatePlaceTest (placeTest.resultState, currentDirIsValid, rotation)
302- }
303- }
304- }
305- private data class PlaceTest (val resultState : BlockState , val testResult : PlaceTestResult )
306- private enum class PlaceTestResult {
307- Success ,
308- BlockedByEntity ,
309- NoIntegrity
310- }
303+ private class RotatePlaceTest (val resultState : BlockState , val currentDirIsValid : Boolean , val rotation : Rotation )
311304}
0 commit comments