diff --git a/src/main/java/de/bixilon/minosoft/physics/entities/living/ItemEntityPhysics.kt b/src/main/java/de/bixilon/minosoft/physics/entities/living/ItemEntityPhysics.kt index 7c85f58cb..937cdec27 100644 --- a/src/main/java/de/bixilon/minosoft/physics/entities/living/ItemEntityPhysics.kt +++ b/src/main/java/de/bixilon/minosoft/physics/entities/living/ItemEntityPhysics.kt @@ -31,11 +31,11 @@ class ItemEntityPhysics(entity: ItemEntity) : EntityPhysics(entity) private fun updateFluidVelocity(friction: Float) { val velocity = this.velocity - this.velocity = Vec3d( - velocity.x * friction, - velocity.y + if (this.velocity.y < 0.06f) 5.0E-4f else 0.0f, - velocity.z * friction, - ) + this.velocity = Vec3d( + velocity.x * friction, + velocity.y + if (this.velocity.y < 0.06f) 5.0E-4f else 0.0f, + velocity.z * friction, + ) } private fun updateVelocity() { @@ -49,20 +49,23 @@ class ItemEntityPhysics(entity: ItemEntity) : EntityPhysics(entity) if (!entity.hasGravity) return - this.velocity = velocity + Vec3d(0.0, -GRAVITY, 0.0) + this.velocity = velocity + GRAVITY } private fun move() { - if (onGround && this.velocity.xz.length2() <= 9.999999747378752E-6 && (entity.age + (entity.id ?: 0)) % 4 != 0) return + // This is not 100% vanilla, but performance optimized + if (onGround && this.velocity.xz.length2() <= 9.999999747378752E-6 && entity.age % 4 != 0) return move(this.velocity) var friction = PhysicsConstants.AIR_RESISTANCEf if (onGround) { - val frictionPosition = (position + Vec3d(0, -1, 0)).blockPosition.inChunkPosition + val frictionPosition = (position + FRICTION_OFFSET).blockPosition.inChunkPosition friction *= positionInfo.chunk?.get(frictionPosition)?.block?.nullCast()?.friction ?: FrictionBlock.DEFAULT_FRICTION + this.velocity = Vec3d(this.velocity.x * friction, 0.0, this.velocity.z * friction) + } else { + this.velocity = this.velocity * Vec3d(friction, PhysicsConstants.AIR_RESISTANCE, friction) } - this.velocity = this.velocity * Vec3d(friction, PhysicsConstants.AIR_RESISTANCE, friction) if (onGround) { val velocity = this.velocity @@ -79,7 +82,8 @@ class ItemEntityPhysics(entity: ItemEntity) : EntityPhysics(entity) } companion object { - const val GRAVITY = 0.04 + val GRAVITY = Vec3d(0.0, -0.04, 0.0) + val FRICTION_OFFSET = Vec3d(0, -1, 0) val Fluid.friction: Float get() = when (this) {