death and item drops n' stuff
This commit is contained in:
parent
797cd5db62
commit
4afb4a0633
2 changed files with 16 additions and 2 deletions
|
@ -40,11 +40,10 @@ export class EntityLiving extends Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
damageFrom(damage:number, entity?:IEntity) {
|
damageFrom(damage:number, entity?:IEntity) {
|
||||||
|
super.damageFrom(damage, entity);
|
||||||
if (this.health <= 0) {
|
if (this.health <= 0) {
|
||||||
this.isDead = true;
|
this.isDead = true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
super.damageFrom(damage, entity);
|
|
||||||
|
|
||||||
// Send Damage Animation packet or death packet
|
// Send Damage Animation packet or death packet
|
||||||
if (this.isDead) {
|
if (this.isDead) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { IReader, IWriter } from "bufferstuff";
|
||||||
import { EntityItem } from "./EntityItem";
|
import { EntityItem } from "./EntityItem";
|
||||||
import { Entity } from "./Entity";
|
import { Entity } from "./Entity";
|
||||||
import { PacketCollectItem } from "../packets/CollectItem";
|
import { PacketCollectItem } from "../packets/CollectItem";
|
||||||
|
import { PacketPickupSpawn } from "../packets/PickupSpawn";
|
||||||
|
|
||||||
const CHUNK_LOAD_RANGE = 15;
|
const CHUNK_LOAD_RANGE = 15;
|
||||||
|
|
||||||
|
@ -79,6 +80,16 @@ export class Player extends EntityLiving {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dropAllItems() {
|
||||||
|
for (const itemStack of this.inventory.itemStacks) {
|
||||||
|
if (itemStack) {
|
||||||
|
const item = new EntityItem(this.world, itemStack);
|
||||||
|
item.position.set(this.position);
|
||||||
|
this.world.addEntity(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async updatePlayerChunks() {
|
private async updatePlayerChunks() {
|
||||||
const bitX = this.position.x >> 4;
|
const bitX = this.position.x >> 4;
|
||||||
const bitZ = this.position.z >> 4;
|
const bitZ = this.position.z >> 4;
|
||||||
|
@ -181,6 +192,10 @@ export class Player extends EntityLiving {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.health != this.lastHealth) {
|
if (this.health != this.lastHealth) {
|
||||||
|
if (this.health <= 0 && this.isDead) {
|
||||||
|
this.dropAllItems();
|
||||||
|
}
|
||||||
|
|
||||||
this.lastHealth = this.health;
|
this.lastHealth = this.health;
|
||||||
this.mpClient?.send(new PacketUpdateHealth(this.health).writeData());
|
this.mpClient?.send(new PacketUpdateHealth(this.health).writeData());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue