mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
optimize item entity physics performance
This commit is contained in:
parent
3d301929fe
commit
468e3ec735
@ -49,20 +49,23 @@ class ItemEntityPhysics(entity: ItemEntity) : EntityPhysics<ItemEntity>(entity)
|
|||||||
|
|
||||||
if (!entity.hasGravity) return
|
if (!entity.hasGravity) return
|
||||||
|
|
||||||
this.velocity = velocity + Vec3d(0.0, -GRAVITY, 0.0)
|
this.velocity = velocity + GRAVITY
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun move() {
|
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)
|
move(this.velocity)
|
||||||
|
|
||||||
var friction = PhysicsConstants.AIR_RESISTANCEf
|
var friction = PhysicsConstants.AIR_RESISTANCEf
|
||||||
if (onGround) {
|
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
|
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) {
|
if (onGround) {
|
||||||
val velocity = this.velocity
|
val velocity = this.velocity
|
||||||
@ -79,7 +82,8 @@ class ItemEntityPhysics(entity: ItemEntity) : EntityPhysics<ItemEntity>(entity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
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
|
val Fluid.friction: Float
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user