mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 02:15:34 -04:00
some more memory optimisations
This commit is contained in:
parent
3548824ac5
commit
199aab67d7
@ -45,7 +45,7 @@ class EntityRenderInfo(private val entity: Entity) : Drawable, Tickable {
|
||||
private fun interpolatePosition(delta: Float) {
|
||||
// TODO: Only interpolate if changed
|
||||
position = Vec3dUtil.interpolateLinear(delta.toDouble(), position0, position1)
|
||||
eyePosition = position + Vec3d(0.0, entity.eyeHeight, 0.0)
|
||||
eyePosition = position + Vec3d(0.0, entity.eyeHeight.toDouble(), 0.0)
|
||||
cameraAABB = entity.defaultAABB + position
|
||||
eyeBlockPosition = position1.blockPosition
|
||||
}
|
||||
|
@ -30,10 +30,11 @@ open class SweetBerryBushBlock(resourceLocation: ResourceLocation, registries: R
|
||||
if (entity !is LivingEntity) {
|
||||
return
|
||||
}
|
||||
physics.slowMovement(state, Vec3d(0.8f, 0.75, 0.8f))
|
||||
physics.slowMovement(state, SLOW)
|
||||
}
|
||||
|
||||
companion object : PixLyzerBlockFactory<SweetBerryBushBlock> {
|
||||
val SLOW = Vec3d(0.8f, 0.75, 0.8f)
|
||||
|
||||
override fun build(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>): SweetBerryBushBlock {
|
||||
return SweetBerryBushBlock(resourceLocation, registries, data)
|
||||
|
@ -51,7 +51,7 @@ open class PowderSnowBlock(identifier: ResourceLocation = PowderSnowBlock.identi
|
||||
if (entity is LivingEntity && physics.positionInfo.block?.block !is PowderSnowBlock) {
|
||||
return
|
||||
}
|
||||
physics.slowMovement(state, Vec3d(0.9f, 1.5, 0.9f))
|
||||
physics.slowMovement(state, SLOW)
|
||||
}
|
||||
|
||||
override fun getCollisionShape(context: CollisionContext, blockPosition: Vec3i, state: BlockState, blockEntity: BlockEntity?): AbstractVoxelShape? {
|
||||
@ -70,6 +70,7 @@ open class PowderSnowBlock(identifier: ResourceLocation = PowderSnowBlock.identi
|
||||
|
||||
companion object : BlockFactory<PowderSnowBlock> {
|
||||
override val identifier = minecraft("powder_snow")
|
||||
private val SLOW = Vec3d(0.9f, 1.5, 0.9f)
|
||||
private val FALLING_SHAPE = VoxelShape(AABB(Vec3d(0.0, 0.0, 0.0), Vec3d(1.0, 0.9f, 1.0)))
|
||||
private val TAG = minecraft("powder_snow_walkable_mobs")
|
||||
|
||||
|
@ -52,11 +52,12 @@ open class CobwebBlock(identifier: ResourceLocation = Companion.identifier, sett
|
||||
}
|
||||
|
||||
override fun onEntityCollision(entity: Entity, physics: EntityPhysics<*>, position: Vec3i, state: BlockState) {
|
||||
physics.slowMovement(state, Vec3d(0.25, 0.05f, 0.25))
|
||||
physics.slowMovement(state, SLOW)
|
||||
}
|
||||
|
||||
companion object : BlockFactory<CobwebBlock> {
|
||||
override val identifier = minecraft("cobweb")
|
||||
val SLOW = Vec3d(0.25, 0.05f, 0.25)
|
||||
|
||||
override fun build(registries: Registries, settings: BlockSettings) = CobwebBlock(settings = settings)
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ abstract class Fluid(override val identifier: ResourceLocation) : RegistryItem()
|
||||
protected fun LivingEntityPhysics<*>.applyBouncing(y: Double) {
|
||||
val velocity = this.velocity
|
||||
if (!horizontalCollision || !doesNotCollide(Vec3d(velocity.x, velocity.y + 0.6f - position.y + y, velocity.z))) return
|
||||
this.velocity = Vec3d(velocity.x, 0.3f, velocity.z)
|
||||
this.velocity = Vec3d(velocity.x, 0.3, velocity.z)
|
||||
}
|
||||
|
||||
protected fun LivingEntityPhysics<*>.applyFriction(horizontal: Double, vertical: Double = 0.8f.toDouble()) {
|
||||
|
@ -168,9 +168,9 @@ class AABB {
|
||||
|
||||
fun offset(axis: Axes, offset: Double): AABB {
|
||||
return when (axis) {
|
||||
Axes.X -> this + Vec3d(-offset, 0, 0)
|
||||
Axes.Y -> this + Vec3d(0, -offset, 0)
|
||||
Axes.Z -> this + Vec3d(0, 0, -offset)
|
||||
Axes.X -> this + Vec3d(-offset, 0.0, 0.0)
|
||||
Axes.Y -> this + Vec3d(0.0, -offset, 0.0)
|
||||
Axes.Z -> this + Vec3d(0.0, 0.0, -offset)
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ class AABB {
|
||||
}
|
||||
|
||||
fun hShrink(size: Float): AABB {
|
||||
val vec = Vec3d(size, 0.0, size)
|
||||
val vec = Vec3d(size, 0.0f, size)
|
||||
return AABB(min + vec, max - vec)
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ object VecUtil {
|
||||
get() = this shr 4
|
||||
|
||||
val Vec3i.entityPosition: Vec3d
|
||||
get() = Vec3d(x + 0.5f, y, z + 0.5f) // ToDo: Confirm
|
||||
get() = Vec3d(x + 0.5, y + 0.0, z + 0.5) // ToDo: Confirm
|
||||
|
||||
val Vec3i.centerf: Vec3
|
||||
get() = Vec3(x + 0.5f, y + 0.5f, z + 0.5f)
|
||||
|
@ -14,6 +14,7 @@
|
||||
package de.bixilon.minosoft.physics.entities
|
||||
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.observer.DataObserver.Companion.observed
|
||||
import de.bixilon.kutil.primitive.DoubleUtil
|
||||
import de.bixilon.minosoft.data.direction.Directions
|
||||
@ -33,7 +34,6 @@ import de.bixilon.minosoft.data.world.positions.BlockPosition
|
||||
import de.bixilon.minosoft.data.world.positions.ChunkPositionUtil.inChunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.blockPosition
|
||||
import de.bixilon.minosoft.physics.EntityPositionInfo
|
||||
import de.bixilon.minosoft.physics.handlers.general.AbstractEntityPhysics
|
||||
import de.bixilon.minosoft.physics.handlers.movement.SneakAdjuster
|
||||
@ -107,7 +107,7 @@ open class EntityPhysics<E : Entity>(val entity: E) : BasicPhysicsEntity(), Abst
|
||||
|
||||
fun getLandingPosition(): BlockPosition {
|
||||
val info = this.positionInfo
|
||||
val position = Vec3d(info.inChunkPosition.x, position.y - 0.2, info.inChunkPosition.z).blockPosition
|
||||
val position = Vec3i(info.inChunkPosition.x, (position.y - 0.2).toInt(), info.inChunkPosition.z)
|
||||
val state = positionInfo.chunk?.get(position)
|
||||
if (state == null) {
|
||||
val down = positionInfo.chunk?.get(position + Directions.DOWN)
|
||||
|
@ -83,7 +83,7 @@ open class LivingEntityPhysics<E : LivingEntity>(entity: E) : EntityPhysics<E>(e
|
||||
}
|
||||
|
||||
fun swimUpwards(fluid: Identified) {
|
||||
this.velocity = velocity + Vec3d(0.0, 0.04f, 0.0)
|
||||
this.velocity = velocity + SWIM_UPWARDS
|
||||
}
|
||||
|
||||
fun doesNotCollide(offset: Vec3d): Boolean {
|
||||
@ -173,4 +173,8 @@ open class LivingEntityPhysics<E : LivingEntity>(entity: E) : EntityPhysics<E>(e
|
||||
super.tickRiding()
|
||||
fallDistance = 0.0f
|
||||
}
|
||||
|
||||
private companion object {
|
||||
val SWIM_UPWARDS = Vec3d(0.0, 0.04f, 0.0)
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ object CollisionMovementPhysics {
|
||||
|
||||
if (!grounded || !(collided.x || collided.z)) return collision
|
||||
|
||||
val stepHeight = stepHeight
|
||||
val stepHeight = stepHeight.toDouble()
|
||||
|
||||
var total = collide(Vec3d(movement.x, stepHeight, movement.z), aabb, collisions)
|
||||
val vertical = collide(Vec3d(0.0, stepHeight, 0.0), aabb.extend(Vec3d(movement.x, 0.0, movement.z)), collisions)
|
||||
|
Loading…
x
Reference in New Issue
Block a user