From 4afb4a06338224d5abf2fe94eec48b20f0c3f884 Mon Sep 17 00:00:00 2001 From: Holly Date: Mon, 18 Dec 2023 21:49:23 +0000 Subject: [PATCH] death and item drops n' stuff --- server/entities/EntityLiving.ts | 3 +-- server/entities/Player.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/server/entities/EntityLiving.ts b/server/entities/EntityLiving.ts index b1962d3..df9cc56 100644 --- a/server/entities/EntityLiving.ts +++ b/server/entities/EntityLiving.ts @@ -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) { diff --git a/server/entities/Player.ts b/server/entities/Player.ts index d838683..e419681 100644 --- a/server/entities/Player.ts +++ b/server/entities/Player.ts @@ -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()); }