Skip to content

Commit 468c355

Browse files
committed
Forcing horizontal rotation, placement preprocessor, lots of fixes
1 parent 1adbf71 commit 468c355

File tree

24 files changed

+541
-150
lines changed

24 files changed

+541
-150
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ interface InteractionConfig {
2525
*/
2626
val reach: Double
2727

28+
val visibilityCheck: Boolean
29+
2830
/**
2931
* Will check `resolution squared` many points on a grid on each visible surface of the hit box.
3032
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class InteractionSettings(
2626
) : InteractionConfig {
2727
override val reach by c.setting("Reach", defaultReach, 0.1..10.0, 0.1, "Players reach / range", " blocks", vis)
2828
override val useRayCast by c.setting("Raycast", true, "Verify hit vector with ray casting (for very strict ACs)", vis)
29+
override val visibilityCheck by c.setting("Visibility Check", true, "Check if target is visible", vis)
2930
override val resolution by c.setting("Resolution", 4, 1..40, 1, "How many raycast checks per surface (will be squared)") { vis() && useRayCast }
3031
override val swingHand by c.setting("Swing Hand", true, "Swing hand on interactions", vis)
3132
override val pingTimeout by c.setting("Ping Timeout", false, "Timeout on high ping", vis)

common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ import kotlin.reflect.KProperty
4646
* The [SafeListener] will keep a reference to the last signal processed by the listener.
4747
* Allowing use cases where the last signal is needed.
4848
* ```kotlin
49-
* val lastPacketReceived by listener<PacketEvent.Receive.Pre>()
49+
* val lastPacketReceived by listen<PacketEvent.Receive.Pre>()
5050
*
51-
* listener<PacketEvent.Send.Pre> { event ->
51+
* listen<PacketEvent.Send.Pre> { event ->
5252
* println("Last packet received: ${lastPacketReceived?.packet}")
5353
* // prints the last packet received
5454
* // prints null if no packet was received

common/src/main/kotlin/com/lambda/interaction/RotationManager.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,20 @@ object RotationManager : Loadable {
123123
currentRotation = currentContext?.let { context ->
124124
val rotationTo = if (keepTicks >= 0) context.rotation else player.rotation
125125

126-
var speedMultiplier = (context.config as? RotationSettings)?.speedMultiplier ?: 1.0
127-
if (keepTicks < 0) speedMultiplier = 1.0
128-
129-
val turnSpeed = context.config.turnSpeed * speedMultiplier
130-
131-
currentRotation
132-
.slerp(rotationTo, turnSpeed)
133-
.fixSensitivity(prevRotation)
134-
.apply {
135-
if (context.config.rotationMode != RotationMode.LOCK) return@apply
136-
player.yaw = this.yawF
137-
player.pitch = this.pitchF
138-
}
126+
rotationTo
127+
// var speedMultiplier = (context.config as? RotationSettings)?.speedMultiplier ?: 1.0
128+
// if (keepTicks < 0) speedMultiplier = 1.0
129+
//
130+
// val turnSpeed = context.config.turnSpeed * speedMultiplier
131+
//
132+
// currentRotation
133+
// .slerp(rotationTo, turnSpeed)
134+
// .fixSensitivity(prevRotation)
135+
// .apply {
136+
// if (context.config.rotationMode != RotationMode.LOCK) return@apply
137+
// player.yaw = this.yawF
138+
// player.pitch = this.pitchF
139+
// }
139140
} ?: player.rotation
140141
}
141142

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import net.minecraft.block.BlockState
2424
import net.minecraft.util.Hand
2525
import net.minecraft.util.hit.BlockHitResult
2626
import net.minecraft.util.math.BlockPos
27+
import net.minecraft.util.math.Direction
2728
import net.minecraft.util.math.Vec3d
2829

2930
data class PlaceContext(
@@ -37,6 +38,7 @@ data class PlaceContext(
3738
val targetState: TargetState,
3839
val sneak: Boolean,
3940
val insideBlock: Boolean,
41+
val primeDirection: Direction?
4042
) : BuildContext {
4143
override val resultingPos: BlockPos
4244
get() = result.blockPos.offset(result.side)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.construction.processing
19+
20+
import net.minecraft.block.BlockState
21+
22+
abstract class PlacementProcessor {
23+
abstract fun acceptState(state: BlockState): Boolean
24+
abstract fun preProcess(state: BlockState): PreprocessingStep
25+
}
26+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.construction.processing
19+
20+
import com.lambda.interaction.construction.verify.SurfaceScan
21+
import net.minecraft.state.property.Property
22+
import net.minecraft.util.math.Direction
23+
24+
data class PreprocessingStep(
25+
val surfaceScan: SurfaceScan = SurfaceScan.DEFAULT,
26+
val ignore: Set<Property<*>> = emptySet(),
27+
val sides: Set<Direction> = Direction.entries.toSet(),
28+
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.construction.processing
19+
20+
import com.lambda.core.Loadable
21+
import com.lambda.interaction.construction.verify.TargetState
22+
import com.lambda.util.reflections.getInstances
23+
import net.minecraft.block.BlockState
24+
import net.minecraft.block.Blocks
25+
26+
object ProcessorRegistry : Loadable {
27+
private const val PROCESSOR_PACKAGE = "com.lambda.interaction.construction.processing.processors"
28+
private val processors = getInstances<PlacementProcessor> { forPackages(PROCESSOR_PACKAGE) }
29+
private val processorCache = mutableMapOf<BlockState, PreprocessingStep>()
30+
31+
fun findProcessorForState(target: TargetState): PreprocessingStep =
32+
(target as? TargetState.State)?.let { state ->
33+
processorCache.getOrPut(state.blockState) {
34+
(processors.find { it.acceptState(state.blockState) } ?: DefaultProcessor).preProcess(state.blockState)
35+
}
36+
} ?: DefaultProcessor.preProcess(Blocks.AIR.defaultState)
37+
38+
object DefaultProcessor : PlacementProcessor() {
39+
override fun acceptState(state: BlockState) = true
40+
override fun preProcess(state: BlockState) = PreprocessingStep()
41+
}
42+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.construction.processing.processors
19+
20+
import com.lambda.interaction.construction.processing.PlacementProcessor
21+
import com.lambda.interaction.construction.processing.PreprocessingStep
22+
import net.minecraft.block.BlockState
23+
import net.minecraft.state.property.Properties
24+
25+
object FacingProcessor : PlacementProcessor() {
26+
override fun acceptState(state: BlockState) =
27+
state.getOrEmpty(Properties.FACING).isPresent
28+
29+
override fun preProcess(state: BlockState): PreprocessingStep {
30+
// Needs two sets of blocks: native and opposite!
31+
return PreprocessingStep(
32+
sides = setOf(state.getOrEmpty(Properties.FACING).get())
33+
)
34+
}
35+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.construction.processing.processors
19+
20+
import com.lambda.interaction.construction.processing.PlacementProcessor
21+
import com.lambda.interaction.construction.processing.PreprocessingStep
22+
import com.lambda.interaction.construction.verify.ScanMode
23+
import com.lambda.interaction.construction.verify.SurfaceScan
24+
import net.minecraft.block.BlockState
25+
import net.minecraft.block.SlabBlock
26+
import net.minecraft.block.enums.SlabType
27+
import net.minecraft.state.property.Properties
28+
import net.minecraft.util.math.Direction
29+
30+
object SlabProcessor : PlacementProcessor() {
31+
override fun acceptState(state: BlockState) = state.block is SlabBlock
32+
33+
override fun preProcess(state: BlockState): PreprocessingStep {
34+
val slab = state.getOrEmpty(Properties.SLAB_TYPE).get()
35+
36+
val surfaceScan = when (slab) {
37+
SlabType.BOTTOM -> SurfaceScan(
38+
ScanMode.LESSER_HALF, Direction.Axis.Y
39+
)
40+
SlabType.TOP -> SurfaceScan(
41+
ScanMode.GREATER_HALF, Direction.Axis.Y
42+
)
43+
SlabType.DOUBLE -> SurfaceScan(
44+
ScanMode.FULL, Direction.Axis.Y
45+
)
46+
}
47+
48+
return PreprocessingStep(surfaceScan)
49+
}
50+
}

0 commit comments

Comments
 (0)