From eddca17bf2c8542458ba00c88e17470dff9c529f Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sat, 5 Jun 2021 22:56:35 +0200 Subject: [PATCH] particles: `enchant`, `nautilus`, `witch`, wip stepping This reduces the warnings in lobbies on hypixel --- .../data/physics/CollisionDetector.kt | 26 +++++++-- .../particle/DefaultParticleFactory.kt | 6 +++ .../texture/simple/enchant/EnchantParticle.kt | 32 +++++++++++ .../simple/enchant/EnchantedGlyphParticle.kt | 54 +++++++++++++++++++ .../simple/enchant/NautilusParticle.kt | 32 +++++++++++ .../texture/simple/spell/WitchParticle.kt | 38 +++++++++++++ .../s2c/play/PositionAndRotationS2CP.kt | 3 +- 7 files changed, 184 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/EnchantParticle.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/EnchantedGlyphParticle.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/NautilusParticle.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/spell/WitchParticle.kt diff --git a/src/main/java/de/bixilon/minosoft/data/physics/CollisionDetector.kt b/src/main/java/de/bixilon/minosoft/data/physics/CollisionDetector.kt index 31c4cd595..a1936e42f 100644 --- a/src/main/java/de/bixilon/minosoft/data/physics/CollisionDetector.kt +++ b/src/main/java/de/bixilon/minosoft/data/physics/CollisionDetector.kt @@ -83,7 +83,8 @@ class CollisionDetector(val connection: PlayConnection) { return movement } - fun collide(physicsEntity: PhysicsEntity?, deltaPosition: Vec3, aabb: AABB, collisionsToCheck: VoxelShape = connection.collisionDetector.getCollisionsToCheck(deltaPosition, aabb)): Vec3 { + fun collide(physicsEntity: PhysicsEntity?, deltaPosition: Vec3, aabb: AABB, stepping: Boolean = false, collisionsToCheck: VoxelShape = connection.collisionDetector.getCollisionsToCheck(deltaPosition, aabb)): Vec3 { + // ToDo: Check world border collision val delta = Vec3(deltaPosition) if (delta.y != 0.0f) { delta.y = collisionsToCheck.computeOffset(aabb, deltaPosition.y, Axes.Y) @@ -95,22 +96,33 @@ class CollisionDetector(val connection: PlayConnection) { it.onGround = true } } - aabb += Vec3(0f, delta.y, 0f) + aabb += Vec3(0.0f, delta.y, 0.0f) } else if (delta.y < 0) { physicsEntity?.let { it.onGround = false } } } + if (false && stepping && (deltaPosition.x != 0.0f || deltaPosition.z != 0.0f)) { + val testDelta = Vec3(delta) + testDelta.y = PhysicsConstants.STEP_HEIGHT + val stepMovementY = collisionsToCheck.computeOffset(aabb + testDelta, -PhysicsConstants.STEP_HEIGHT, Axes.Y) + if (stepMovementY < 0.0f && stepMovementY >= -PhysicsConstants.STEP_HEIGHT) { + testDelta.y = PhysicsConstants.STEP_HEIGHT + stepMovementY + aabb += Vec3(0.0f, testDelta.y, 0.0f) + delta.y += testDelta.y + } + } + val xPriority = delta.x > delta.z if (delta.x != 0.0f && xPriority) { delta.x = collisionsToCheck.computeOffset(aabb, deltaPosition.x, Axes.X) - aabb += Vec3(delta.x, 0f, 0f) + aabb += Vec3(delta.x, 0.0f, 0.0f) if (delta.x != deltaPosition.x) { physicsEntity?.let { it.velocity.x = 0.0f } } } if (delta.z != 0.0f) { delta.z = collisionsToCheck.computeOffset(aabb, deltaPosition.z, Axes.Z) - aabb += Vec3(0f, 0f, delta.z) + aabb += Vec3(0.0f, 0.0f, delta.z) if (delta.z != deltaPosition.z) { physicsEntity?.let { it.velocity.z = 0.0f } } @@ -122,7 +134,11 @@ class CollisionDetector(val connection: PlayConnection) { physicsEntity?.let { it.velocity.x = 0.0f } } } - if (delta.length() > deltaPosition.length()) { + var length = deltaPosition.length() + if (stepping) { + length += PhysicsConstants.STEP_HEIGHT + } + if (delta.length() > length) { return Vec3.EMPTY // abort all movement if the collision system would move the entity further than wanted } return delta 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 b8a4388f7..86349aa46 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 @@ -21,10 +21,13 @@ import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.Ca import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.ExplosionParticle 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.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 import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.suspend.DolphinParticle object DefaultParticleFactory : DefaultFactory>( @@ -40,4 +43,7 @@ object DefaultParticleFactory : DefaultFactory>( AmbientEntityEffectParticle, BlockDustParticle, EnchantedHitParticle, + WitchParticle, + EnchantParticle, + NautilusParticle, ) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/EnchantParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/EnchantParticle.kt new file mode 100644 index 000000000..caa5730de --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/EnchantParticle.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.enchant + +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.Vec3 + +class EnchantParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData? = null) : EnchantedGlyphParticle(connection, position, velocity, data) { + + companion object : ParticleFactory { + override val RESOURCE_LOCATION: ResourceLocation = "minecraft:enchant".asResourceLocation() + + override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): EnchantParticle { + return EnchantParticle(connection, position, velocity, data) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/EnchantedGlyphParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/EnchantedGlyphParticle.kt new file mode 100644 index 000000000..87571ba5c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/EnchantedGlyphParticle.kt @@ -0,0 +1,54 @@ +/* + * 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.enchant + +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.gui.rendering.util.VecUtil.assign +import de.bixilon.minosoft.protocol.network.connection.PlayConnection +import glm_.pow +import glm_.vec3.Vec3 + +abstract class EnchantedGlyphParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData? = null) : SimpleTextureParticle(connection, position, Vec3.EMPTY, data) { + private val startPosition = Vec3(position) + + init { + this.velocity assign velocity + + super.scale = 0.1f * (random.nextFloat() * 0.5f + 0.2f) + + val colorMultiplier = random.nextFloat() * 0.6f + 0.4f + this.color = RGBColor(colorMultiplier * 0.9f, colorMultiplier * 0.9f, colorMultiplier) + + this.physics = false + + this.maxAge = (random.nextFloat() * 10.0f).toInt() + 30 + movement = false + spriteDisabled = true + setRandomSprite() + } + + override fun postTick(deltaTime: Int) { + super.postTick(deltaTime) + if (dead) { + return + } + val ageDivisor = 1.0f - floatAge / maxAge + val ageDivisor2 = (1.0f - ageDivisor).pow(3) + this.position assign (startPosition + velocity * ageDivisor) + this.position.y -= ageDivisor2 * 1.2f + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/NautilusParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/NautilusParticle.kt new file mode 100644 index 000000000..da5d2c915 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/enchant/NautilusParticle.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.enchant + +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.Vec3 + +class NautilusParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData? = null) : EnchantedGlyphParticle(connection, position, velocity, data) { + + companion object : ParticleFactory { + override val RESOURCE_LOCATION: ResourceLocation = "minecraft:nautilus".asResourceLocation() + + override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): NautilusParticle { + return NautilusParticle(connection, position, velocity, data) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/spell/WitchParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/spell/WitchParticle.kt new file mode 100644 index 000000000..90140ab50 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/spell/WitchParticle.kt @@ -0,0 +1,38 @@ +/* + * 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.spell + +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.Vec3 + +class WitchParticle(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData? = null) : SpellParticle(connection, position, velocity, data) { + + init { + val randomColor = random.nextFloat() * 0.5f + 0.35f + color = RGBColor(red = randomColor, green = 0.0f, blue = randomColor) + } + + companion object : ParticleFactory { + override val RESOURCE_LOCATION: ResourceLocation = "minecraft:witch".asResourceLocation() + + override fun build(connection: PlayConnection, position: Vec3, velocity: Vec3, data: ParticleData): WitchParticle { + return WitchParticle(connection, position, velocity, data) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PositionAndRotationS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PositionAndRotationS2CP.kt index 7354317b9..dccae13bf 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PositionAndRotationS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PositionAndRotationS2CP.kt @@ -77,9 +77,8 @@ class PositionAndRotationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { if (connection.version.versionId >= ProtocolVersions.V_15W42A) { connection.sendPacket(TeleportConfirmC2SP(teleportId)) - } else { - connection.sendPacket(PositionAndRotationC2SP(position, rotation, isOnGround)) } + connection.sendPacket(PositionAndRotationC2SP(position, rotation, isOnGround)) } override fun log() {