Item entities
This commit is contained in:
+8
-10
@@ -23,16 +23,14 @@ export interface BlockBehavior {
|
||||
|
||||
export const BLOCK_BEHAVIORS: Record<string, BlockBehavior> = {};
|
||||
|
||||
// give the breaking player whatever was inside
|
||||
function give_container_contents(tile: Tile, player: ServerPlayer | undefined) {
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
// whatever was inside falls out, like minecraft's Containers.dropContents
|
||||
function drop_container_contents(game: GameServer, tile: Tile) {
|
||||
for (const container of Object.values(tile.containers)) {
|
||||
for (let i = 0; i < container.size; i++) {
|
||||
const item = container.get_item(i);
|
||||
if (item) {
|
||||
player.give(item);
|
||||
container.set_item(i, undefined);
|
||||
game.pop_item(tile.x, tile.y, tile.z, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,8 +73,8 @@ BLOCK_BEHAVIORS["bworld:chest"] = {
|
||||
});
|
||||
return true;
|
||||
},
|
||||
on_break(_game, tile, player) {
|
||||
give_container_contents(tile, player);
|
||||
on_break(game, tile) {
|
||||
drop_container_contents(game, tile);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -201,8 +199,8 @@ BLOCK_BEHAVIORS["bworld:furnace"] = {
|
||||
});
|
||||
return true;
|
||||
},
|
||||
on_break(_game, tile, player) {
|
||||
give_container_contents(tile, player);
|
||||
on_break(game, tile) {
|
||||
drop_container_contents(game, tile);
|
||||
},
|
||||
on_tick(game, tile) {
|
||||
const data = tile.data as unknown as FurnaceData;
|
||||
|
||||
Reference in New Issue
Block a user