particles: flame, small_flame, soul_fire_flame, cloud, sneeze

This commit is contained in:
Bixilon 2021-06-06 17:10:03 +02:00
parent 2c852e5670
commit a95eb1b705
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
11 changed files with 309 additions and 8 deletions

View File

@ -23,7 +23,7 @@ import de.bixilon.minosoft.data.mappings.items.tools.ShovelItem
import de.bixilon.minosoft.data.mappings.versions.Registries
import de.bixilon.minosoft.data.player.Hands
import de.bixilon.minosoft.gui.rendering.input.camera.RaycastHit
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.CampfireSmokeParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.campfire.CampfireSmokeParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.fire.SmokeParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.lava.LavaParticle
import de.bixilon.minosoft.gui.rendering.util.VecUtil.horizontalPlus

View File

@ -13,9 +13,12 @@
package de.bixilon.minosoft.data.world
import de.bixilon.minosoft.data.abilities.Gamemodes
import de.bixilon.minosoft.data.entities.entities.Entity
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
import de.bixilon.minosoft.util.KUtil.toSynchronizedMap
import glm_.vec3.Vec3d
import java.util.*
class WorldEntities : Iterable<Entity> {
@ -75,4 +78,48 @@ class WorldEntities : Iterable<Entity> {
override fun iterator(): Iterator<Entity> {
return idEntityMap.toSynchronizedMap().values.iterator()
}
fun getInRadius(position: Vec3d, distance: Double, check: (Entity) -> Boolean): List<Entity> {
// ToDo: Improve performance
val ret: MutableList<Entity> = mutableListOf()
val entities = idEntityMap.toSynchronizedMap().values
for (entity in entities) {
if ((entity.position - position).length() > distance) {
continue
}
if (check(entity)) {
ret += entity
}
}
return ret.toList()
}
fun getClosestInRadius(position: Vec3d, distance: Double, check: (Entity) -> Boolean): Entity? {
val entities = getInRadius(position, distance, check)
var closestDistance = Double.MAX_VALUE
var closestEntity: Entity? = null
for (entity in entities) {
val currentDistance = (entity.position - position).length()
if (currentDistance < closestDistance) {
closestDistance = currentDistance
closestEntity = entity
}
}
return closestEntity
}
companion object {
val CHECK_CLOSEST_PLAYER: (Entity) -> Boolean = check@{
if (it !is PlayerEntity) {
return@check false
}
if (it.gamemode == Gamemodes.SPECTATOR) {
return@check false
}
return@check true
}
}
}

View File

@ -17,14 +17,19 @@ import de.bixilon.minosoft.data.mappings.DefaultFactory
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
import de.bixilon.minosoft.gui.rendering.particle.types.norender.ExplosionEmitterParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.advanced.block.BlockDustParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.CampfireSmokeParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.ExplosionParticle
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
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.damage.EnchantedHitParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.dust.DustParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.enchant.EnchantParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.enchant.NautilusParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.fire.SmokeParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.lava.LavaParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.slowing.FlameParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.slowing.SmallFlameParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.slowing.SoulFireFlameParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.spell.AmbientEntityEffectParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.spell.EntityEffectParticle
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.spell.WitchParticle
@ -46,4 +51,9 @@ object DefaultParticleFactory : DefaultFactory<ParticleFactory<out Particle>>(
WitchParticle,
EnchantParticle,
NautilusParticle,
FlameParticle,
SmallFlameParticle,
SoulFireFlameParticle,
CloudParticle,
SneezeParticle,
)

View File

@ -33,7 +33,7 @@ import kotlin.reflect.full.companionObjectInstance
abstract class Particle(
protected val connection: PlayConnection,
final override val position: Vec3d,
final override val velocity: Vec3d = Vec3d.EMPTY,
velocity: Vec3d = Vec3d.EMPTY,
data: ParticleData? = null,
) : PhysicsEntity {
protected val data: ParticleData = data ?: let {
@ -52,6 +52,7 @@ abstract class Particle(
var maxAge: Int = (4.0f / (random.nextFloat() * 0.9f + 0.1f)).toInt()
// moving
final override val velocity: Vec3d = Vec3d(velocity)
var previousPosition = position
var movement: Boolean = true
var physics: Boolean = true
@ -82,12 +83,12 @@ abstract class Particle(
init {
velocity += { (random.nextDouble() * 2.0 - 1.0) * MAGIC_VELOCITY_CONSTANT }
this.velocity += { (random.nextDouble() * 2.0 - 1.0) * MAGIC_VELOCITY_CONSTANT }
val modifier = (random.nextFloat() + random.nextFloat() + 1.0f) * 0.15000000596046448
val divider = velocity.length()
val divider = this.velocity.length()
velocity assign velocity / divider * modifier * MAGIC_VELOCITY_CONSTANTf
velocity.y += 0.10000000149011612
this.velocity assign this.velocity / divider * modifier * MAGIC_VELOCITY_CONSTANTf
this.velocity.y += 0.10000000149011612
spacing = Vec3(0.2)
}

View File

@ -11,11 +11,12 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple
package de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.campfire
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
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.gui.rendering.util.VecUtil.assign
import de.bixilon.minosoft.gui.rendering.util.VecUtil.millis

View File

@ -0,0 +1,67 @@
/*
* 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.gui.rendering.particle.types.render.texture.simple.cloud
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
import de.bixilon.minosoft.data.text.RGBColor.Companion.asGray
import de.bixilon.minosoft.data.world.WorldEntities
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
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 de.bixilon.minosoft.util.KUtil.asResourceLocation
import glm_.vec3.Vec3d
import java.lang.Float.max
open class CloudParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : SimpleTextureParticle(connection, position, Vec3d.EMPTY, data) {
init {
friction = 0.96f
this.velocity *= 0.10000000149011612
this.velocity += velocity
this.color = (1.0f - random.nextFloat() * 0.30000001192092896f).asGray()
super.scale *= 1.875f
maxAge = max((8.0f / (random.nextFloat() * 0.8f + 0.3f)).toInt() * 2.5f, 1.0f).toInt()
physics = false
}
override fun realTick() {
super.realTick()
if (dead) {
return
}
connection.world.entities.getClosestInRadius(position, 2.0, WorldEntities.CHECK_CLOSEST_PLAYER)?.let {
val y = it.position.y
if (this.position.y <= y) {
return@let
}
this.position.y += (y - this.position.y) * 0.2
this.velocity.y += (it.velocity.y - this.velocity.y) * 0.2
}
}
companion object : ParticleFactory<CloudParticle> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:cloud".asResourceLocation()
override fun build(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData): CloudParticle {
return CloudParticle(connection, position, velocity, data)
}
}
}

View File

@ -0,0 +1,37 @@
/*
* 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.gui.rendering.particle.types.render.texture.simple.cloud
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
import de.bixilon.minosoft.data.text.RGBColor
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.KUtil.asResourceLocation
import glm_.vec3.Vec3d
open class SneezeParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : CloudParticle(connection, position, velocity, data) {
init {
color = RGBColor(200, 50, 120, 102)
}
companion object : ParticleFactory<SneezeParticle> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:sneeze".asResourceLocation()
override fun build(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData): SneezeParticle {
return SneezeParticle(connection, position, velocity, data)
}
}
}

View File

@ -0,0 +1,39 @@
/*
* 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.gui.rendering.particle.types.render.texture.simple.slowing
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.KUtil.asResourceLocation
import glm_.vec3.Vec3d
import kotlin.math.pow
open class FlameParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : SlowingParticle(connection, position, velocity, data) {
override var scale: Float
get() = super.scale * (1.0f - (floatAge / maxAge).pow(2) * 0.5f)
set(value) {
super.scale = value
}
companion object : ParticleFactory<FlameParticle> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:flame".asResourceLocation()
override fun build(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData): FlameParticle {
return FlameParticle(connection, position, velocity, data)
}
}
}

View File

@ -0,0 +1,31 @@
/*
* 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.gui.rendering.particle.types.render.texture.simple.slowing
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.SimpleTextureParticle
import de.bixilon.minosoft.gui.rendering.util.VecUtil.assign
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plusAssign
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import glm_.vec3.Vec3d
abstract class SlowingParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : SimpleTextureParticle(connection, position, velocity, data) {
init {
friction = 0.96f
this.velocity assign (this.velocity * 0.009999999776482582 + velocity)
this.position += { random.nextDouble() - random.nextDouble() * 0.05 }
maxAge = (8.0 / (random.nextDouble() * 0.8 + 0.2)).toInt() + 4
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.gui.rendering.particle.types.render.texture.simple.slowing
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.KUtil.asResourceLocation
import glm_.vec3.Vec3d
class SmallFlameParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : FlameParticle(connection, position, velocity, data) {
init {
scale *= 0.5f
}
companion object : ParticleFactory<SmallFlameParticle> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:small_flame".asResourceLocation()
override fun build(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData): SmallFlameParticle {
return SmallFlameParticle(connection, position, velocity, data)
}
}
}

View File

@ -0,0 +1,32 @@
/*
* 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.gui.rendering.particle.types.render.texture.simple.slowing
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.KUtil.asResourceLocation
import glm_.vec3.Vec3d
class SoulFireFlameParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : FlameParticle(connection, position, velocity, data) {
companion object : ParticleFactory<SoulFireFlameParticle> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:soul_fire_flame".asResourceLocation()
override fun build(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData): SoulFireFlameParticle {
return SoulFireFlameParticle(connection, position, velocity, data)
}
}
}