Skip to content

Commit 38a5fc0

Browse files
committed
previous rotation direction checks in build sim
1 parent b267a79 commit 38a5fc0

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import com.lambda.util.BlockUtils.blockState
3030
import net.minecraft.block.BlockState
3131
import net.minecraft.util.hit.BlockHitResult
3232
import net.minecraft.util.math.BlockPos
33-
import net.minecraft.util.math.Direction
3433
import net.minecraft.util.math.Vec3d
3534
import java.awt.Color
3635

@@ -46,7 +45,7 @@ data class PlaceContext(
4645
override val targetState: TargetState,
4746
val sneak: Boolean,
4847
val insideBlock: Boolean,
49-
val primeDirection: Direction?
48+
val previousDirWasInvalid: Boolean = false
5049
) : BuildContext {
5150
private val baseColor = Color(35, 188, 254, 25)
5251
private val sideColor = Color(35, 188, 254, 100)
@@ -79,7 +78,9 @@ data class PlaceContext(
7978

8079
fun requestDependencies(request: PlaceRequest): Boolean {
8180
val hotbarRequest = request.hotbar.request(HotbarRequest(hotbarIndex, request.hotbar))
82-
val validRotation = if (request.build.placing.rotate) request.rotation.request(rotation).done else true
81+
val validRotation = if (request.build.placing.rotate) {
82+
request.rotation.request(rotation).done && !previousDirWasInvalid
83+
} else true
8384
return hotbarRequest.done && validRotation
8485
}
8586
}

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ import net.minecraft.item.BlockItem
6969
import net.minecraft.item.ItemPlacementContext
7070
import net.minecraft.item.ItemUsageContext
7171
import net.minecraft.registry.RegistryKeys
72-
import net.minecraft.state.property.Properties
7372
import net.minecraft.util.Hand
7473
import net.minecraft.util.hit.BlockHitResult
7574
import net.minecraft.util.math.BlockPos
7675
import net.minecraft.util.math.Box
7776
import net.minecraft.util.math.Direction
7877
import net.minecraft.util.math.Vec3d
7978
import net.minecraft.util.shape.VoxelShapes
80-
import kotlin.jvm.optionals.getOrNull
8179
import kotlin.math.pow
8280

8381
object BuildSimulator {
@@ -243,7 +241,7 @@ object BuildSimulator {
243241
// ToDo: For each hand and sneak or not?
244242
val fakePlayer = copyPlayer(player).apply {
245243
setPos(eye.x, eye.y - standingEyeHeight, eye.z)
246-
if (place.rotateForPlace) this.rotation = checkedHit.targetRotation
244+
this.rotation = RotationManager.serverRotation
247245
}
248246

249247
val checkedResult = checkedHit.hit
@@ -311,11 +309,26 @@ object BuildSimulator {
311309
}
312310
}
313311

314-
simulatePlaceState()?.let simulatePlaceState@ { basePlaceResult ->
315-
if (!place.axisRotate) {
312+
var currentDirIsInvalid = false
313+
simulatePlaceState()?.let { basePlaceResult ->
314+
if (!place.rotate) {
316315
acc.add(basePlaceResult)
317316
return@forEach
318317
}
318+
319+
currentDirIsInvalid = true
320+
}
321+
322+
if (place.rotateForPlace && !place.axisRotate) {
323+
fakePlayer.rotation = checkedHit.targetRotation
324+
simulatePlaceState()?.let { rotatedPlaceResult ->
325+
acc.add(rotatedPlaceResult)
326+
return@forEach
327+
}
328+
rot = checkedHit.targetRotation
329+
}
330+
331+
if (place.axisRotate) run axisRotations@ {
319332
placementRotations.forEachIndexed direction@ { index, angle ->
320333
fakePlayer.rotation = angle
321334

@@ -332,8 +345,8 @@ object BuildSimulator {
332345
}
333346

334347
else -> {
335-
rot = fakePlayer.rotation
336-
return@simulatePlaceState
348+
rot = angle
349+
return@axisRotations
337350
}
338351
}
339352
}
@@ -343,9 +356,6 @@ object BuildSimulator {
343356
val hitBlock = blockState(blockHit.blockPos).block
344357
val shouldSneak = hitBlock::class in BlockUtils.interactionBlocks
345358

346-
val primeDirection =
347-
(target as? TargetState.State)?.blockState?.getOrEmpty(Properties.HORIZONTAL_FACING)?.getOrNull()
348-
349359
val placeContext = PlaceContext(
350360
eye,
351361
blockHit,
@@ -358,7 +368,7 @@ object BuildSimulator {
358368
target,
359369
shouldSneak,
360370
false,
361-
primeDirection
371+
currentDirIsInvalid
362372
)
363373

364374
val currentHandStack = player.getStackInHand(Hand.MAIN_HAND)

0 commit comments

Comments
 (0)