Skip to content

Commit aee1d80

Browse files
committed
better place rotation logic
1 parent c2dd7d7 commit aee1d80

File tree

1 file changed

+25
-27
lines changed
  • src/main/kotlin/com/lambda/interaction/construction/simulation/checks

1 file changed

+25
-27
lines changed

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.lambda.interaction.construction.simulation.ISimInfo
2828
import com.lambda.interaction.construction.simulation.SimChecker
2929
import com.lambda.interaction.construction.simulation.SimCheckerDsl
3030
import com.lambda.interaction.construction.simulation.SimInfo
31+
import com.lambda.interaction.construction.simulation.checks.PlaceChecker.RotatePlaceTest.Companion.rotatePlaceTest
3132
import com.lambda.interaction.construction.verify.TargetState
3233
import com.lambda.interaction.material.ContainerSelection.Companion.selectContainer
3334
import com.lambda.interaction.material.StackSelection.Companion.select
@@ -151,7 +152,6 @@ class PlaceChecker @SimCheckerDsl private constructor(simInfo: SimInfo)
151152

152153
// ToDo: For each hand
153154
val fakePlayer = copyPlayer(player).apply {
154-
this.rotation = RotationManager.serverRotation
155155
if (testBlockState.block::class in BlockUtils.interactionBlocks) {
156156
input.sneaking = true
157157
updatePose()
@@ -244,7 +244,6 @@ class PlaceChecker @SimCheckerDsl private constructor(simInfo: SimInfo)
244244
}
245245

246246
val rotatePlaceTest = simRotatePlace(fakePlayer, checkedHit, context) ?: return
247-
if (!rotatePlaceTest.isValid) return
248247

249248
val rotationRequest = if (placeConfig.axisRotate) {
250249
lookInDirection(PlaceDirection.fromRotation(rotatePlaceTest.rotation))
@@ -256,7 +255,7 @@ class PlaceChecker @SimCheckerDsl private constructor(simInfo: SimInfo)
256255
swapStack.inventoryIndex,
257256
pos,
258257
state,
259-
rotatePlaceTest.placeTest.resultState,
258+
rotatePlaceTest.resultState,
260259
fakePlayer.isSneaking,
261260
false,
262261
rotatePlaceTest.currentDirIsValid,
@@ -274,37 +273,23 @@ class PlaceChecker @SimCheckerDsl private constructor(simInfo: SimInfo)
274273
checkedHit: CheckedHit,
275274
context: ItemPlacementContext
276275
): RotatePlaceTest? {
277-
val currentDirIsValid = testPlaceState(context).let { currentDirTest ->
278-
if (currentDirTest.testResult != PlaceTestResult.Success) {
279-
if (!placeConfig.rotateForPlace)
280-
return RotatePlaceTest(currentDirTest, false, fakePlayer.rotation)
281-
else false
282-
} else true
283-
}
276+
fakePlayer.rotation = RotationManager.serverRotation
277+
val currentDirIsValid = testPlaceState(context).testResult == PlaceTestResult.Success
284278

285279
if (!placeConfig.axisRotate) {
286280
fakePlayer.rotation = checkedHit.targetRotation
287-
return RotatePlaceTest(testPlaceState(context), currentDirIsValid, fakePlayer.rotation)
281+
return rotatePlaceTest(testPlaceState(context), currentDirIsValid, fakePlayer.rotation)
288282
}
289283

290284
fakePlayer.rotation = player.rotation
291-
testPlaceState(context).let { playerRotTest ->
292-
if (playerRotTest.testResult == PlaceTestResult.Success)
293-
return RotatePlaceTest(playerRotTest, currentDirIsValid, fakePlayer.rotation)
285+
testPlaceState(context).takeIf { it.testResult == PlaceTestResult.Success }?.let { playerRotTest ->
286+
return rotatePlaceTest(playerRotTest, currentDirIsValid, fakePlayer.rotation)
294287
}
295288

296-
PlaceDirection.entries.asReversed().forEachIndexed direction@{ index, direction ->
289+
PlaceDirection.entries.asReversed().forEach direction@{ direction ->
297290
fakePlayer.rotation = direction.rotation
298-
val axisRotateTest = testPlaceState(context)
299-
when (axisRotateTest.testResult) {
300-
PlaceTestResult.BlockedByEntity -> return@direction
301-
302-
PlaceTestResult.NoIntegrity -> {
303-
if (index != PlaceDirection.entries.lastIndex) return@direction
304-
return RotatePlaceTest(axisRotateTest, currentDirIsValid, fakePlayer.rotation)
305-
}
306-
307-
else -> return RotatePlaceTest(axisRotateTest, currentDirIsValid, fakePlayer.rotation)
291+
testPlaceState(context).takeIf { it.testResult == PlaceTestResult.Success }?.let { axisRotateTest ->
292+
return rotatePlaceTest(axisRotateTest, currentDirIsValid, fakePlayer.rotation)
308293
}
309294
}
310295

@@ -323,8 +308,21 @@ class PlaceChecker @SimCheckerDsl private constructor(simInfo: SimInfo)
323308
} else PlaceTest(resultState, PlaceTestResult.Success)
324309
}
325310

326-
private data class RotatePlaceTest(val placeTest: PlaceTest, val currentDirIsValid: Boolean, val rotation: Rotation) {
327-
val isValid = placeTest.testResult == PlaceTestResult.Success
311+
private class RotatePlaceTest private constructor(
312+
val resultState: BlockState,
313+
val currentDirIsValid: Boolean,
314+
val rotation: Rotation
315+
) {
316+
companion object {
317+
fun rotatePlaceTest(
318+
placeTest: PlaceTest,
319+
currentDirIsValid: Boolean,
320+
rotation: Rotation
321+
): RotatePlaceTest? {
322+
return if (placeTest.testResult != PlaceTestResult.Success) null
323+
else RotatePlaceTest(placeTest.resultState, currentDirIsValid, rotation)
324+
}
325+
}
328326
}
329327
private data class PlaceTest(val resultState: BlockState, val testResult: PlaceTestResult)
330328
private enum class PlaceTestResult {

0 commit comments

Comments
 (0)