mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 17:37:58 -04:00
optimize item entity physics performance
This commit is contained in:
parent
3d301929fe
commit
468e3ec735
@ -31,11 +31,11 @@ class ItemEntityPhysics(entity: ItemEntity) : EntityPhysics<ItemEntity>(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<ItemEntity>(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<FrictionBlock>()?.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<ItemEntity>(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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user