don't render local hitbox

This commit is contained in:
Moritz Zwerger 2023-10-24 21:20:46 +02:00
parent 5ee928ac87
commit 3f3d34d100
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 63 additions and 10 deletions

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 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.
*
@ -22,11 +22,6 @@ class HitboxC(profile: EntityProfile) {
*/
var enabled by BooleanDelegate(profile, true)
/**
* Shows your own hit-box when in first person view
*/
var showLocal by BooleanDelegate(profile, false)
/**
* Shows hit-boxes from invisible entities
*/

View File

@ -36,6 +36,9 @@ import de.bixilon.minosoft.data.registries.item.items.dye.DyeableItem
import de.bixilon.minosoft.data.registries.shapes.aabb.AABB
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
import de.bixilon.minosoft.gui.rendering.entities.renderer.player.PlayerRenderer
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
import de.bixilon.minosoft.physics.entities.living.player.PlayerPhysics
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
@ -136,7 +139,7 @@ abstract class PlayerEntity(
}
override fun createPhysics(): PlayerPhysics<*> = PlayerPhysics(this)
override fun createRenderer(renderer: EntitiesRenderer): EntityRenderer<*> = PlayerRenderer(renderer, this)
fun swingHand(hand: Hands) {
val arm = hand.getArm(mainArm)

View File

@ -27,6 +27,9 @@ import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.data.entities.entities.player.additional.PlayerAdditional
import de.bixilon.minosoft.data.entities.entities.player.compass.CompassPosition
import de.bixilon.minosoft.data.registries.effects.attributes.integrated.IntegratedAttributeModifiers
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
import de.bixilon.minosoft.gui.rendering.entities.renderer.player.LocalPlayerRenderer
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
import de.bixilon.minosoft.input.camera.MovementInputActions
import de.bixilon.minosoft.input.camera.PlayerMovementInput
@ -109,4 +112,6 @@ class LocalPlayerEntity(
override fun createPhysics() = LocalPlayerPhysics(this)
override fun physics(): LocalPlayerPhysics = super.physics().unsafeCast()
override fun createRenderer(renderer: EntitiesRenderer): EntityRenderer<*> = LocalPlayerRenderer(renderer, this)
}

View File

@ -24,6 +24,11 @@ class FeatureManager(val renderer: EntityRenderer<*>) : Iterable<EntityRenderFea
this.features += feature
}
operator fun minusAssign(feature: EntityRenderFeature) = remove(feature)
fun remove(feature: EntityRenderFeature) {
this.features -= feature
}
fun update(millis: Long) {
for (feature in features) {
feature.update(millis)

View File

@ -43,6 +43,7 @@ class HitboxFeature(renderer: EntityRenderer<*>) : EntityRenderFeature(renderer)
override fun update(millis: Long) {
if (!manager.enabled) return unload()
if (!enabled) return unload()
val offset = renderer.renderer.context.camera.offset.offset

View File

@ -37,8 +37,7 @@ class HitboxManager(private val renderer: EntitiesRenderer) {
renderer.context.input.bindings.register(TOGGLE, KeyBinding(
KeyActions.MODIFIER to setOf(KeyCodes.KEY_F3),
KeyActions.STICKY to setOf(KeyCodes.KEY_B),
), pressed = enabled
) {
), pressed = enabled) {
profile.enabled = it
renderer.connection.util.sendDebugMessage("Entity hit boxes: ${it.format()}")
enabled = it

View File

@ -22,7 +22,7 @@ import de.bixilon.minosoft.gui.rendering.entities.visibility.EntityVisibility
abstract class EntityRenderer<E : Entity>(
val renderer: EntitiesRenderer,
val entity: Entity,
val entity: E,
) {
val features = FeatureManager(this)
val visibility = EntityVisibility(this)

View File

@ -0,0 +1,25 @@
/*
* Minosoft
* Copyright (C) 2020-2023 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.gui.rendering.entities.renderer.player
import de.bixilon.kutil.observer.DataObserver.Companion.observe
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
open class LocalPlayerRenderer(renderer: EntitiesRenderer, entity: LocalPlayerEntity) : PlayerRenderer<LocalPlayerEntity>(renderer, entity) {
init {
renderer.context.camera.view::view.observe(this, instant = true) { hitbox.enabled = it.renderSelf }
}
}

View File

@ -0,0 +1,20 @@
/*
* Minosoft
* Copyright (C) 2020-2023 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.gui.rendering.entities.renderer.player
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
open class PlayerRenderer<E : PlayerEntity>(renderer: EntitiesRenderer, entity: E) : EntityRenderer<E>(renderer, entity)