From 38297daf212da95dc56059a8c95da705c7a1ee94 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Thu, 10 Jun 2021 21:32:24 +0200 Subject: [PATCH] particles: `end_rod` --- .../particle/DefaultParticleFactory.kt | 2 + .../simple/animated/AnimatedParticle.kt | 46 +++++++++++++++++++ .../texture/simple/animated/EndRodParticle.kt | 43 +++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/animated/AnimatedParticle.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/animated/EndRodParticle.kt diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/DefaultParticleFactory.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/DefaultParticleFactory.kt index 502d0cf98..0abb8904a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/DefaultParticleFactory.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/DefaultParticleFactory.kt @@ -20,6 +20,7 @@ import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.advanced. import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.ExplosionParticle import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.NoteParticle import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.PortalParticle +import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.animated.EndRodParticle import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.campfire.CampfireSmokeParticle import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.cloud.CloudParticle import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.cloud.SneezeParticle @@ -78,4 +79,5 @@ object DefaultParticleFactory : DefaultFactory>( PortalParticle, HeartParticle, AngryVillagerParticle, + EndRodParticle, ) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/animated/AnimatedParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/animated/AnimatedParticle.kt new file mode 100644 index 000000000..8418d1eab --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/animated/AnimatedParticle.kt @@ -0,0 +1,46 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.animated + +import de.bixilon.minosoft.data.mappings.particle.data.ParticleData +import de.bixilon.minosoft.data.text.RGBColor +import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.SimpleTextureParticle +import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY +import de.bixilon.minosoft.protocol.network.connection.PlayConnection +import glm_.vec3.Vec3d + +abstract class AnimatedParticle(connection: PlayConnection, position: Vec3d, gravityStrength: Float, data: ParticleData? = null) : SimpleTextureParticle(connection, position, Vec3d.EMPTY, data) { + var targetColor: RGBColor? = null + + init { + this.friction = 0.91f + this.gravityStrength = gravityStrength + } + + override fun tick() { + super.tick() + + if (age > maxAge / 2) { + color = color.with(alpha = (floatAge - (maxAge / 2)) / maxAge) + + targetColor?.let { + this.color = this.color.with( + red = this.color.floatRed + (it.floatRed - this.color.floatRed) * 0.2f, + green = this.color.floatGreen + (it.floatGreen - this.color.floatGreen) * 0.2f, + blue = this.color.floatBlue + (it.floatBlue - this.color.floatBlue) * 0.2f, + ) + } + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/animated/EndRodParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/animated/EndRodParticle.kt new file mode 100644 index 000000000..c5ca9f12e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/animated/EndRodParticle.kt @@ -0,0 +1,43 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.animated + +import de.bixilon.minosoft.data.mappings.ResourceLocation +import de.bixilon.minosoft.data.mappings.particle.data.ParticleData +import de.bixilon.minosoft.data.text.RGBColor.Companion.asRGBColor +import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory +import de.bixilon.minosoft.gui.rendering.util.VecUtil.assign +import de.bixilon.minosoft.protocol.network.connection.PlayConnection +import de.bixilon.minosoft.util.KUtil.asResourceLocation +import glm_.vec3.Vec3d + +class EndRodParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : AnimatedParticle(connection, position, 0.0125f, data) { + + init { + this.velocity assign velocity + + this.scale *= 0.75f + this.maxAge = 60 + random.nextInt(12) + + targetColor = 15916745.asRGBColor() + } + + companion object : ParticleFactory { + override val RESOURCE_LOCATION: ResourceLocation = "minecraft:end_rod".asResourceLocation() + + override fun build(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData): EndRodParticle { + return EndRodParticle(connection, position, velocity, data) + } + } +}