diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/CampfireBlock.kt b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/CampfireBlock.kt index f3207150b..2566b4dd1 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/CampfireBlock.kt +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/types/CampfireBlock.kt @@ -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 diff --git a/src/main/java/de/bixilon/minosoft/data/world/WorldEntities.kt b/src/main/java/de/bixilon/minosoft/data/world/WorldEntities.kt index e68653833..541af1b05 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/WorldEntities.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/WorldEntities.kt @@ -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 { @@ -75,4 +78,48 @@ class WorldEntities : Iterable { override fun iterator(): Iterator { return idEntityMap.toSynchronizedMap().values.iterator() } + + fun getInRadius(position: Vec3d, distance: Double, check: (Entity) -> Boolean): List { + // ToDo: Improve performance + val ret: MutableList = 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 + } + } } 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 86349aa46..8aa7ebbb0 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 @@ -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>( WitchParticle, EnchantParticle, NautilusParticle, + FlameParticle, + SmallFlameParticle, + SoulFireFlameParticle, + CloudParticle, + SneezeParticle, ) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/Particle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/Particle.kt index 0d87918b1..da59377bb 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/Particle.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/Particle.kt @@ -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) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/CampfireSmokeParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/campfire/CampfireSmokeParticle.kt similarity index 96% rename from src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/CampfireSmokeParticle.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/campfire/CampfireSmokeParticle.kt index edaa20f04..8376816f0 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/CampfireSmokeParticle.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/campfire/CampfireSmokeParticle.kt @@ -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 diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/cloud/CloudParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/cloud/CloudParticle.kt new file mode 100644 index 000000000..a69003264 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/cloud/CloudParticle.kt @@ -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 . + * + * 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 { + 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) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/cloud/SneezeParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/cloud/SneezeParticle.kt new file mode 100644 index 000000000..09ed14e06 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/cloud/SneezeParticle.kt @@ -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 . + * + * 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 { + 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) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/FlameParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/FlameParticle.kt new file mode 100644 index 000000000..ef08a0320 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/FlameParticle.kt @@ -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 . + * + * 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 { + 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) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SlowingParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SlowingParticle.kt new file mode 100644 index 000000000..5c147fe75 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SlowingParticle.kt @@ -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 . + * + * 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 + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SmallFlameParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SmallFlameParticle.kt new file mode 100644 index 000000000..f1368275e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SmallFlameParticle.kt @@ -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 . + * + * 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 { + 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) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SoulFireFlameParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SoulFireFlameParticle.kt new file mode 100644 index 000000000..8e8826a2c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/slowing/SoulFireFlameParticle.kt @@ -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 . + * + * 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 { + 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) + } + } +}