lava fluid movement

This commit is contained in:
Bixilon 2021-06-28 23:36:40 +02:00
parent f05ffc2742
commit 14768e89a0
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 29 additions and 3 deletions

View File

@ -94,7 +94,7 @@ class LocalPlayerEntity(
// fluids stuff
private val fluidHeights: MutableMap<ResourceLocation, Float> = synchronizedMapOf()
val fluidHeights: MutableMap<ResourceLocation, Float> = synchronizedMapOf()
var submgergedFluid: Fluid? = null
var input = MovementInput()
@ -203,6 +203,9 @@ class LocalPlayerEntity(
override val spawnSprintingParticles: Boolean
get() = super.spawnSprintingParticles && !baseAbilities.isFlying
val swimHeight: Double
get() = (eyeHeight < 0.4).decide(0.0, 0.4)
private fun sendMovementPackets() {
if (Minosoft.config.config.game.camera.disableMovementSending) {
return
@ -461,7 +464,7 @@ class LocalPlayerEntity(
maxHeight = max(maxHeight, level)
}
// ToDo: First water, then jumping, then lava?
if (maxHeight > 0 && (!onGround || maxHeight > ((eyeHeight < 0.4).decide(0.0, 0.4)))) {
if (maxHeight > 0 && (!onGround || maxHeight > swimHeight)) {
this.velocity.y += 0.03999999910593033
} else if (onGround && jumpingCoolDown == 0) {
jump()

View File

@ -69,7 +69,9 @@ open class Fluid(
return (8 - ((blockState.properties[BlockProperties.FLUID_LEVEL]?.unsafeCast<Int>()) ?: 8)) / 9.0f
}
open fun travel(entity: LocalPlayerEntity, sidewaysSpeed: Float, forwardSpeed: Float, gravity: Double, falling: Boolean) {}
open fun travel(entity: LocalPlayerEntity, sidewaysSpeed: Float, forwardSpeed: Float, gravity: Double, falling: Boolean) {
entity.accelerate(sidewaysSpeed, forwardSpeed, 0.02)
}
open fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {}

View File

@ -15,8 +15,10 @@ package de.bixilon.minosoft.data.registries.fluid.lava
import com.google.gson.JsonObject
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.player.LocalPlayerEntity
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.fluid.DefaultFluids
import de.bixilon.minosoft.data.registries.fluid.FlowableFluid
import de.bixilon.minosoft.data.registries.fluid.Fluid
import de.bixilon.minosoft.data.registries.versions.Registries
@ -49,6 +51,25 @@ class LavaFluid(
return other is LavaFluid
}
override fun travel(entity: LocalPlayerEntity, sidewaysSpeed: Float, forwardSpeed: Float, gravity: Double, falling: Boolean) {
entity.accelerate(sidewaysSpeed, forwardSpeed, 0.02)
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 = updateMovement(entity, gravity, falling, entity.velocity)
} else {
entity.velocity = entity.velocity * 0.5
}
if (entity.hasGravity) {
entity.velocity.y += -gravity / 4.0
}
// ToDo: Same as for water
}
override fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {
super.randomTick(connection, blockState, blockPosition, random)
val above = connection.world[blockPosition + Directions.UP]