Data on /give
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
} from "$/common/constants.ts";
|
||||
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { FluidFlow } from "./fluids.ts";
|
||||
import { Container, ItemData, ItemStack } from "$/common/inventory.ts";
|
||||
import { contained_fluid, Container, ItemData, ItemStack } from "$/common/inventory.ts";
|
||||
import {
|
||||
AIR_ID,
|
||||
ClientMessage,
|
||||
@@ -56,8 +56,10 @@ import {
|
||||
type CommandContext,
|
||||
CommandError,
|
||||
type CommandNode,
|
||||
fluid,
|
||||
integer,
|
||||
item,
|
||||
json,
|
||||
literal,
|
||||
number,
|
||||
word,
|
||||
@@ -1596,10 +1598,21 @@ export class GameServer {
|
||||
const register = (node: CommandNode<ServerCommandSource>) => this.mods.register_command("engine", node);
|
||||
|
||||
// TODO: only let operators do this
|
||||
const give = (context: CommandContext<ServerCommandSource>, count: number) => {
|
||||
// with data, any json, like { "damage": 10 } on a tool, or a fluid container full of a fluid with its data
|
||||
const give = (context: CommandContext<ServerCommandSource>, count: number, data?: unknown) => {
|
||||
const id = context.get<string>("item");
|
||||
this.give(context.source.server_player, id, count);
|
||||
context.source.send_message(`Gave ${count} ${display_name(id)}`);
|
||||
this.give(context.source.server_player, id, count, data);
|
||||
const fluid = contained_fluid(id, data);
|
||||
const of = fluid ? ` of ${this.mods.fluid_rules.name(fluid)}` : "";
|
||||
context.source.send_message(`Gave ${count} ${display_name(id)}${of}`);
|
||||
};
|
||||
const give_full = (context: CommandContext<ServerCommandSource>, data?: unknown) => {
|
||||
const id = context.get<string>("item");
|
||||
if (!EverythingRegistry.get<ItemRegistry>("items", id)?.fluid_container) {
|
||||
throw new CommandError(`${display_name(id)} doesn't hold fluids`);
|
||||
}
|
||||
const fluid = { id: context.get<string>("fluid"), ...(data === undefined ? {} : { data }) };
|
||||
give(context, context.get<number>("count"), { fluid });
|
||||
};
|
||||
register(
|
||||
literal<ServerCommandSource>("give").describe("Gives you an item").then(
|
||||
@@ -1607,7 +1620,23 @@ export class GameServer {
|
||||
.executes((context) => give(context, 1))
|
||||
.then(
|
||||
argument<number, ServerCommandSource>("count", integer(1, MAX_GIVE))
|
||||
.executes((context) => give(context, context.get<number>("count"))),
|
||||
.executes((context) => give(context, context.get<number>("count")))
|
||||
.then(
|
||||
literal<ServerCommandSource>("fluid").then(
|
||||
argument<string, ServerCommandSource>("fluid", fluid())
|
||||
.executes((context) => give_full(context))
|
||||
.then(
|
||||
argument<unknown, ServerCommandSource>("fluid_data", json())
|
||||
.executes((context) => give_full(context, context.get("fluid_data"))),
|
||||
),
|
||||
),
|
||||
)
|
||||
.then(
|
||||
argument<unknown, ServerCommandSource>("data", json())
|
||||
.executes((context) =>
|
||||
give(context, context.get<number>("count"), context.get("data"))
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -57,9 +57,11 @@ import {
|
||||
CommandDispatcher,
|
||||
CommandError,
|
||||
CommandNode,
|
||||
fluid as fluid_argument,
|
||||
greedy_string,
|
||||
integer,
|
||||
item,
|
||||
json,
|
||||
literal,
|
||||
number,
|
||||
word,
|
||||
@@ -698,9 +700,11 @@ export class ModRuntime {
|
||||
boolean,
|
||||
word,
|
||||
greedy_string,
|
||||
json,
|
||||
choice,
|
||||
item: () => item(),
|
||||
block: () => block_argument(),
|
||||
fluid: () => fluid_argument(),
|
||||
player: () => ({
|
||||
parse: (text: string) => {
|
||||
const found = game().players().find((p) => p.name === text);
|
||||
|
||||
Reference in New Issue
Block a user