Improve crops system

This commit is contained in:
2026-09-26 18:32:38 -03:00
parent e22f12c0b6
commit 0fa6ec4ed3
15 changed files with 394 additions and 31 deletions
+10
View File
@@ -48,6 +48,7 @@ export interface BlockJson {
item?: boolean;
interactive?: boolean;
replaceable?: boolean;
place_on?: string[];
states?: BlockStateDefinition[];
components?: Record<string, unknown>;
}
@@ -120,6 +121,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (!has_item) json.item = false;
if (block.interactive) json.interactive = true;
if (block.replaceable) json.replaceable = true;
if (block.place_on) json.place_on = block.place_on;
if (block.states) json.states = block.states;
if (block.components) json.components = block.components;
return json;
@@ -148,6 +150,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
if (json.drops !== undefined) block.drop_table = json.drops;
if (json.interactive) block.interactive = true;
if (json.replaceable) block.replaceable = true;
if (json.place_on) block.place_on = json.place_on;
if (json.states) block.states = json.states;
if (json.components) block.components = json.components;
return { block, has_item: json.item ?? true };
@@ -337,6 +340,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");
} else {
for (const id of json.place_on) problems.push(...validate_id(id, "place_on"));
}
}
if (json.states !== undefined) {
const states = json.states;
if (!Array.isArray(states)) {