Waterlogging
This commit is contained in:
+34
-3
@@ -13,6 +13,7 @@ import {
|
||||
RENDER_LAYERS,
|
||||
type RenderLayer,
|
||||
type ToolProperties,
|
||||
WATERLOGGED,
|
||||
type WornProperties,
|
||||
} from "./everything_registry.ts";
|
||||
import { type BlockPart, type BlockVariant, MODEL_FACES, type ModelFace } from "./block_models.ts";
|
||||
@@ -78,6 +79,10 @@ export interface BlockJson {
|
||||
item_display?: { surface: number };
|
||||
// makes it a liquid, see LiquidProperties. range is 7 when not set
|
||||
liquid?: Partial<LiquidProperties>;
|
||||
// the liquid it can hold, see BlockRegistry.waterloggable
|
||||
waterloggable?: string;
|
||||
// only placed into a source of it, see BlockRegistry.waterlogged_only
|
||||
waterlogged_only?: boolean;
|
||||
}
|
||||
|
||||
export interface OreJson {
|
||||
@@ -301,9 +306,12 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
|
||||
if (!!block.replaceable !== !!block.liquid) json.replaceable = !!block.replaceable;
|
||||
if (block.place_on) json.place_on = block.place_on;
|
||||
if (block.place_in) json.place_in = block.place_in;
|
||||
// a liquid's level state is its own, added when it loads
|
||||
const states = block.liquid ? block.states?.slice(0, -1) : block.states;
|
||||
if (states && (states.length > 0 || !block.liquid)) json.states = states;
|
||||
// a liquid's level state and a waterloggable block's waterlogged state are its own, added when it loads
|
||||
const added = block.liquid || block.waterloggable;
|
||||
const states = added ? block.states?.slice(0, -1) : block.states;
|
||||
if (states && (states.length > 0 || !added)) json.states = states;
|
||||
if (block.waterloggable) json.waterloggable = block.waterloggable;
|
||||
if (block.waterlogged_only) json.waterlogged_only = true;
|
||||
if (block.components) json.components = block.components;
|
||||
if (block.item_display) json.item_display = block.item_display;
|
||||
if (block.liquid) {
|
||||
@@ -355,6 +363,12 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
|
||||
// last, so the block's own states keep their bits
|
||||
block.states = [...block.states ?? [], { ...LIQUID_LEVEL }];
|
||||
}
|
||||
if (json.waterlogged_only) block.waterlogged_only = true;
|
||||
if (json.waterloggable) {
|
||||
block.waterloggable = json.waterloggable;
|
||||
// last too, see WATERLOGGED
|
||||
block.states = [...block.states ?? [], { ...WATERLOGGED }];
|
||||
}
|
||||
return { block, has_item: json.item ?? true };
|
||||
}
|
||||
|
||||
@@ -669,6 +683,23 @@ export function validate_block(json: unknown): Problems {
|
||||
} else {
|
||||
const bits = states.reduce((sum, s) => sum + (is_object(s) && typeof s.bits === "number" ? s.bits : 0), 0);
|
||||
if (bits > 16) problems.push(`states use ${bits} bits, the most is 16`);
|
||||
if (json.waterloggable !== undefined && bits + WATERLOGGED.bits > 16) {
|
||||
problems.push(`its states and waterlogged use more than 16 bits`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (json.waterloggable !== undefined) {
|
||||
problems.push(...validate_id(json.waterloggable, "waterloggable"));
|
||||
if (json.liquid !== undefined) problems.push("a liquid can't be waterloggable");
|
||||
const states = Array.isArray(json.states) ? json.states : [];
|
||||
if (states.some((state) => is_object(state) && state.name === WATERLOGGED.name)) {
|
||||
problems.push(`a waterloggable block gets a "${WATERLOGGED.name}" state of its own`);
|
||||
}
|
||||
}
|
||||
if (json.waterlogged_only !== undefined) {
|
||||
if (typeof json.waterlogged_only !== "boolean") problems.push("waterlogged_only must be true or false");
|
||||
else if (json.waterlogged_only && json.waterloggable === undefined) {
|
||||
problems.push("waterlogged_only needs waterloggable, the liquid it's placed into");
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
|
||||
Reference in New Issue
Block a user