mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-11 16:36:58 -04:00
entity renderer: damage
This commit is contained in:
parent
d33eb3bb6c
commit
b33696058f
@ -229,7 +229,7 @@ testing {
|
||||
val options = this as TestNGOptions
|
||||
options.preserveOrder = true
|
||||
// options.excludeGroups("models", "mesher", "chunk", "input", "font", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "block", "physics", "light", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "chunk_renderer", "rendering", "texture", "atlas", "gui")
|
||||
options.excludeGroups("models", "mesher", "chunk", "input", "font", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "block", "physics", "light", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "chunk_renderer", "texture", "atlas", "gui")
|
||||
options.excludeGroups("models", "chunk", "input", "font", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "physics", "light", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "chunk_renderer", "texture", "atlas", "gui")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.entities.entities
|
||||
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.minosoft.data.container.equipment.EntityEquipment
|
||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
||||
@ -22,6 +23,8 @@ import de.bixilon.minosoft.data.entities.data.EntityData
|
||||
import de.bixilon.minosoft.data.entities.data.EntityDataField
|
||||
import de.bixilon.minosoft.data.entities.entities.player.Hands
|
||||
import de.bixilon.minosoft.data.entities.entities.properties.StatusEffectProperty
|
||||
import de.bixilon.minosoft.data.entities.event.events.damage.DamageEvent
|
||||
import de.bixilon.minosoft.data.entities.event.events.damage.DamageListener
|
||||
import de.bixilon.minosoft.data.registries.effects.attributes.EntityAttributes
|
||||
import de.bixilon.minosoft.data.registries.effects.attributes.MinecraftAttributes
|
||||
import de.bixilon.minosoft.data.registries.entities.EntityType
|
||||
@ -33,7 +36,7 @@ import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.sp
|
||||
import de.bixilon.minosoft.physics.entities.living.LivingEntityPhysics
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
|
||||
abstract class LivingEntity(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : Entity(connection, entityType, data, position, rotation) {
|
||||
abstract class LivingEntity(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : Entity(connection, entityType, data, position, rotation), DamageListener {
|
||||
private val entityEffectParticle = connection.registries.particleType[EntityEffectParticle]
|
||||
private val ambientEntityEffectParticle = connection.registries.particleType[AmbientEntityEffectParticle]
|
||||
|
||||
@ -109,6 +112,10 @@ abstract class LivingEntity(connection: PlayConnection, entityType: EntityType,
|
||||
|
||||
override fun physics(): LivingEntityPhysics<*> = super.physics().unsafeCast()
|
||||
|
||||
override fun onDamage(type: DamageEvent) {
|
||||
this.renderer?.nullCast<DamageListener>()?.onDamage(type)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val FLAGS_DATA = EntityDataField("LIVING_ENTITY_FLAGS")
|
||||
private val HEALTH_DATA = EntityDataField("LIVING_ENTITY_HEALTH")
|
||||
|
@ -19,6 +19,6 @@ import de.bixilon.minosoft.data.entities.event.EntityEvent
|
||||
interface DamageEvent : EntityEvent<LivingEntity> {
|
||||
|
||||
override fun handle(entity: LivingEntity) {
|
||||
// TODO
|
||||
entity.onDamage(this)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.data.entities.event.events.damage
|
||||
|
||||
fun interface DamageListener {
|
||||
|
||||
fun onDamage(type: DamageEvent) // TODO: DamageType
|
||||
}
|
@ -13,6 +13,8 @@
|
||||
|
||||
package de.bixilon.minosoft.data.text.formatting.color
|
||||
|
||||
import de.bixilon.kutil.math.interpolation.FloatInterpolation
|
||||
|
||||
object ColorUtil {
|
||||
|
||||
fun mixColors(vararg colors: Int): Int {
|
||||
@ -38,7 +40,7 @@ object ColorUtil {
|
||||
return (start.toFloat() + delta * (end.toFloat() - start.toFloat())).toInt()
|
||||
}
|
||||
|
||||
fun interpolateRGB(delta: Float, start: RGBColor, end: RGBColor): RGBColor {
|
||||
fun interpolateRGB(delta: Float, start: RGBColor, end: RGBColor, component: (Float, Float, Float) -> Float = FloatInterpolation::interpolateLinear): RGBColor {
|
||||
if (delta <= 0.0f) return start
|
||||
if (delta >= 1.0f) return end
|
||||
|
||||
|
@ -64,7 +64,8 @@ open class SkeletalFeature(
|
||||
}
|
||||
|
||||
override fun draw() {
|
||||
instance.draw(renderer.light.value)
|
||||
val tint = renderer.light.value.mix(renderer.damage.value)
|
||||
instance.draw(tint)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
|
@ -48,7 +48,6 @@ class HitboxFeature(renderer: EntityRenderer<*>) : EntityRenderFeature(renderer)
|
||||
override fun update(millis: Long, delta: Float) {
|
||||
if (!manager.enabled) return unload()
|
||||
if (!enabled) return unload()
|
||||
if (!manager.profile.showInvisible && renderer.entity.isInvisible) return unload()
|
||||
if (!visible) return
|
||||
|
||||
val offset = renderer.renderer.context.camera.offset.offset
|
||||
|
@ -37,7 +37,7 @@ open class PlayerModel(
|
||||
|
||||
shader.use()
|
||||
shader.texture = renderer.skin?.shaderId ?: renderer.renderer.context.textures.debugTexture.shaderId
|
||||
shader.light = renderer.light.value
|
||||
shader.tint = renderer.light.value.mix(renderer.damage.value)
|
||||
shader.skinParts = this.skinParts
|
||||
|
||||
|
||||
|
@ -16,6 +16,8 @@ package de.bixilon.minosoft.gui.rendering.entities.renderer
|
||||
import de.bixilon.kotlinglm.mat4x4.Mat4
|
||||
import de.bixilon.kotlinglm.vec3.Vec3
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.entities.event.events.damage.DamageEvent
|
||||
import de.bixilon.minosoft.data.entities.event.events.damage.DamageListener
|
||||
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||
import de.bixilon.minosoft.data.text.formatting.color.ColorUtil
|
||||
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
|
||||
@ -31,13 +33,14 @@ import de.bixilon.minosoft.util.interpolate.Interpolator
|
||||
abstract class EntityRenderer<E : Entity>(
|
||||
val renderer: EntitiesRenderer,
|
||||
val entity: E,
|
||||
) {
|
||||
) : DamageListener {
|
||||
private var update = 0L
|
||||
val features = FeatureManager(this)
|
||||
val info = entity.renderInfo
|
||||
|
||||
val hitbox = HitboxFeature(this).register()
|
||||
val light = Interpolator(ChatColors.WHITE, ColorUtil::interpolateRGB)
|
||||
val damage = Interpolator(ChatColors.WHITE, ColorUtil::interpolateRGB) // TODO delta^2
|
||||
val matrix = Mat4()
|
||||
var visible = true
|
||||
protected set
|
||||
@ -62,6 +65,10 @@ abstract class EntityRenderer<E : Entity>(
|
||||
open fun update(millis: Long) {
|
||||
val delta = if (this.update <= 0L) 0.0f else ((millis - update) / 1000.0f)
|
||||
updateLight(delta)
|
||||
if (damage.delta > 1.0f) {
|
||||
damage.push(ChatColors.WHITE)
|
||||
}
|
||||
damage.add(delta, 0.05f)
|
||||
entity.draw(millis)
|
||||
updateMatrix(delta)
|
||||
features.update(millis, delta)
|
||||
@ -96,4 +103,8 @@ abstract class EntityRenderer<E : Entity>(
|
||||
this.visible = visible && !entity.isInvisible
|
||||
features.updateVisibility(occluded)
|
||||
}
|
||||
|
||||
override fun onDamage(type: DamageEvent) {
|
||||
damage.push(ChatColors.RED)
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,13 @@
|
||||
package de.bixilon.minosoft.gui.rendering.entities.renderer.living.player
|
||||
|
||||
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||
import de.bixilon.minosoft.gui.rendering.shader.types.TintedShader
|
||||
import de.bixilon.minosoft.gui.rendering.skeletal.shader.BaseSkeletalShader
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.FloatUniformBuffer
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader
|
||||
|
||||
class PlayerShader(native: NativeShader, buffer: FloatUniformBuffer) : BaseSkeletalShader(native, buffer) {
|
||||
class PlayerShader(native: NativeShader, buffer: FloatUniformBuffer) : BaseSkeletalShader(native, buffer), TintedShader {
|
||||
var texture by uniform("uIndexLayer", 0x00, NativeShader::setUInt)
|
||||
var light by uniform("uLight", ChatColors.WHITE) { shader, name, value -> shader.setUInt(name, value.rgb) }
|
||||
override var tint by uniform("uTintColor", ChatColors.WHITE) { shader, name, value -> shader.setUInt(name, value.rgb) }
|
||||
var skinParts by uniform("uSkinParts", 0xFF, NativeShader::setUInt)
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.shader.types
|
||||
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.shader.AbstractShader
|
||||
|
||||
interface TintedShader : AbstractShader {
|
||||
var tint: RGBColor
|
||||
}
|
@ -41,11 +41,11 @@ class SkeletalInstance(
|
||||
draw(shader)
|
||||
}
|
||||
|
||||
fun draw(light: RGBColor) {
|
||||
fun draw(tint: RGBColor) {
|
||||
context.system.reset(faceCulling = false)
|
||||
val shader = context.skeletal.shader
|
||||
shader.use()
|
||||
shader.light = light
|
||||
shader.tint = tint
|
||||
draw(shader)
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,10 @@ package de.bixilon.minosoft.gui.rendering.skeletal.shader
|
||||
|
||||
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||
import de.bixilon.minosoft.gui.rendering.shader.types.AnimatedShader
|
||||
import de.bixilon.minosoft.gui.rendering.shader.types.TintedShader
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.FloatUniformBuffer
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader
|
||||
|
||||
class SkeletalShader(native: NativeShader, buffer: FloatUniformBuffer) : BaseSkeletalShader(native, buffer), AnimatedShader {
|
||||
var light by uniform("uLight", ChatColors.WHITE) { shader, name, value -> shader.setUInt(name, value.rgb) }
|
||||
class SkeletalShader(native: NativeShader, buffer: FloatUniformBuffer) : BaseSkeletalShader(native, buffer), AnimatedShader, TintedShader {
|
||||
override var tint by uniform("uTintColor", ChatColors.WHITE) { shader, name, value -> shader.setUInt(name, value.rgb) }
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ out vec3 finFragmentPosition;
|
||||
|
||||
|
||||
uniform uint uIndexLayer;
|
||||
uniform uint uLight;
|
||||
uniform uint uTintColor;
|
||||
uniform uint uSkinParts;
|
||||
|
||||
flat out uint finAllowTransparency;
|
||||
@ -45,7 +45,7 @@ void main() {
|
||||
}
|
||||
finAllowTransparency = skinPart;
|
||||
run_skeletal(partTransformNormal, vinPosition);
|
||||
vec4 light = getRGBColor(uLight & 0xFFFFFFu);
|
||||
vec4 light = getRGBColor(uTintColor & 0xFFFFFFu);
|
||||
finTintColor *= light;
|
||||
|
||||
finTextureIndex = uIndexLayer >> 28u;
|
||||
|
@ -28,12 +28,12 @@ layout (location = 3) in float vinIndexLayerAnimation;// texture index (0xF00000
|
||||
|
||||
#include "minosoft:color"
|
||||
|
||||
uniform uint uLight;
|
||||
uniform uint uTintColor;
|
||||
|
||||
|
||||
void main() {
|
||||
run_skeletal(floatBitsToUint(vinTransformNormal), vinPosition);
|
||||
run_animation();
|
||||
|
||||
finTintColor *= getRGBColor(uLight & 0xFFFFFFu);
|
||||
finTintColor *= getRGBColor(uTintColor & 0xFFFFFFu);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user