mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 12:25:12 -04:00
key combinations: remove STICKY_INVERTED, profiles: hitbox
This commit is contained in:
parent
61c195f4e9
commit
c0905b85a0
@ -14,7 +14,6 @@
|
||||
package de.bixilon.minosoft.config.config.game
|
||||
|
||||
import de.bixilon.minosoft.config.config.game.controls.ControlsGameConfig
|
||||
import de.bixilon.minosoft.config.config.game.entities.EntitiesConfig
|
||||
import de.bixilon.minosoft.config.config.game.graphics.GraphicsGameConfig
|
||||
import de.bixilon.minosoft.config.config.game.hud.HUDGameConfig
|
||||
import de.bixilon.minosoft.config.config.game.world.WorldConfig
|
||||
@ -25,7 +24,6 @@ data class GameConfig(
|
||||
var hud: HUDGameConfig = HUDGameConfig(),
|
||||
var controls: ControlsGameConfig = ControlsGameConfig(),
|
||||
var camera: CameraGameConfig = CameraGameConfig(),
|
||||
var entities: EntitiesConfig = EntitiesConfig(),
|
||||
var world: WorldConfig = WorldConfig(),
|
||||
var light: LightConfig = LightConfig(),
|
||||
var skin: SkinConfig = SkinConfig(),
|
||||
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.config.config.game.entities
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
data class EntitiesConfig(
|
||||
@Json(name = "hit_box") val hitBox: EntityHitBoxConfig = EntityHitBoxConfig(),
|
||||
)
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.config.config.game.entities
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
data class EntityHitBoxConfig(
|
||||
@Json(name = "enabled") val enabled: Boolean = true,
|
||||
@Json(name = "own_hit_box") val ownHitBox: Boolean = false,
|
||||
@Json(name = "disable_z_buffer") val disableZBuffer: Boolean = false,
|
||||
@Json(name = "invisible_entities") val invisibleEntities: Boolean = false,
|
||||
@Json(name = "lazy_hit_boxes") val lazyHitBoxes: Boolean = false,
|
||||
)
|
@ -39,15 +39,11 @@ enum class KeyAction {
|
||||
MODIFIER,
|
||||
|
||||
/**
|
||||
* Pressing the key makes it sticky, you have to press it again to make it not pressed anymore. Initially not pressed.
|
||||
* Pressing the key makes it sticky, you have to press it again to make it not pressed anymore.
|
||||
* Initial pressing state can be set when registering, defaults to false
|
||||
*/
|
||||
STICKY,
|
||||
|
||||
/**
|
||||
* Exactly the same as STICKY, but inverted. Initial pressed.
|
||||
*/
|
||||
STICKY_INVERTED,
|
||||
|
||||
/**
|
||||
* Key must be pressed twice in a certain time. Behaves like sticky (press twice again to disable)
|
||||
*/
|
||||
|
@ -3,6 +3,7 @@ package de.bixilon.minosoft.config.profile
|
||||
import com.fasterxml.jackson.databind.type.MapType
|
||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
@ -24,6 +25,7 @@ object GlobalProfileManager {
|
||||
ErosProfileManager,
|
||||
ParticleProfileManager,
|
||||
AudioProfileManager,
|
||||
EntityProfileManager,
|
||||
)
|
||||
private val SELECTED_PROFILES_TYPE: MapType = Jackson.MAPPER.typeFactory.constructMapType(HashMap::class.java, ResourceLocation::class.java, String::class.java)
|
||||
val CLASS_MAPPING: Map<Class<out Profile>, ProfileManager<*>>
|
||||
|
@ -2,6 +2,8 @@ package de.bixilon.minosoft.config.profile
|
||||
|
||||
import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfile
|
||||
import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfile
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfile
|
||||
@ -11,4 +13,5 @@ data class ProfileCollection(
|
||||
val eros: ErosProfile = ErosProfileManager.selected,
|
||||
val particle: ParticleProfile = ParticleProfileManager.selected,
|
||||
val audio: AudioProfile = AudioProfileManager.selected,
|
||||
val entity: EntityProfile = EntityProfileManager.selected,
|
||||
)
|
||||
|
@ -59,8 +59,9 @@ interface ProfileManager<T : Profile> {
|
||||
return profile
|
||||
}
|
||||
|
||||
|
||||
fun <V> delegate(value: V, checkEquals: Boolean = true, verify: ((V) -> Unit)? = null): ProfileDelegate<V>
|
||||
fun <V> delegate(value: V, checkEquals: Boolean = true, verify: ((V) -> Unit)? = null): ProfileDelegate<V> {
|
||||
return ProfileDelegate(value, checkEquals, this, currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"), verify)
|
||||
}
|
||||
|
||||
fun selectDefault() {
|
||||
selected = profiles[DEFAULT_PROFILE_NAME] ?: createDefaultProfile()
|
||||
|
@ -32,10 +32,12 @@ class SimpleProfileChangeListener<T>(
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmOverloads
|
||||
fun <T> KProperty<T>.listen(reference: Any, instant: Boolean = false, profile: Profile? = null, callback: ((T) -> Unit)) {
|
||||
ProfilesChangeManager.register(reference, SimpleProfileChangeListener(this, javaField!!, profile, instant, callback))
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun <T> KProperty<T>.listenFX(reference: Any, instant: Boolean = false, profile: Profile? = null, callback: ((T) -> Unit)) {
|
||||
ProfilesChangeManager.register(reference, SimpleProfileChangeListener(this, javaField!!, profile, instant) { JavaFXUtil.runLater { callback(it) } })
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package de.bixilon.minosoft.config.profile.profiles.audio
|
||||
import com.google.common.collect.HashBiMap
|
||||
import de.bixilon.minosoft.config.profile.GlobalProfileManager
|
||||
import de.bixilon.minosoft.config.profile.ProfileManager
|
||||
import de.bixilon.minosoft.config.profile.util.ProfileDelegate
|
||||
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||
@ -34,8 +33,4 @@ object AudioProfileManager : ProfileManager<AudioProfile> {
|
||||
|
||||
return profile
|
||||
}
|
||||
|
||||
override fun <V> delegate(value: V, checkEquals: Boolean, verify: ((V) -> Unit)?): ProfileDelegate<V> {
|
||||
return ProfileDelegate(value, checkEquals, this, currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"), verify)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package de.bixilon.minosoft.config.profile.profiles.entity
|
||||
|
||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager.delegate
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager.latestVersion
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.hitbox.HitboxC
|
||||
|
||||
/**
|
||||
* Profile for entity
|
||||
*/
|
||||
class EntityProfile(
|
||||
description: String? = null,
|
||||
) : Profile {
|
||||
override var initializing: Boolean = true
|
||||
private set
|
||||
override var saved: Boolean = true
|
||||
override val version: Int = latestVersion
|
||||
override val description by delegate(description ?: "")
|
||||
|
||||
|
||||
val hitbox = HitboxC()
|
||||
|
||||
override fun toString(): String {
|
||||
return EntityProfileManager.getName(this)
|
||||
}
|
||||
|
||||
init {
|
||||
initializing = false
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package de.bixilon.minosoft.config.profile.profiles.entity
|
||||
|
||||
import com.google.common.collect.HashBiMap
|
||||
import de.bixilon.minosoft.config.profile.GlobalProfileManager
|
||||
import de.bixilon.minosoft.config.profile.ProfileManager
|
||||
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
|
||||
object EntityProfileManager : ProfileManager<EntityProfile> {
|
||||
override val namespace = "minosoft:entity".toResourceLocation()
|
||||
override val latestVersion = 1
|
||||
override val saveLock = ReentrantLock()
|
||||
override val profileClass = EntityProfile::class.java
|
||||
|
||||
|
||||
override var currentLoadingPath: String? = null
|
||||
override val profiles: HashBiMap<String, EntityProfile> = HashBiMap.create()
|
||||
|
||||
override var selected: EntityProfile = null.unsafeCast()
|
||||
set(value) {
|
||||
field = value
|
||||
GlobalProfileManager.selectProfile(this, value)
|
||||
GlobalEventMaster.fireEvent(EntityProfileSelectEvent(value))
|
||||
}
|
||||
|
||||
override fun createDefaultProfile(name: String): EntityProfile {
|
||||
currentLoadingPath = name
|
||||
val profile = EntityProfile("Default entity profile")
|
||||
currentLoadingPath = null
|
||||
profiles[name] = profile
|
||||
|
||||
return profile
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package de.bixilon.minosoft.config.profile.profiles.entity
|
||||
|
||||
import de.bixilon.minosoft.modding.event.events.Event
|
||||
|
||||
class EntityProfileSelectEvent(
|
||||
val profile: EntityProfile,
|
||||
) : Event
|
@ -0,0 +1,32 @@
|
||||
package de.bixilon.minosoft.config.profile.profiles.entity.hitbox
|
||||
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager.delegate
|
||||
|
||||
class HitboxC {
|
||||
/**
|
||||
* Enables or disables hit-boxes for all entities
|
||||
*/
|
||||
var enabled by delegate(true)
|
||||
|
||||
/**
|
||||
* Shows your own hit-box when in first person view
|
||||
*/
|
||||
var showLocal by delegate(false)
|
||||
|
||||
/**
|
||||
* Shows hit-boxes from invisible entities
|
||||
*/
|
||||
var showInvisible by delegate(false)
|
||||
|
||||
/**
|
||||
* If true: Shows full colored hit-boxes (aka. lazy boxes).
|
||||
* If false: Shows just the outline of the hit-box
|
||||
*/
|
||||
var lazy by delegate(false)
|
||||
|
||||
/**
|
||||
* Disables the z-buffer when rendering
|
||||
* => Shows the boxes through walls
|
||||
*/
|
||||
var showThroughWalls by delegate(false)
|
||||
}
|
@ -3,7 +3,6 @@ package de.bixilon.minosoft.config.profile.profiles.eros
|
||||
import com.google.common.collect.HashBiMap
|
||||
import de.bixilon.minosoft.config.profile.GlobalProfileManager
|
||||
import de.bixilon.minosoft.config.profile.ProfileManager
|
||||
import de.bixilon.minosoft.config.profile.util.ProfileDelegate
|
||||
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||
@ -34,8 +33,4 @@ object ErosProfileManager : ProfileManager<ErosProfile> {
|
||||
|
||||
return profile
|
||||
}
|
||||
|
||||
override fun <V> delegate(value: V, checkEquals: Boolean, verify: ((V) -> Unit)?): ProfileDelegate<V> {
|
||||
return ProfileDelegate(value, checkEquals, this, currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"), verify)
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package de.bixilon.minosoft.config.profile.profiles.particle
|
||||
import com.google.common.collect.HashBiMap
|
||||
import de.bixilon.minosoft.config.profile.GlobalProfileManager
|
||||
import de.bixilon.minosoft.config.profile.ProfileManager
|
||||
import de.bixilon.minosoft.config.profile.util.ProfileDelegate
|
||||
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||
@ -34,8 +33,4 @@ object ParticleProfileManager : ProfileManager<ParticleProfile> {
|
||||
|
||||
return profile
|
||||
}
|
||||
|
||||
override fun <V> delegate(value: V, checkEquals: Boolean, verify: ((V) -> Unit)?): ProfileDelegate<V> {
|
||||
return ProfileDelegate(value, checkEquals, this, currentLoadingPath ?: throw IllegalAccessException("Delegate can only be created while loading or creating profiles!"), verify)
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ class WorldEntities : Iterable<Entity> {
|
||||
uuidEntityMap[entityUUID]?.let { remove(it) }
|
||||
}
|
||||
|
||||
@Deprecated("ToDo: Lock")
|
||||
override fun iterator(): Iterator<Entity> {
|
||||
return idEntityMap.toSynchronizedMap().values.iterator()
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.BaseComponent
|
||||
import de.bixilon.minosoft.data.text.ChatColors
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.gui.rendering.entity.EntityHitBoxRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.entity.EntityHitboxRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.font.Font
|
||||
import de.bixilon.minosoft.gui.rendering.font.FontLoader
|
||||
import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer
|
||||
@ -136,9 +136,7 @@ class RenderWindow(
|
||||
if (!connection.profiles.particle.skipLoading) {
|
||||
registerRenderer(ParticleRenderer)
|
||||
}
|
||||
if (Minosoft.config.config.game.entities.hitBox.enabled) {
|
||||
registerRenderer(EntityHitBoxRenderer)
|
||||
}
|
||||
registerRenderer(EntityHitboxRenderer)
|
||||
if (Minosoft.config.config.game.world.chunkBorders.enabled) {
|
||||
registerRenderer(ChunkBorderRenderer)
|
||||
}
|
||||
@ -168,12 +166,7 @@ class RenderWindow(
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING) { "Generating font and gathering textures (${stopwatch.labTime()})..." }
|
||||
textureManager.staticTextures.createTexture(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION)
|
||||
WHITE_TEXTURE = TextureLikeTexture(
|
||||
texture = textureManager.staticTextures.createTexture(ResourceLocation("minosoft:textures/white.png")),
|
||||
uvStart = Vec2(0.0f, 0.0f),
|
||||
uvEnd = Vec2(0.001f, 0.001f),
|
||||
size = Vec2i(16, 16)
|
||||
)
|
||||
WHITE_TEXTURE = TextureLikeTexture(texture = textureManager.staticTextures.createTexture(ResourceLocation("minosoft:textures/white.png")), uvStart = Vec2(0.0f, 0.0f), uvEnd = Vec2(0.001f, 0.001f), size = Vec2i(16, 16))
|
||||
font = FontLoader.load(this)
|
||||
|
||||
|
||||
@ -226,48 +219,53 @@ class RenderWindow(
|
||||
}
|
||||
|
||||
private fun registerGlobalKeyCombinations() {
|
||||
inputHandler.registerKeyCallback("minosoft:enable_debug_polygon".toResourceLocation(), KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_P),
|
||||
),
|
||||
)) {
|
||||
inputHandler.registerKeyCallback("minosoft:enable_debug_polygon".toResourceLocation(),
|
||||
KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_P),
|
||||
),
|
||||
)) {
|
||||
val nextMode = it.decide(PolygonModes.LINE, PolygonModes.FILL)
|
||||
renderSystem.polygonMode = nextMode
|
||||
sendDebugMessage("Set polygon to: $nextMode")
|
||||
}
|
||||
|
||||
inputHandler.registerKeyCallback("minosoft:quit_rendering".toResourceLocation(), KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.RELEASE to mutableSetOf(KeyCodes.KEY_ESCAPE),
|
||||
),
|
||||
)) { window.close() }
|
||||
inputHandler.registerKeyCallback("minosoft:quit_rendering".toResourceLocation(),
|
||||
KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.RELEASE to mutableSetOf(KeyCodes.KEY_ESCAPE),
|
||||
),
|
||||
)) { window.close() }
|
||||
|
||||
inputHandler.registerKeyCallback("minosoft:take_screenshot".toResourceLocation(), KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_F2),
|
||||
),
|
||||
ignoreConsumer = true,
|
||||
)) { screenshotTaker.takeScreenshot() }
|
||||
inputHandler.registerKeyCallback("minosoft:take_screenshot".toResourceLocation(),
|
||||
KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.PRESS to mutableSetOf(KeyCodes.KEY_F2),
|
||||
),
|
||||
ignoreConsumer = true,
|
||||
)) { screenshotTaker.takeScreenshot() }
|
||||
|
||||
inputHandler.registerKeyCallback("minosoft:pause_incoming_packets".toResourceLocation(), KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_I),
|
||||
),
|
||||
ignoreConsumer = true,
|
||||
)) {
|
||||
inputHandler.registerKeyCallback("minosoft:pause_incoming_packets".toResourceLocation(),
|
||||
KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_I),
|
||||
),
|
||||
ignoreConsumer = true,
|
||||
)) {
|
||||
sendDebugMessage("Pausing incoming packets: $it")
|
||||
connection.network.pauseReceiving(it)
|
||||
}
|
||||
|
||||
inputHandler.registerKeyCallback("minosoft:pause_outgoing_packets".toResourceLocation(), KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_O),
|
||||
),
|
||||
ignoreConsumer = true,
|
||||
)) {
|
||||
inputHandler.registerKeyCallback("minosoft:pause_outgoing_packets".toResourceLocation(),
|
||||
KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_O),
|
||||
),
|
||||
ignoreConsumer = true,
|
||||
)) {
|
||||
sendDebugMessage("Pausing outgoing packets: $it")
|
||||
connection.network.pauseSending(it)
|
||||
}
|
||||
|
@ -13,13 +13,11 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.entity
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.registries.AABB
|
||||
import de.bixilon.minosoft.data.text.ChatColors
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.input.camera.frustum.Frustum
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.empty
|
||||
import de.bixilon.minosoft.gui.rendering.util.mesh.LineMesh
|
||||
@ -28,8 +26,8 @@ import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
|
||||
import glm_.vec3.Vec3
|
||||
import glm_.vec3.Vec3d
|
||||
|
||||
class EntityHitBox(
|
||||
val renderWindow: RenderWindow,
|
||||
class EntityHitbox(
|
||||
val renderer: EntityHitboxRenderer,
|
||||
val entity: Entity,
|
||||
val frustum: Frustum,
|
||||
) {
|
||||
@ -58,7 +56,7 @@ class EntityHitBox(
|
||||
|
||||
this.checkVisibility = false
|
||||
|
||||
val visible = ((entity.isInvisible && Minosoft.config.config.game.entities.hitBox.invisibleEntities) || !entity.isInvisible) && frustum.containsAABB(aabb)
|
||||
val visible = ((entity.isInvisible && renderer.profile.showInvisible) || !entity.isInvisible) && frustum.containsAABB(aabb)
|
||||
if (checkVisibility && equals && this::mesh.isInitialized) {
|
||||
// only visibility changed
|
||||
this.visible = visible
|
||||
@ -68,8 +66,8 @@ class EntityHitBox(
|
||||
this.mesh.unload()
|
||||
}
|
||||
if (visible) {
|
||||
val mesh = LineMesh(renderWindow)
|
||||
if (Minosoft.config.config.game.entities.hitBox.lazyHitBoxes) {
|
||||
val mesh = LineMesh(renderer.renderWindow)
|
||||
if (renderer.profile.lazy) {
|
||||
mesh.drawLazyAABB(aabb, color = hitBoxColor)
|
||||
} else {
|
||||
mesh.drawAABB(aabb = aabb, color = hitBoxColor, margin = 0.1f)
|
@ -13,8 +13,12 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.entity
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.key.KeyAction
|
||||
import de.bixilon.minosoft.config.key.KeyBinding
|
||||
import de.bixilon.minosoft.config.key.KeyCodes
|
||||
import de.bixilon.minosoft.config.profile.change.listener.SimpleProfileChangeListener.Companion.listen
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.player.LocalPlayerEntity
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.Renderer
|
||||
@ -23,31 +27,53 @@ import de.bixilon.minosoft.gui.rendering.modding.events.FrustumChangeEvent
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.DepthFunctions
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.phases.OpaqueDrawable
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.phases.SkipAll
|
||||
import de.bixilon.minosoft.modding.event.events.EntityDestroyEvent
|
||||
import de.bixilon.minosoft.modding.event.events.EntitySpawnEvent
|
||||
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.format
|
||||
import de.bixilon.minosoft.util.KUtil.lockMapOf
|
||||
import de.bixilon.minosoft.util.KUtil.synchronizedSetOf
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.toSynchronizedSet
|
||||
import de.bixilon.minosoft.util.collections.LockMap
|
||||
|
||||
class EntityHitBoxRenderer(
|
||||
class EntityHitboxRenderer(
|
||||
val connection: PlayConnection,
|
||||
override val renderWindow: RenderWindow,
|
||||
) : Renderer, OpaqueDrawable {
|
||||
) : Renderer, OpaqueDrawable, SkipAll {
|
||||
override val renderSystem: RenderSystem = renderWindow.renderSystem
|
||||
val profile = connection.profiles.entity.hitbox
|
||||
private val frustum = renderWindow.inputHandler.camera.frustum
|
||||
private val meshes: LockMap<Entity, EntityHitBox> = lockMapOf()
|
||||
private val toUnload: MutableSet<EntityHitBox> = synchronizedSetOf()
|
||||
private val meshes: LockMap<Entity, EntityHitbox> = lockMapOf()
|
||||
private val toUnload: MutableSet<EntityHitbox> = synchronizedSetOf()
|
||||
|
||||
private lateinit var localHitbox: EntityHitbox
|
||||
|
||||
private var enabled = profile.enabled
|
||||
private var setAvailable = enabled
|
||||
|
||||
override val skipAll: Boolean
|
||||
get() = !enabled
|
||||
|
||||
override fun init() {
|
||||
connection.registerEvent(CallbackEventInvoker.of<EntitySpawnEvent> {
|
||||
meshes.getOrPut(it.entity) { EntityHitBox(renderWindow, it.entity, frustum) }
|
||||
if (!enabled) {
|
||||
return@of
|
||||
}
|
||||
meshes.getOrPut(it.entity) { EntityHitbox(this, it.entity, frustum) }
|
||||
})
|
||||
connection.registerEvent(CallbackEventInvoker.of<EntityDestroyEvent> {
|
||||
if (!enabled) {
|
||||
return@of
|
||||
}
|
||||
toUnload += meshes.remove(it.entity) ?: return@of
|
||||
})
|
||||
connection.registerEvent(CallbackEventInvoker.of<EntityDestroyEvent> { toUnload += meshes.remove(it.entity) ?: return@of })
|
||||
connection.registerEvent(CallbackEventInvoker.of<FrustumChangeEvent> {
|
||||
if (!enabled) {
|
||||
return@of
|
||||
}
|
||||
meshes.lock.acquire()
|
||||
for (mesh in meshes.values) {
|
||||
mesh.updateVisibility()
|
||||
@ -55,12 +81,50 @@ class EntityHitBoxRenderer(
|
||||
meshes.lock.release()
|
||||
})
|
||||
|
||||
if (Minosoft.config.config.game.entities.hitBox.ownHitBox) {
|
||||
meshes[connection.player] = EntityHitBox(renderWindow, connection.player, frustum)
|
||||
profile::enabled.listen(this, profile = connection.profiles.entity) { this.setAvailable = it }
|
||||
|
||||
this.localHitbox = EntityHitbox(this, connection.player, frustum)
|
||||
profile::showLocal.listen(this, true, connection.profiles.entity) {
|
||||
if (it) {
|
||||
meshes[connection.player] = localHitbox
|
||||
} else {
|
||||
meshes -= connection.player
|
||||
}
|
||||
}
|
||||
|
||||
renderWindow.inputHandler.registerKeyCallback(HITBOX_TOGGLE_KEY_COMBINATION,
|
||||
KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F3),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_B),
|
||||
),
|
||||
), defaultPressed = profile.enabled) {
|
||||
profile.enabled = it
|
||||
renderWindow.sendDebugMessage("Entity hit boxes: ${it.format()}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateEnabled() {
|
||||
if (setAvailable) {
|
||||
for (entity in connection.world.entities) {
|
||||
if (entity is LocalPlayerEntity && !profile.showLocal) {
|
||||
continue
|
||||
}
|
||||
meshes[entity] = EntityHitbox(this, entity, frustum)
|
||||
}
|
||||
} else {
|
||||
for (mesh in meshes.values) {
|
||||
mesh.unload()
|
||||
}
|
||||
this.meshes.clear()
|
||||
}
|
||||
this.enabled = setAvailable
|
||||
}
|
||||
|
||||
override fun prepareDraw() {
|
||||
if (setAvailable != enabled) {
|
||||
updateEnabled()
|
||||
}
|
||||
for (hitBox in toUnload.toSynchronizedSet()) {
|
||||
hitBox.unload()
|
||||
toUnload -= hitBox
|
||||
@ -69,7 +133,7 @@ class EntityHitBoxRenderer(
|
||||
|
||||
override fun setupOpaque() {
|
||||
renderWindow.renderSystem.reset(faceCulling = false)
|
||||
if (Minosoft.config.config.game.entities.hitBox.disableZBuffer) {
|
||||
if (profile.showThroughWalls) {
|
||||
renderWindow.renderSystem.depth = DepthFunctions.ALWAYS
|
||||
}
|
||||
renderWindow.shaderManager.genericColorShader.use()
|
||||
@ -84,11 +148,12 @@ class EntityHitBoxRenderer(
|
||||
}
|
||||
|
||||
|
||||
companion object : RendererBuilder<EntityHitBoxRenderer> {
|
||||
override val RESOURCE_LOCATION = ResourceLocation("minosoft:entity_hit_box")
|
||||
companion object : RendererBuilder<EntityHitboxRenderer> {
|
||||
override val RESOURCE_LOCATION = ResourceLocation("minosoft:entity_hitbox")
|
||||
private val HITBOX_TOGGLE_KEY_COMBINATION = "minosoft:toggle_hitboxes".toResourceLocation()
|
||||
|
||||
override fun build(connection: PlayConnection, renderWindow: RenderWindow): EntityHitBoxRenderer {
|
||||
return EntityHitBoxRenderer(connection, renderWindow)
|
||||
override fun build(connection: PlayConnection, renderWindow: RenderWindow): EntityHitboxRenderer {
|
||||
return EntityHitboxRenderer(connection, renderWindow)
|
||||
}
|
||||
}
|
||||
}
|
@ -130,9 +130,9 @@ class HUDRenderer(
|
||||
|
||||
renderWindow.inputHandler.registerKeyCallback("minosoft:enable_hud".toResourceLocation(), KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.STICKY_INVERTED to mutableSetOf(KeyCodes.KEY_F1),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_F1),
|
||||
),
|
||||
)) { enabled = it }
|
||||
), defaultPressed = enabled) { enabled = it }
|
||||
}
|
||||
|
||||
override fun postInit() {
|
||||
|
@ -49,12 +49,13 @@ class RenderWindowInputHandler(
|
||||
val interactionManager = InteractionManager(renderWindow)
|
||||
|
||||
init {
|
||||
registerKeyCallback("minosoft:debug_mouse_catch".toResourceLocation(), KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_M),
|
||||
),
|
||||
)) {
|
||||
registerKeyCallback("minosoft:debug_mouse_catch".toResourceLocation(),
|
||||
KeyBinding(
|
||||
mutableMapOf(
|
||||
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
|
||||
KeyAction.STICKY to mutableSetOf(KeyCodes.KEY_M),
|
||||
),
|
||||
)) {
|
||||
renderWindow.window.cursorMode = it.decide(CursorModes.DISABLED, CursorModes.NORMAL)
|
||||
renderWindow.sendDebugMessage("Toggled mouse catch!")
|
||||
}
|
||||
@ -140,27 +141,19 @@ class RenderWindowInputHandler(
|
||||
checksRun++
|
||||
}
|
||||
|
||||
fun checkSticky(keys: MutableSet<KeyCodes>) {
|
||||
pair.keyBinding.action[KeyAction.STICKY]?.let {
|
||||
checksRun++
|
||||
if (!keys.contains(keyCode)) {
|
||||
if (!it.contains(keyCode)) {
|
||||
thisIsChange = false
|
||||
return
|
||||
return@let
|
||||
}
|
||||
if (!keyDown) {
|
||||
thisIsChange = false
|
||||
return
|
||||
return@let
|
||||
}
|
||||
thisKeyBindingDown = !keyBindingsDown.contains(resourceLocation)
|
||||
}
|
||||
|
||||
pair.keyBinding.action[KeyAction.STICKY]?.let {
|
||||
checkSticky(it)
|
||||
}
|
||||
|
||||
pair.keyBinding.action[KeyAction.STICKY_INVERTED]?.let {
|
||||
checkSticky(it)
|
||||
}
|
||||
|
||||
pair.keyBinding.action[KeyAction.DOUBLE_PRESS]?.let {
|
||||
checksRun++
|
||||
if (!keyDown) {
|
||||
@ -220,7 +213,7 @@ class RenderWindowInputHandler(
|
||||
//currentKeyConsumer?.charInput(char.toChar())
|
||||
}
|
||||
|
||||
fun registerKeyCallback(resourceLocation: ResourceLocation, defaultKeyBinding: KeyBinding, callback: ((keyDown: Boolean) -> Unit)) {
|
||||
fun registerKeyCallback(resourceLocation: ResourceLocation, defaultKeyBinding: KeyBinding, defaultPressed: Boolean = false, callback: ((keyDown: Boolean) -> Unit)) {
|
||||
val keyBinding = Minosoft.config.config.game.controls.keyBindings.entries.getOrPut(resourceLocation) { defaultKeyBinding } // ToDo (Performance): Should the defaultKeyBinding be a lambda parameter?
|
||||
val callbackPair = keyBindingCallbacks.getOrPut(resourceLocation) { KeyBindingCallbackPair(keyBinding) }
|
||||
if (keyBinding.ignoreConsumer) {
|
||||
@ -233,12 +226,9 @@ class RenderWindowInputHandler(
|
||||
callback(it)
|
||||
}
|
||||
}
|
||||
// Instant fire
|
||||
if (keyBinding.action.containsKey(KeyAction.STICKY)) {
|
||||
callback(false)
|
||||
} else if (keyBinding.action.containsKey(KeyAction.STICKY_INVERTED)) {
|
||||
|
||||
if (keyBinding.action.containsKey(KeyAction.STICKY) && defaultPressed) {
|
||||
keyBindingsDown += resourceLocation
|
||||
callback(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.*;
|
||||
|
||||
@Deprecated
|
||||
@Deprecated(forRemoval = true)
|
||||
public final class Util {
|
||||
public static final Pattern UUID_FIX_PATTERN = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); // thanks https://www.spigotmc.org/threads/free-code-easily-convert-between-trimmed-and-full-uuids.165615
|
||||
public static final char[] RANDOM_STRING_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||
|
Loading…
x
Reference in New Issue
Block a user