Add a bunch of crops and farmer's delight crops
This commit is contained in:
@@ -132,6 +132,8 @@ export interface BlockRegistry {
|
||||
// the blocks it can stand on, like crops on farmland. it can't be placed elsewhere, and breaks when the block
|
||||
// under it becomes something else. anything when not set
|
||||
place_on?: string[];
|
||||
// the blocks it can be placed into, replacing them, like rice into water. air and replaceable blocks when not set
|
||||
place_in?: string[];
|
||||
// custom components from mods and their params, the server runs them
|
||||
components?: Record<string, unknown>;
|
||||
|
||||
|
||||
@@ -141,6 +141,8 @@ export interface ServerAfterEvents {
|
||||
export interface ServerWorld {
|
||||
get_block(x: number, y: number, z: number): Id | undefined; // undefined when the chunk isn't loaded
|
||||
set_block(x: number, y: number, z: number, id: Id): boolean; // runs on_break / on_create, synced to everyone
|
||||
// like breaking it by hand without a tool: on_break, then its drops. false when there was nothing to break
|
||||
break_block(x: number, y: number, z: number): boolean;
|
||||
get_state(x: number, y: number, z: number, name: string): number | undefined;
|
||||
set_state(x: number, y: number, z: number, name: string, value: number): boolean;
|
||||
get_block_data<T>(x: number, y: number, z: number): T | undefined;
|
||||
|
||||
+3
-1
@@ -107,7 +107,9 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
}
|
||||
}
|
||||
if (json.drops) uses(file, json.drops, "item");
|
||||
for (const id of json.place_on ?? []) uses(file, id, "block");
|
||||
for (const id of [...(json.place_on ?? []), ...(json.place_in ?? [])]) {
|
||||
if (id !== "bworld:air") uses(file, id, "block");
|
||||
}
|
||||
}
|
||||
for (const { file, json } of mod.models) {
|
||||
if ((model_owners.get(json.id)?.length ?? 0) > 1 || BUILTIN_MODELS[json.id]) {
|
||||
|
||||
+9
-4
@@ -50,6 +50,7 @@ export interface BlockJson {
|
||||
interactive?: boolean;
|
||||
replaceable?: boolean;
|
||||
place_on?: string[];
|
||||
place_in?: string[];
|
||||
states?: BlockStateDefinition[];
|
||||
components?: Record<string, unknown>;
|
||||
}
|
||||
@@ -124,6 +125,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
|
||||
if (block.interactive) json.interactive = true;
|
||||
if (block.replaceable) json.replaceable = true;
|
||||
if (block.place_on) json.place_on = block.place_on;
|
||||
if (block.place_in) json.place_in = block.place_in;
|
||||
if (block.states) json.states = block.states;
|
||||
if (block.components) json.components = block.components;
|
||||
return json;
|
||||
@@ -153,6 +155,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
|
||||
if (json.interactive) block.interactive = true;
|
||||
if (json.replaceable) block.replaceable = true;
|
||||
if (json.place_on) block.place_on = json.place_on;
|
||||
if (json.place_in) block.place_in = json.place_in;
|
||||
if (json.states) block.states = json.states;
|
||||
if (json.components) block.components = json.components;
|
||||
return { block, has_item: json.item ?? true };
|
||||
@@ -344,11 +347,13 @@ export function validate_block(json: unknown): Problems {
|
||||
}
|
||||
}
|
||||
if (json.drops !== undefined) problems.push(...validate_id(json.drops, "drops"));
|
||||
if (json.place_on !== undefined) {
|
||||
if (!Array.isArray(json.place_on) || json.place_on.length === 0) {
|
||||
problems.push("place_on must be a list of block ids");
|
||||
for (const key of ["place_on", "place_in"]) {
|
||||
const list = json[key];
|
||||
if (list === undefined) continue;
|
||||
if (!Array.isArray(list) || list.length === 0) {
|
||||
problems.push(`${key} must be a list of block ids`);
|
||||
} else {
|
||||
for (const id of json.place_on) problems.push(...validate_id(id, "place_on"));
|
||||
for (const id of list) problems.push(...validate_id(id, key));
|
||||
}
|
||||
}
|
||||
if (json.states !== undefined) {
|
||||
|
||||
@@ -123,6 +123,31 @@ export function can_stand_on(block: BlockRegistry | undefined, below: string): b
|
||||
return !block?.place_on || block.place_on.includes(below);
|
||||
}
|
||||
|
||||
// where a block placed by clicking a face of another goes: into the clicked block when it can be replaced (like water),
|
||||
// like minecraft, otherwise next to it
|
||||
export function placement_target(
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
offset: { x: number; y: number; z: number },
|
||||
clicked: BlockRegistry | undefined,
|
||||
) {
|
||||
return clicked?.replaceable ? { x, y, z } : { x: x + offset.x, y: y + offset.y, z: z + offset.z };
|
||||
}
|
||||
|
||||
// whether a player can place block where current is now, with below under it. current is undefined for air
|
||||
export function can_place(
|
||||
block: BlockRegistry | undefined,
|
||||
current: BlockRegistry | undefined,
|
||||
below: string,
|
||||
): boolean {
|
||||
if (!block) return false;
|
||||
const into = current?.id ?? "bworld:air";
|
||||
const replaceable = !current || current.replaceable === true;
|
||||
const in_ok = block.place_in ? block.place_in.includes(into) : replaceable;
|
||||
return in_ok && can_stand_on(block, below);
|
||||
}
|
||||
|
||||
// numeric so looking chunks up doesnt allocate a string every time, fine for |x|, |z| < 32768
|
||||
export function chunk_key(x: number, z: number) {
|
||||
return (x + 32768) * 65536 + (z + 32768);
|
||||
|
||||
Reference in New Issue
Block a user