Improve tools system
This commit is contained in:
@@ -540,14 +540,16 @@ export class GameServer {
|
||||
}
|
||||
|
||||
// breaks a block the way breaking it by hand does: its components' on_break, then what it drops. without the
|
||||
// right tool (or without a player) blocks that need one drop nothing
|
||||
// right tool of a high enough tier (or without a player) blocks that need one drop nothing
|
||||
destroy_block(x: number, y: number, z: number, player?: ServerPlayer) {
|
||||
const info = this.world.get_block_info(x, y, z);
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
const held = EverythingRegistry.get<ItemRegistry>("items", player?.held_item?.type_id ?? "");
|
||||
const drops = info.drop_table && (!info.requires_tool || held?.tool_type === info.tool_to_break);
|
||||
const tool = held?.tool;
|
||||
const right_tool = tool !== undefined && tool.type === info.tool_to_break && tool.tier >= (info.tool_tier ?? 0);
|
||||
const drops = info.drop_table && (!info.requires_tool || right_tool);
|
||||
this.set_block(x, y, z, AIR_ID, player);
|
||||
if (drops) {
|
||||
this.pop_item(x, y, z, new ItemStack(info.drop_table!));
|
||||
|
||||
@@ -490,12 +490,12 @@ export class ModRuntime {
|
||||
max_stack: (id) => {
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", id);
|
||||
if (!item) throw new Error(`unknown item ${id}`);
|
||||
return item.max_stack ?? 64;
|
||||
return item.max_stack ?? (item.tool ? 1 : 64);
|
||||
},
|
||||
tool: (id) => {
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", id);
|
||||
if (!item) throw new Error(`unknown item ${id}`);
|
||||
return item.tool_type;
|
||||
return item.tool?.type;
|
||||
},
|
||||
},
|
||||
recipes: {
|
||||
|
||||
Reference in New Issue
Block a user