Loot tables
This commit is contained in:
@@ -79,6 +79,8 @@ export interface BlockJson {
|
||||
item_display?: { surface: number };
|
||||
// makes it a liquid, see LiquidProperties. range is 7 when not set
|
||||
liquid?: Partial<LiquidProperties>;
|
||||
// what it drops when broken, see common/loot.ts. drops is the shorthand for one of an item
|
||||
loot_table?: string;
|
||||
// the liquid it can hold, see BlockRegistry.waterloggable
|
||||
waterloggable?: string;
|
||||
// only placed into a source of it, see BlockRegistry.waterlogged_only
|
||||
@@ -152,6 +154,8 @@ export interface EntityJson {
|
||||
// protection from physical and from arcane damage, not used yet
|
||||
physical_shielding?: number;
|
||||
arcane_shielding?: number;
|
||||
// what it drops when it dies, see common/loot.ts
|
||||
loot_table?: string;
|
||||
}
|
||||
|
||||
// a status effect, like neoforge's MobEffect. what it does over time comes from components scripts register, see
|
||||
@@ -301,6 +305,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
|
||||
if (block.tool_tier) json.mining.tier = block.tool_tier;
|
||||
}
|
||||
if (block.drop_table !== undefined) json.drops = block.drop_table;
|
||||
if (block.loot_table !== undefined) json.loot_table = block.loot_table;
|
||||
if (!has_item) json.item = false;
|
||||
if (block.interactive) json.interactive = true;
|
||||
if (!!block.replaceable !== !!block.liquid) json.replaceable = !!block.replaceable;
|
||||
@@ -351,6 +356,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
|
||||
if (json.mining.tier) block.tool_tier = json.mining.tier;
|
||||
}
|
||||
if (json.drops !== undefined) block.drop_table = json.drops;
|
||||
if (json.loot_table !== undefined) block.loot_table = json.loot_table;
|
||||
if (json.interactive) block.interactive = true;
|
||||
if (json.replaceable ?? json.liquid) block.replaceable = true;
|
||||
if (json.place_on) block.place_on = json.place_on;
|
||||
@@ -661,6 +667,12 @@ export function validate_block(json: unknown): Problems {
|
||||
}
|
||||
}
|
||||
if (json.drops !== undefined) problems.push(...validate_id(json.drops, "drops"));
|
||||
if (json.loot_table !== undefined) {
|
||||
if (!(typeof json.loot_table === "string" && TAG_ID_PATTERN.test(json.loot_table))) {
|
||||
problems.push('loot_table must be a loot table id, like "my_mod:blocks/thing"');
|
||||
}
|
||||
if (json.drops !== undefined) problems.push("drops and loot_table can't both be set, drops is one item");
|
||||
}
|
||||
if (json.item_display !== undefined) {
|
||||
const surface = is_object(json.item_display) ? json.item_display.surface : undefined;
|
||||
if (typeof surface !== "number" || surface < 0 || surface > 16) {
|
||||
@@ -1005,6 +1017,11 @@ export function validate_entity(json: unknown): Problems {
|
||||
if (json.behavior !== undefined && !["animal", "monster", "scripted"].includes(json.behavior as string)) {
|
||||
problems.push('behavior must be "animal", "monster" or "scripted"');
|
||||
}
|
||||
if (
|
||||
json.loot_table !== undefined && !(typeof json.loot_table === "string" && TAG_ID_PATTERN.test(json.loot_table))
|
||||
) {
|
||||
problems.push('loot_table must be a loot table id, like "my_mod:entities/thing"');
|
||||
}
|
||||
for (const key of ["width", "height"]) {
|
||||
if (typeof json[key] !== "number" || json[key] <= 0 || json[key] > 16) {
|
||||
problems.push(`${key} must be a number of blocks above 0, at most 16`);
|
||||
|
||||
Reference in New Issue
Block a user