Allow for entities to be killed.
This commit is contained in:
parent
91395db919
commit
3ea5e47c57
5 changed files with 18 additions and 11 deletions
|
@ -178,14 +178,14 @@ export class MPClient {
|
|||
private breakBlock(brokenBlockId:number, x:number, y:number, z:number) {
|
||||
const metadata = this.entity.world.getBlockMetadata(this.diggingAt.x, this.diggingAt.y, this.diggingAt.z);
|
||||
this.entity.world.setBlockWithNotify(this.diggingAt.x, this.diggingAt.y, this.diggingAt.z, 0);
|
||||
this.inventory.addItemStack(new ItemStack(Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId), 1, metadata));
|
||||
this.send(new PacketWindowItems(0, this.inventory.getInventorySize(), this.inventory.constructInventoryPayload()).writeData());
|
||||
/*const itemId = Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId);
|
||||
//this.inventory.addItemStack(new ItemStack(Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId), 1, metadata));
|
||||
//this.send(new PacketWindowItems(0, this.inventory.getInventorySize(), this.inventory.constructInventoryPayload()).writeData());
|
||||
const itemId = Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId);
|
||||
if (itemId !== -1) {
|
||||
const itemEntity = new EntityItem(this.entity.world, new ItemStack(itemId, 1, metadata));
|
||||
itemEntity.position.set(x + 0.5, y + 0.5, z + 0.5);
|
||||
this.entity.world.addEntity(itemEntity);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Cap how far away a player is able to break blocks
|
||||
|
|
|
@ -287,6 +287,10 @@ export class World {
|
|||
entity.justUnloaded = new Array<number>();
|
||||
}
|
||||
}
|
||||
|
||||
if (entity.markedForDisposal) {
|
||||
this.removeEntity(entity);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -58,6 +58,8 @@ export class Entity implements IEntity {
|
|||
public readonly isPlayer:boolean;
|
||||
private queuedChunkUpdate:boolean;
|
||||
|
||||
public markedForDisposal:boolean = false;
|
||||
|
||||
public constructor(world:World, isPlayer:boolean = false) {
|
||||
this.entityId = Entity.nextEntityId++;
|
||||
|
||||
|
@ -217,6 +219,11 @@ export class Entity implements IEntity {
|
|||
// TODO: Entity falling mount transfer
|
||||
}
|
||||
|
||||
kill() {
|
||||
this.health = 0;
|
||||
this.markedForDisposal = true;
|
||||
}
|
||||
|
||||
updateFalling(distance:number) {
|
||||
if (this.onGround) {
|
||||
if (this.fallDistance > 0) {
|
||||
|
@ -241,11 +248,7 @@ export class Entity implements IEntity {
|
|||
// TODO: Handle X and Z collisions.
|
||||
if (this.entityAABB.intersects(blockBoundingBox)) {
|
||||
const inersectionY = this.entityAABB.intersectionY(blockBoundingBox);
|
||||
this.position.add(
|
||||
0,
|
||||
inersectionY,
|
||||
0
|
||||
);
|
||||
this.position.add(0, inersectionY, 0);
|
||||
this.motion.y = 0;
|
||||
this.onGround = true;
|
||||
}
|
||||
|
@ -267,7 +270,6 @@ export class Entity implements IEntity {
|
|||
|
||||
if (!this.isDead && this.health <= 0) {
|
||||
this.isDead = true;
|
||||
|
||||
}
|
||||
|
||||
if (this.wasHurt) {
|
||||
|
|
|
@ -46,7 +46,7 @@ export class EntityItem extends Entity {
|
|||
|
||||
this.age++;
|
||||
if (this.age >= 6000) {
|
||||
// TODO: Kill entity
|
||||
this.kill();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ export interface IEntity {
|
|||
lastPosition:Vec3,
|
||||
crouching:boolean,
|
||||
isDead:boolean,
|
||||
markedForDisposal:boolean,
|
||||
updateMetadata:() => void,
|
||||
distanceTo:(entity:IEntity) => number,
|
||||
onTick:() => void
|
||||
|
|
Loading…
Reference in a new issue