death and item drops n' stuff

This commit is contained in:
Holly Stubbs 2023-12-18 21:49:23 +00:00
parent 797cd5db62
commit 4afb4a0633
Signed by: tgpholly
GPG Key ID: B8583C4B7D18119E
2 changed files with 16 additions and 2 deletions

View File

@ -40,11 +40,10 @@ export class EntityLiving extends Entity {
}
damageFrom(damage:number, entity?:IEntity) {
super.damageFrom(damage, entity);
if (this.health <= 0) {
this.isDead = true;
return;
}
super.damageFrom(damage, entity);
// Send Damage Animation packet or death packet
if (this.isDead) {

View File

@ -16,6 +16,7 @@ import { IReader, IWriter } from "bufferstuff";
import { EntityItem } from "./EntityItem";
import { Entity } from "./Entity";
import { PacketCollectItem } from "../packets/CollectItem";
import { PacketPickupSpawn } from "../packets/PickupSpawn";
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() {
const bitX = this.position.x >> 4;
const bitZ = this.position.z >> 4;
@ -181,6 +192,10 @@ export class Player extends EntityLiving {
}
if (this.health != this.lastHealth) {
if (this.health <= 0 && this.isDead) {
this.dropAllItems();
}
this.lastHealth = this.health;
this.mpClient?.send(new PacketUpdateHealth(this.health).writeData());
}