Scrap !!
This commit is contained in:
@@ -43,6 +43,36 @@ export interface SavedItemEntity extends SavedEntity {
|
||||
health?: number;
|
||||
}
|
||||
|
||||
// one tick of falling, sliding and floating like an item lying around, for an entity whose own gravity is 0 (see
|
||||
// ItemEntity.gravity)
|
||||
export function move_like_item(entity: Entity) {
|
||||
// covered by a block placed on it, float out the top instead of being stuck inside. only inside what it bumps
|
||||
// into, like minecraft's noCollision, so it can lie in a block with a hollow, like a basin
|
||||
const level = entity.level;
|
||||
if (!physics.box_is_free(entity, 0, 0, 0, (x, y, z) => level.collision_shape(x, y, z))) {
|
||||
entity.vy = UNSTICK_SPEED;
|
||||
}
|
||||
|
||||
// like minecraft's ItemEntity.tick, gravity goes on its speed before it moves, not along the way like
|
||||
// move_body's. the floating numbers are made for that: an item bobbing up out of the water drops straight back
|
||||
// in, instead of hanging above it a tick longer and falling twice as fast
|
||||
if (physics.fluid_depth(entity, (x, y, z) => level.fluid_at(x, y, z)) > FLOAT_DEPTH) {
|
||||
entity.vx *= WATER_DRAG;
|
||||
entity.vz *= WATER_DRAG;
|
||||
if (entity.vy < FLOAT_SPEED) entity.vy += FLOAT_ACCELERATION;
|
||||
} else if (!entity.no_gravity) {
|
||||
entity.vy += GRAVITY * TICK_DELTA;
|
||||
}
|
||||
|
||||
entity.move();
|
||||
const friction = entity.on_ground ? GROUND_FRICTION : AIR_DRAG;
|
||||
entity.vx *= friction;
|
||||
entity.vy *= AIR_DRAG;
|
||||
entity.vz *= friction;
|
||||
if (Math.abs(entity.vx) < MIN_SPEED) entity.vx = 0;
|
||||
if (Math.abs(entity.vz) < MIN_SPEED) entity.vz = 0;
|
||||
}
|
||||
|
||||
// a stack of items lying in the world, like minecraft's ItemEntity. only the server simulates it,
|
||||
// clients draw where they're told it is
|
||||
export class ItemEntity extends Entity {
|
||||
@@ -51,7 +81,7 @@ export class ItemEntity extends Entity {
|
||||
override width = ITEM_SIZE;
|
||||
override height = ITEM_SIZE;
|
||||
override eye_height = ITEM_SIZE / 2;
|
||||
// it falls in tick() instead, see there
|
||||
// it falls in move_like_item instead, see there
|
||||
override gravity = 0;
|
||||
|
||||
// ticks until a player can pick it up
|
||||
@@ -79,32 +109,7 @@ export class ItemEntity extends Entity {
|
||||
if (this.pickup_delay > 0) {
|
||||
this.pickup_delay -= 1;
|
||||
}
|
||||
|
||||
// covered by a block placed on it, float out the top instead of being stuck inside. only inside what it bumps
|
||||
// into, like minecraft's noCollision, so it can lie in a block with a hollow, like a basin
|
||||
const level = this.level;
|
||||
if (!physics.box_is_free(this, 0, 0, 0, (x, y, z) => level.collision_shape(x, y, z))) {
|
||||
this.vy = UNSTICK_SPEED;
|
||||
}
|
||||
|
||||
// like minecraft's ItemEntity.tick, gravity goes on its speed before it moves, not along the way like
|
||||
// move_body's. the floating numbers are made for that: an item bobbing up out of the water drops straight back
|
||||
// in, instead of hanging above it a tick longer and falling twice as fast
|
||||
if (physics.fluid_depth(this, (x, y, z) => level.fluid_at(x, y, z)) > FLOAT_DEPTH) {
|
||||
this.vx *= WATER_DRAG;
|
||||
this.vz *= WATER_DRAG;
|
||||
if (this.vy < FLOAT_SPEED) this.vy += FLOAT_ACCELERATION;
|
||||
} else if (!this.no_gravity) {
|
||||
this.vy += GRAVITY * TICK_DELTA;
|
||||
}
|
||||
|
||||
this.move();
|
||||
const friction = this.on_ground ? GROUND_FRICTION : AIR_DRAG;
|
||||
this.vx *= friction;
|
||||
this.vy *= AIR_DRAG;
|
||||
this.vz *= friction;
|
||||
if (Math.abs(this.vx) < MIN_SPEED) this.vx = 0;
|
||||
if (Math.abs(this.vz) < MIN_SPEED) this.vz = 0;
|
||||
move_like_item(this);
|
||||
|
||||
if (this.age >= DESPAWN_TICKS) {
|
||||
this.remove();
|
||||
|
||||
Reference in New Issue
Block a user