Health and hunger system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Container, Cursor, ItemData, ItemStack } from "$/common/inventory.ts";
|
||||
import { PlayerInfo, ScreenLayout } from "$/common/protocol.ts";
|
||||
import { type SavedVitals, Vitals } from "./vitals.ts";
|
||||
|
||||
export const INVENTORY_SIZE = 9 * 4;
|
||||
export const CRAFTING_SIZE = 10;
|
||||
@@ -26,6 +27,8 @@ export interface SavedPlayer {
|
||||
pitch: number;
|
||||
selected_slot: number;
|
||||
inventory: (ItemData | null)[];
|
||||
// players saved before health and hunger start full
|
||||
vitals?: SavedVitals;
|
||||
}
|
||||
|
||||
export class ServerPlayer {
|
||||
@@ -40,6 +43,11 @@ export class ServerPlayer {
|
||||
pitch = 0;
|
||||
|
||||
inventory = new Container(INVENTORY_SIZE);
|
||||
vitals = new Vitals();
|
||||
// blocks fallen since last standing on something, for fall damage
|
||||
fall_distance = 0;
|
||||
// when the last move came, to tell walking from sprinting
|
||||
last_move_tick = 0;
|
||||
crafting = new Container(CRAFTING_SIZE);
|
||||
cursor: Cursor = { item: undefined };
|
||||
selected_slot = 0;
|
||||
@@ -70,6 +78,7 @@ export class ServerPlayer {
|
||||
pitch: this.pitch,
|
||||
selected_slot: this.selected_slot,
|
||||
inventory: this.inventory.to_data(),
|
||||
vitals: this.vitals.save(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -81,5 +90,6 @@ export class ServerPlayer {
|
||||
this.pitch = saved.pitch;
|
||||
this.selected_slot = saved.selected_slot;
|
||||
this.inventory.load(saved.inventory);
|
||||
this.vitals.load(saved.vitals);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user