Skip to content

Commit 58aef67

Browse files
committed
axis rotations for air placing rotational blocks
1 parent 1951207 commit 58aef67

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

common/src/main/kotlin/com/lambda/config/groups/PlaceSettings.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class PlaceSettings(
2828
) : PlaceConfig(priority) {
2929
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() }
3030
override val airPlace by c.setting("Air Place", AirPlaceMode.None, "Allows for placing blocks without adjacent faces") { vis() }
31+
override val axisRotateSetting by c.setting("Axis Rotate", true, "Overrides the Rotate For Place setting and rotates the player on each axis to air place rotational blocks") { vis() && airPlace.isEnabled() }
32+
override val axisRotate
33+
get() = airPlace.isEnabled() && axisRotateSetting
3134
override val placeConfirmationMode by c.setting("Place Confirmation", PlaceConfirmationMode.PlaceThenAwait, "Wait for block placement confirmation") { vis() }
3235
override val maxPendingPlacements by c.setting("Max Pending Placements", 5, 0..30, 1, "The maximum amount of pending placements") { vis() }
3336
override val placementsPerTick by c.setting("Instant Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick") { vis() }

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

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import com.lambda.util.math.distSq
5858
import com.lambda.util.player.SlotUtils.hotbar
5959
import com.lambda.util.player.copyPlayer
6060
import com.lambda.util.player.gamemode
61+
import com.lambda.util.player.placementRotations
6162
import com.lambda.util.world.raycast.RayCastUtils.blockResult
6263
import net.minecraft.block.OperatorBlock
6364
import net.minecraft.block.pattern.CachedBlockPosition
@@ -292,18 +293,52 @@ object BuildSimulator {
292293
context = checked
293294
}
294295

295-
val resultState = blockItem.getPlacementState(context) ?: run {
296+
var resultState = blockItem.getPlacementState(context) ?: run {
296297
acc.add(PlaceResult.BlockedByEntity(pos))
297298
return@forEach
298299
}
300+
var rot = checkedHit.targetRotation
299301

300-
if (!target.matches(resultState, pos, world)) {
301-
acc.add(
302-
PlaceResult.NoIntegrity(
302+
val simulatePlaceState = placeState@ {
303+
resultState = blockItem.getPlacementState(context)
304+
?: return@placeState PlaceResult.BlockedByEntity(pos)
305+
306+
if (!target.matches(resultState, pos, world)) {
307+
return@placeState PlaceResult.NoIntegrity(
303308
pos, resultState, context, (target as? TargetState.State)?.blockState
304309
)
305-
)
306-
return@forEach
310+
} else {
311+
rot = fakePlayer.rotation
312+
return@placeState null
313+
}
314+
}
315+
316+
if (!place.axisRotate && place.rotateForPlace) {
317+
simulatePlaceState()?.let { placeResult ->
318+
acc.add(placeResult)
319+
return@forEach
320+
}
321+
} else if (place.rotateForPlace) run axisRotate@ {
322+
placementRotations.forEachIndexed direction@ { index, angle ->
323+
fakePlayer.rotation = angle
324+
325+
when (val placeResult = simulatePlaceState()) {
326+
is PlaceResult.BlockedByEntity -> {
327+
acc.add(placeResult)
328+
return@forEach
329+
}
330+
331+
is PlaceResult.NoIntegrity -> {
332+
if (index != placementRotations.lastIndex) return@direction
333+
acc.add(placeResult)
334+
return@forEach
335+
}
336+
337+
else -> {
338+
return@axisRotate
339+
}
340+
}
341+
}
307342
}
308343

309344
val blockHit = checkedResult.blockResult ?: return@forEach
@@ -316,7 +351,7 @@ object BuildSimulator {
316351
val placeContext = PlaceContext(
317352
eye,
318353
blockHit,
319-
RotationRequest(lookAt(checkedHit.targetRotation, 0.001), rotation),
354+
RotationRequest(lookAt(rot, 0.001), rotation),
320355
eye.distanceTo(blockHit.pos),
321356
resultState,
322357
blockState(blockHit.blockPos.offset(blockHit.side)),

common/src/main/kotlin/com/lambda/interaction/request/placing/PlaceConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ abstract class PlaceConfig(
2626
) : RequestConfig<PlaceRequest>(priority) {
2727
abstract val rotateForPlace: Boolean
2828
abstract val airPlace: AirPlaceMode
29+
protected abstract val axisRotateSetting: Boolean
30+
abstract val axisRotate: Boolean
2931
abstract val placeConfirmationMode: PlaceConfirmationMode
3032
abstract val maxPendingPlacements: Int
3133
abstract val placementsPerTick: Int

common/src/main/kotlin/com/lambda/util/player/PlayerUtils.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.lambda.util.player
22

33
import com.lambda.config.groups.BuildConfig
44
import com.lambda.context.SafeContext
5+
import com.lambda.interaction.request.rotation.Rotation
6+
import com.lambda.interaction.request.rotation.Rotation.Companion.yaw
57
import com.mojang.authlib.GameProfile
68
import net.minecraft.client.network.ClientPlayerEntity
79
import net.minecraft.client.network.OtherClientPlayerEntity
@@ -10,6 +12,7 @@ import net.minecraft.entity.player.PlayerEntity
1012
import net.minecraft.item.Item
1113
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket
1214
import net.minecraft.util.Hand
15+
import net.minecraft.util.math.Direction
1316

1417
val SafeContext.gamemode
1518
get() = interaction.currentGameMode
@@ -62,4 +65,15 @@ fun SafeContext.swingHandClient(hand: Hand) {
6265
}
6366
}
6467

65-
fun SafeContext.isItemOnCooldown(item: Item) = player.itemCooldownManager.isCoolingDown(item)
68+
fun SafeContext.isItemOnCooldown(item: Item) = player.itemCooldownManager.isCoolingDown(item)
69+
70+
val placementRotations = Direction.entries
71+
.filter { it.axis.isHorizontal }
72+
.flatMap { dir ->
73+
val yaw = dir.yaw
74+
listOf(
75+
Rotation(yaw, 0f),
76+
Rotation(yaw, -90f),
77+
Rotation(yaw, 90f)
78+
)
79+
}

0 commit comments

Comments
 (0)