Fluid containers
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
// runs mods' server scripts: builds each one's ServerContext and keeps what they register.
|
||||
// see docs/modding/. parts not built yet throw when used, saying so
|
||||
import { BlockRegistry, EverythingRegistry, fluid_height, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { Container as EngineContainer, ItemStack as EngineItemStack } from "$/common/inventory.ts";
|
||||
import { Container as EngineContainer, ItemStack as EngineItemStack, max_stack } from "$/common/inventory.ts";
|
||||
import {
|
||||
block_states,
|
||||
fluid_block,
|
||||
@@ -903,10 +903,14 @@ export class ModRuntime {
|
||||
items: {
|
||||
exists: (id) => EverythingRegistry.get("items", id) !== undefined,
|
||||
ids: () => EverythingRegistry.entries("items").map(([id]) => id),
|
||||
max_stack: (id) => {
|
||||
max_stack: (id, data) => {
|
||||
if (!EverythingRegistry.get("items", id)) throw new Error(`unknown item ${id}`);
|
||||
return max_stack(id, data);
|
||||
},
|
||||
fluid_capacity: (id) => {
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", id);
|
||||
if (!item) throw new Error(`unknown item ${id}`);
|
||||
return item.max_stack ?? (item.tool ? 1 : 64);
|
||||
return item.fluid_container?.capacity;
|
||||
},
|
||||
tool: (id) => {
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", id);
|
||||
@@ -1401,6 +1405,14 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
if (!EverythingRegistry.get("items", id)) throw new Error(`unknown item ${id}`);
|
||||
game.give(player, id, count, data);
|
||||
},
|
||||
exchange_held(result) {
|
||||
const held = player.held_item;
|
||||
if (!held) throw new Error("exchange_held needs something in the hand");
|
||||
const stack = new_stack(result);
|
||||
held.amount -= 1;
|
||||
if (held.amount <= 0) player.inventory.set_item(player.selected_slot, stack);
|
||||
else game.give_stack(player, stack);
|
||||
},
|
||||
send_message(text, options) {
|
||||
game.send_chat(player, String(text), options?.overlay === true);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user