-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathInteractionSettings.kt
More file actions
69 lines (59 loc) · 3.11 KB
/
InteractionSettings.kt
File metadata and controls
69 lines (59 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright 2025 Lambda
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lambda.config.groups
import com.lambda.config.Configurable
import com.lambda.interaction.request.rotating.visibilty.PointSelection
import com.lambda.util.NamedEnum
import com.lambda.util.world.raycast.InteractionMask
import kotlin.math.max
class InteractionSettings(
c: Configurable,
baseGroup: NamedEnum,
private val usage: InteractionMask,
vis: () -> Boolean = { true },
) : InteractionConfig {
// Reach
private val useDefaultReach by c.setting("Default Reach", true, "Whether to use vanilla interaction ranges", vis).group(baseGroup)
private val attackReachSetting = if (usage.entity) c.setting("Attack Reach", DEFAULT_ATTACK_REACH, 1.0..10.0, 0.01, "Maximum entity interaction distance") { vis() && !useDefaultReach }.group(baseGroup) else null
private val interactReachSetting = if (usage.block) c.setting("Interact Reach", DEFAULT_INTERACT_REACH, 1.0..10.0, 0.01, "Maximum block interaction distance") { vis() && !useDefaultReach }.group(baseGroup) else null
override val attackReach: Double get() {
check(usage.entity) {
"Given interaction config has no attack reach implementation"
}
return if (useDefaultReach) DEFAULT_ATTACK_REACH else attackReachSetting!!.value
}
override val interactReach: Double get() {
check(usage.block) {
"Given interaction config has no place reach implementation"
}
return if (useDefaultReach) DEFAULT_INTERACT_REACH else interactReachSetting!!.value
}
override val scanReach: Double get() = when (usage) {
InteractionMask.Entity -> attackReach
InteractionMask.Block -> interactReach
InteractionMask.Both -> max(attackReach, interactReach)
}
// Point scan
override val strictRayCast by c.setting("Strict Raycast", false, "Whether to include the environment to the ray cast context", vis).group(baseGroup)
override val checkSideVisibility by c.setting("Visibility Check", true, "Whether to check if an AABB side is visible", vis).group(baseGroup)
override val resolution by c.setting("Resolution", 5, 1..20, 1, "The amount of grid divisions per surface of the hit box", "", vis).group(baseGroup)
override val pointSelection by c.setting("Point Selection", PointSelection.Optimum, "The strategy to select the best hit point", vis).group(baseGroup)
companion object {
const val DEFAULT_ATTACK_REACH = 3.0
const val DEFAULT_INTERACT_REACH = 4.5
}
}