From e38f1f1594b3f25acc64b3b578c8c3bccbfdc231 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 8 Oct 2021 15:47:12 +0200 Subject: [PATCH] constants improvements --- .../minosoft/data/entities/entities/Entity.kt | 8 ++++---- .../minosoft/data/player/LocalPlayerEntity.kt | 4 ++-- .../data/registries/fluid/lava/LavaFluid.kt | 2 +- .../data/registries/fluid/water/WaterFluid.kt | 2 +- .../other/containers/PlayerInventory.kt | 20 ++++++++++++------- .../gui/rendering/particle/types/Particle.kt | 6 +++--- .../texture/simple/cloud/CloudParticle.kt | 4 ++-- .../texture/simple/damage/DamageParticle.kt | 4 ++-- .../simple/dust/AbstractDustParticle.kt | 2 +- .../texture/simple/lava/LavaParticle.kt | 4 ++-- .../texture/simple/spell/SpellParticle.kt | 6 +++--- .../texture/simple/water/BubbleParticle.kt | 4 ++-- .../packets/s2c/play/HotbarSlotSetS2CP.kt | 7 +++++++ 13 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.kt index c3ad2f9c9..f33fa67e5 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.kt @@ -357,7 +357,7 @@ abstract class Entity( } private fun spawnSprintingParticles() { - val blockPosition = Vec3i(position.x.floor, (position.y - 0.20000000298023224).floor, position.z.floor) + val blockPosition = Vec3i(position.x.floor, (position.y - 0.2).floor, position.z.floor) val blockState = connection.world[blockPosition] ?: return // ToDo: Don't render particles for invisible blocks @@ -544,9 +544,9 @@ abstract class Entity( velocity /= checks } - if (abs(this.velocity.x) < 0.003 && abs(this.velocity.z) < 0.003 && velocity.length() < 0.0045000000000000005) { + if (abs(this.velocity.x) < 0.003 && abs(this.velocity.z) < 0.003 && velocity.length() < 0.0045) { velocity.normalizeAssign() - velocity *= 0.0045000000000000005 + velocity *= 0.0045 } this.velocity = (this.velocity + velocity) @@ -603,6 +603,6 @@ abstract class Entity( } companion object { - private val BELOW_POSITION_MINUS = Vec3(0, 0.20000000298023224f, 0) + private val BELOW_POSITION_MINUS = Vec3(0, 0.2f, 0) } } diff --git a/src/main/java/de/bixilon/minosoft/data/player/LocalPlayerEntity.kt b/src/main/java/de/bixilon/minosoft/data/player/LocalPlayerEntity.kt index 0fd664a8f..cb9e90a9b 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/LocalPlayerEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/player/LocalPlayerEntity.kt @@ -384,7 +384,7 @@ class LocalPlayerEntity( velocity.y += (0.05 * (it.amplifier + 1.0f) - velocity.y) * 0.2 // ToDo: This should be correct, but somehow are we to fast... } ?: let { if (connection.world[positionInfo.chunkPosition] == null) { - velocity.y = if (position.y > connection.world.dimension?.minY ?: 0) { + velocity.y = if (position.y > (connection.world.dimension?.minY ?: 0)) { -0.1 } else { 0.0 @@ -393,7 +393,7 @@ class LocalPlayerEntity( velocity.y -= gravity } } - this.velocity = velocity * Vec3d(speedMultiplier, 0.9800000190734863, speedMultiplier) + this.velocity = velocity * Vec3d(speedMultiplier, 0.98, speedMultiplier) } } } diff --git a/src/main/java/de/bixilon/minosoft/data/registries/fluid/lava/LavaFluid.kt b/src/main/java/de/bixilon/minosoft/data/registries/fluid/lava/LavaFluid.kt index d25ee3d39..8d8baa496 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/fluid/lava/LavaFluid.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/fluid/lava/LavaFluid.kt @@ -63,7 +63,7 @@ class LavaFluid( val fluidHeight = entity.fluidHeights[DefaultFluids.LAVA] ?: 0.0f if (fluidHeight <= entity.swimHeight) { - entity.velocity = entity.velocity * Vec3d(0.5, 0.800000011920929, 0.5) + entity.velocity = entity.velocity * Vec3d(0.5, 0.8, 0.5) entity.velocity = updateMovement(entity, gravity, falling, entity.velocity) } else { entity.velocity = entity.velocity * 0.5 diff --git a/src/main/java/de/bixilon/minosoft/data/registries/fluid/water/WaterFluid.kt b/src/main/java/de/bixilon/minosoft/data/registries/fluid/water/WaterFluid.kt index 837bd2753..b90d3e066 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/fluid/water/WaterFluid.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/fluid/water/WaterFluid.kt @@ -103,7 +103,7 @@ class WaterFluid( if (entity.horizontalCollision && entity.isClimbing) { velocity.y = 0.2 } - entity.velocity = velocity * Vec3d(speedMultiplier, 0.800000011920929, speedMultiplier) + entity.velocity = velocity * Vec3d(speedMultiplier, 0.8, speedMultiplier) entity.velocity = updateMovement(entity, gravity, falling, entity.velocity) diff --git a/src/main/java/de/bixilon/minosoft/data/registries/other/containers/PlayerInventory.kt b/src/main/java/de/bixilon/minosoft/data/registries/other/containers/PlayerInventory.kt index 3247bf7fc..b46ecd8d5 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/other/containers/PlayerInventory.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/other/containers/PlayerInventory.kt @@ -38,19 +38,25 @@ class PlayerInventory(connection: PlayConnection) : Container( } fun getHotbarSlot(hotbarSlot: Int = connection.player.selectedHotbarSlot): ItemStack? { - check(hotbarSlot in 0..9) { "Hotbar slot out of bounds!" } - return slots[hotbarSlot + 36] // ToDo + check(hotbarSlot in 0..HOTBAR_SLOTS) { "Hotbar slot out of bounds!" } + return slots[hotbarSlot + HOTBAR_OFFSET] // ToDo } operator fun get(slot: InventorySlots.EquipmentSlots): ItemStack? { return this[when (slot) { - InventorySlots.EquipmentSlots.HEAD -> 5 - InventorySlots.EquipmentSlots.CHEST -> 6 - InventorySlots.EquipmentSlots.LEGS -> 7 - InventorySlots.EquipmentSlots.FEET -> 8 + InventorySlots.EquipmentSlots.HEAD -> ARMOR_OFFSET + 0 + InventorySlots.EquipmentSlots.CHEST -> ARMOR_OFFSET + 1 + InventorySlots.EquipmentSlots.LEGS -> ARMOR_OFFSET + 2 + InventorySlots.EquipmentSlots.FEET -> ARMOR_OFFSET + 3 - InventorySlots.EquipmentSlots.MAIN_HAND -> connection.player.selectedHotbarSlot + 36 + InventorySlots.EquipmentSlots.MAIN_HAND -> connection.player.selectedHotbarSlot + HOTBAR_OFFSET InventorySlots.EquipmentSlots.OFF_HAND -> 45 }] } + + companion object { + private const val HOTBAR_OFFSET = 36 + private const val ARMOR_OFFSET = 5 + const val HOTBAR_SLOTS = 9 + } } 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 8713d1692..4851c6964 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 @@ -84,11 +84,11 @@ abstract class Particle( init { this.velocity += { (random.nextDouble() * 2.0 - 1.0) * MAGIC_VELOCITY_CONSTANT } - val modifier = (random.nextFloat() + random.nextFloat() + 1.0f) * 0.15000000596046448 + val modifier = (random.nextFloat() + random.nextFloat() + 1.0f) * 0.15 val divider = this.velocity.length() this.velocity assign this.velocity / divider * modifier * MAGIC_VELOCITY_CONSTANTf - this.velocity.y += 0.10000000149011612 + this.velocity.y += 0.1 spacing = Vec3(0.2) } @@ -189,7 +189,7 @@ abstract class Particle( abstract fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh) companion object { - private const val MAGIC_VELOCITY_CONSTANT = 0.4000000059604645 + private const val MAGIC_VELOCITY_CONSTANT = 0.4 private const val MAGIC_VELOCITY_CONSTANTf = MAGIC_VELOCITY_CONSTANT.toFloat() private const val Y_VELOCITY_TO_CHECK = 9.999999747378752E-6f } 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 index f751a8d06..31f449f9b 100644 --- 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 @@ -29,10 +29,10 @@ open class CloudParticle(connection: PlayConnection, position: Vec3d, velocity: init { friction = 0.96f - this.velocity *= 0.10000000149011612 + this.velocity *= 0.1 this.velocity += velocity - this.color = (1.0f - random.nextFloat() * 0.30000001192092896f).asGray() + this.color = (1.0f - random.nextFloat() * 0.3).asGray() super.scale *= 1.875f diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/damage/DamageParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/damage/DamageParticle.kt index 0c496abd3..154e25b8f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/damage/DamageParticle.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/damage/DamageParticle.kt @@ -32,9 +32,9 @@ abstract class DamageParticle(connection: PlayConnection, position: Vec3d, veloc init { friction = 0.7f gravityStrength = 0.5f - this.velocity *= 0.10000000149011612 + this.velocity *= 0.1 this.velocity += velocity * 0.4f - color = (random.nextFloat() * 0.30000001192092896f + 0.6000000238418579f).asGray() + color = (random.nextFloat() * 0.3 + 0.6).asGray() super.scale *= 0.75f maxAge = (6.0f / (random.nextFloat() * 0.8f + 0.6f)).toInt().coerceAtLeast(1) physics = false diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/dust/AbstractDustParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/dust/AbstractDustParticle.kt index de93c653f..1414bd84b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/dust/AbstractDustParticle.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/dust/AbstractDustParticle.kt @@ -30,7 +30,7 @@ abstract class AbstractDustParticle(connection: PlayConnection, position: Vec3d, init { this.friction = 0.96f - this.velocity *= 0.10000000149011612f + this.velocity *= 0.1f val brightness = random.nextFloat() * 0.4f + 0.6f this.color = RGBColor( diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/lava/LavaParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/lava/LavaParticle.kt index 0689bdd4e..93b1406dc 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/lava/LavaParticle.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/lava/LavaParticle.kt @@ -35,9 +35,9 @@ class LavaParticle(connection: PlayConnection, position: Vec3d, data: ParticleDa init { gravityStrength = 0.75f friction = 0.999f - velocity.x *= 0.800000011920929 + velocity.x *= 0.8 velocity.y = random.nextDouble() * 0.4f + 0.05f - velocity.z *= 0.800000011920929 + velocity.z *= 0.8 scale *= random.nextFloat() * 2.0f + 0.2f maxAge = (16.0f / (random.nextFloat() * 0.8f + 0.2f)).toInt() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/spell/SpellParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/spell/SpellParticle.kt index 471f938ba..130c0f377 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/spell/SpellParticle.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/spell/SpellParticle.kt @@ -26,10 +26,10 @@ abstract class SpellParticle(connection: PlayConnection, position: Vec3d, veloci friction = 0.96f gravityStrength = -0.1f accelerateIfYBlocked = true - this.velocity.y *= 0.20000000298023224 + this.velocity.y *= 0.2 if (velocity.x == 0.0 && velocity.z == 0.0) { - this.velocity.x *= 0.10000000149011612 - this.velocity.z *= 0.10000000149011612 + this.velocity.x *= 0.1 + this.velocity.z *= 0.1 } super.scale *= 0.75f maxAge = (8.0f / (random.nextFloat() * 0.8f + 0.2f)).toInt() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/water/BubbleParticle.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/water/BubbleParticle.kt index bec626c73..d4fc9b0d2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/water/BubbleParticle.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/types/render/texture/simple/water/BubbleParticle.kt @@ -32,7 +32,7 @@ class BubbleParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3 this.scale *= random.nextFloat() * 0.6f + 0.2f - this.velocity assign (velocity * 0.20000000298023224) + (Vec3d.of { random.nextDouble() * 2.0 - 1.0 } * 0.019999999552965164) + this.velocity assign (velocity * 0.2) + (Vec3d.of { random.nextDouble() * 2.0 - 1.0 } * 0.02) this.maxAge = (8.0f / random.nextFloat() * 0.8f + 0.2f).toInt() movement = false @@ -45,7 +45,7 @@ class BubbleParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3 } this.velocity.y += 0.002 forceMove(velocity) - velocity *= 0.8500000238418579 + velocity *= 0.85 // ToDo: Check if in water: Kill particle } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/HotbarSlotSetS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/HotbarSlotSetS2CP.kt index 0a2c3178a..82e129a2c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/HotbarSlotSetS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/HotbarSlotSetS2CP.kt @@ -12,6 +12,7 @@ */ package de.bixilon.minosoft.protocol.packets.s2c.play +import de.bixilon.minosoft.data.registries.other.containers.PlayerInventory import de.bixilon.minosoft.modding.event.events.SelectHotbarSlotEvent import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket @@ -23,12 +24,18 @@ import de.bixilon.minosoft.util.logging.LogMessageType class HotbarSlotSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { val slot: Int = buffer.readUnsignedByte() + + override fun check(connection: PlayConnection) { + check(slot in 0..PlayerInventory.HOTBAR_SLOTS) + } + override fun handle(connection: PlayConnection) { connection.fireEvent(SelectHotbarSlotEvent(connection, this)) connection.player.selectedHotbarSlot = slot } + override fun log() { Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Hotbar slot set (slot=$slot)" } }