Fluid registry
This commit is contained in:
+15
-4
@@ -11,6 +11,7 @@ import {
|
||||
type EffectJson,
|
||||
type EntityJson,
|
||||
type EntityModelJson,
|
||||
type FluidJson,
|
||||
type ItemJson,
|
||||
type ManifestJson,
|
||||
type OreJson,
|
||||
@@ -21,6 +22,7 @@ import {
|
||||
validate_effect,
|
||||
validate_entity,
|
||||
validate_entity_model,
|
||||
validate_fluid,
|
||||
validate_item,
|
||||
validate_manifest,
|
||||
validate_model,
|
||||
@@ -79,8 +81,8 @@ export class BmodError extends Error {
|
||||
|
||||
// the zip's layout:
|
||||
// manifest.json the mod's manifest, with "scripts" and "credits" pointing into the zip
|
||||
// data.json every block, model, item, recipe, ore, entity, entity model, effect, tag, loot table and
|
||||
// biome, and the mod's config
|
||||
// data.json every block, model, item, recipe, ore, entity, entity model, effect, fluid, tag, loot
|
||||
// table and biome, and the mod's config
|
||||
// scripts/<side>.js
|
||||
// textures/<name>.png the texture <mod id>:<name>
|
||||
// textures/<name>.json its animation, if it has one
|
||||
@@ -177,6 +179,7 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
problems,
|
||||
) as EntityModelJson[],
|
||||
effects: checked(raw_data.effects, "effects", validate_effect, problems) as EffectJson[],
|
||||
fluids: checked(raw_data.fluids, "fluids", validate_fluid, problems) as FluidJson[],
|
||||
tags: checked(raw_data.tags, "tags", validate_tag, problems) as TagJson[],
|
||||
loot_tables: checked(raw_data.loot_tables, "loot_tables", validate_loot_table, problems) as LootTableJson[],
|
||||
biomes: checked(raw_data.biomes, "biomes", validate_biome, problems) as BiomeJson[],
|
||||
@@ -206,7 +209,15 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
problems.push("data.json: config must be an object");
|
||||
}
|
||||
// a mod only registers ids in its own namespace
|
||||
const registered = [...data.blocks, ...data.models, ...data.items, ...data.entities, ...data.entity_models];
|
||||
const registered = [
|
||||
...data.blocks,
|
||||
...data.models,
|
||||
...data.items,
|
||||
...data.entities,
|
||||
...data.entity_models,
|
||||
...data.effects,
|
||||
...data.fluids,
|
||||
];
|
||||
const worldgen = [
|
||||
...data.noises!,
|
||||
...data.density_functions!,
|
||||
@@ -214,7 +225,7 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
...data.biome_sources!,
|
||||
...data.features!,
|
||||
];
|
||||
for (const { id } of [...registered, ...data.effects, ...data.loot_tables!, ...data.biomes!, ...worldgen]) {
|
||||
for (const { id } of [...registered, ...data.loot_tables!, ...data.biomes!, ...worldgen]) {
|
||||
if (typeof id === "string" && id.split(":")[0] !== mod) problems.push(`${id} isn't in this mod's namespace`);
|
||||
}
|
||||
|
||||
|
||||
+14
-3
@@ -9,6 +9,7 @@ import {
|
||||
type EffectJson,
|
||||
type EntityJson,
|
||||
type EntityModelJson,
|
||||
type FluidJson,
|
||||
type ItemJson,
|
||||
type OreJson,
|
||||
type RecipeJson,
|
||||
@@ -58,6 +59,7 @@ export interface LoadedMod {
|
||||
entities: { file: string; json: EntityJson }[];
|
||||
entity_models: { file: string; json: EntityModelJson }[];
|
||||
effects: { file: string; json: EffectJson }[];
|
||||
fluids: { file: string; json: FluidJson }[];
|
||||
tags: { file: string; json: TagJson }[];
|
||||
loot_tables: { file: string; json: LootTableJson }[];
|
||||
biomes: { file: string; json: BiomeJson }[];
|
||||
@@ -88,6 +90,7 @@ export function mod_data(mod: LoadedMod): ModData {
|
||||
entities: mod.entities.map((e) => e.json),
|
||||
entity_models: mod.entity_models.map((m) => m.json),
|
||||
effects: mod.effects.map((e) => e.json),
|
||||
fluids: mod.fluids.map((f) => f.json),
|
||||
tags: mod.tags.map((t) => t.json),
|
||||
loot_tables: mod.loot_tables.map((t) => t.json),
|
||||
biomes: mod.biomes.map((b) => b.json),
|
||||
@@ -159,8 +162,10 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
const entity_model_owners = new Map<string, string[]>();
|
||||
const entity_model_jsons = new Map<string, EntityModelJson>();
|
||||
const effect_owners = new Map<string, string[]>();
|
||||
const fluid_owners = new Map<string, string[]>();
|
||||
const tag_owners = new Map<TagRegistry, Set<string>>();
|
||||
const fluids = new Set<string>();
|
||||
// blocks that flow, which waterloggable blocks can hold
|
||||
const fluid_blocks = new Set<string>();
|
||||
const loot_tables = new Set<string>();
|
||||
const biome_owners = new Map<string, string[]>();
|
||||
const add = (map: Map<string, string[]>, id: string, mod: string) => map.set(id, [...(map.get(id) ?? []), mod]);
|
||||
@@ -181,7 +186,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
for (const { json } of mod.blocks) {
|
||||
add(block_owners, json.id, mod.id);
|
||||
if (json.item !== false) add(item_owners, json.id, mod.id);
|
||||
if (json.fluid) fluids.add(json.id);
|
||||
if (json.fluid) fluid_blocks.add(json.id);
|
||||
}
|
||||
// one without a texture is the item of the mod's block, which is already counted
|
||||
for (const { json } of mod.items) if (json.texture !== undefined) add(item_owners, json.id, mod.id);
|
||||
@@ -198,6 +203,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
entity_model_jsons.set(json.id, json);
|
||||
}
|
||||
for (const { json } of mod.effects) add(effect_owners, json.id, mod.id);
|
||||
for (const { json } of mod.fluids) add(fluid_owners, json.id, mod.id);
|
||||
for (const { json } of mod.loot_tables ?? []) loot_tables.add(json.id);
|
||||
for (const { json } of mod.biomes ?? []) add(biome_owners, json.id, mod.id);
|
||||
for (const { json } of mod.noises ?? []) add(worldgen_owners.noise, json.id, mod.id);
|
||||
@@ -279,7 +285,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
if (json.loot_table) uses(file, json.loot_table, "loot table");
|
||||
if (json.waterloggable) {
|
||||
uses(file, json.waterloggable, "block");
|
||||
if (block_owners.has(json.waterloggable) && !fluids.has(json.waterloggable)) {
|
||||
if (block_owners.has(json.waterloggable) && !fluid_blocks.has(json.waterloggable)) {
|
||||
errors.push(`${file}: waterloggable ${json.waterloggable} isn't a fluid`);
|
||||
}
|
||||
}
|
||||
@@ -474,6 +480,11 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
}
|
||||
if (json.icon !== undefined) uses(file, json.icon, "texture");
|
||||
}
|
||||
for (const { file, json } of mod.fluids) {
|
||||
if ((fluid_owners.get(json.id)?.length ?? 0) > 1) {
|
||||
errors.push(`${file}: fluid ${json.id} is also defined by ${fluid_owners.get(json.id)!.join(", ")}`);
|
||||
}
|
||||
}
|
||||
for (const { file, json } of mod.spawns) {
|
||||
check_namespace(file, json.entity);
|
||||
const entity = entity_jsons.get(json.entity);
|
||||
|
||||
@@ -25,6 +25,7 @@ import { expand_items, list_matches } from "./tags.ts";
|
||||
import { GAME_VERSION } from "./constants.ts";
|
||||
import {
|
||||
by_kind,
|
||||
color,
|
||||
find_problems,
|
||||
id,
|
||||
id_or_tag,
|
||||
@@ -456,6 +457,18 @@ const effect_schema = z.object({
|
||||
|
||||
export type EffectJson = z.infer<typeof effect_schema>;
|
||||
|
||||
// a kind of fluid, like neoforge's FluidType: what it is apart from any block, container or amount. a block flows in
|
||||
// the world with its own "fluid" field, which is another thing
|
||||
const fluid_schema = z.object({
|
||||
id,
|
||||
// what players see, from the id when not set like an item's
|
||||
name: text.optional(),
|
||||
// for whatever shows it, like a container's tinted overlay
|
||||
color,
|
||||
});
|
||||
|
||||
export type FluidJson = z.infer<typeof fluid_schema>;
|
||||
|
||||
// a box from origin to origin + size, textured like minecraft's box uv: see the renderer's FACES
|
||||
const entity_cube = z.object({
|
||||
origin: vec3,
|
||||
@@ -869,6 +882,10 @@ export function validate_effect(json: unknown): Problems {
|
||||
return find_problems(effect_schema, json);
|
||||
}
|
||||
|
||||
export function validate_fluid(json: unknown): Problems {
|
||||
return find_problems(fluid_schema, json);
|
||||
}
|
||||
|
||||
export function validate_entity_model(json: unknown): Problems {
|
||||
return find_problems(entity_model_schema, json);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
EffectJson,
|
||||
EntityJson,
|
||||
EntityModelJson,
|
||||
FluidJson,
|
||||
grid_recipe_from_json,
|
||||
GridRecipe,
|
||||
is_mod_recipe,
|
||||
@@ -45,6 +46,8 @@ export interface ModData {
|
||||
entity_models: EntityModelJson[];
|
||||
// status effects, see EffectJson
|
||||
effects: EffectJson[];
|
||||
// kinds of fluid, see FluidJson
|
||||
fluids: FluidJson[];
|
||||
// tag files, see common/tags.ts
|
||||
tags: TagJson[];
|
||||
// see common/loot.ts. missing from mods packed before there were loot tables
|
||||
@@ -103,8 +106,9 @@ export function is_registered(registry: TagRegistry, id: string): boolean {
|
||||
return (registry === "blocks" && id === "bworld:air") || EverythingRegistry.get(registry, id) !== undefined;
|
||||
}
|
||||
|
||||
// registers every mod's blocks, items, entities, effects, tags and recipes, in the order given (dependencies first). tags load
|
||||
// once every mod's content has, since a tag can hold anything, and recipes after them, since they can use tags
|
||||
// registers every mod's blocks, items, entities, effects, fluids, tags and recipes, in the order given (dependencies
|
||||
// first). tags load once every mod's content has, since a tag can hold anything, and recipes after them, since they can
|
||||
// use tags
|
||||
export function register_mod_data(mods: { id: string; data: ModData }[]): RecipeBook {
|
||||
const recipes = new RecipeBook();
|
||||
|
||||
@@ -147,6 +151,9 @@ export function register_mod_data(mods: { id: string; data: ModData }[]): Recipe
|
||||
for (const json of data.effects) {
|
||||
EverythingRegistry.register<EffectJson>("effects", json.id, json);
|
||||
}
|
||||
for (const json of data.fluids) {
|
||||
EverythingRegistry.register<FluidJson>("fluids", json.id, json);
|
||||
}
|
||||
for (const json of data.loot_tables ?? []) {
|
||||
EverythingRegistry.register<LootTableJson>("loot_tables", json.id, json);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ export const loot_table_id = z.string('must be a loot table id, like "my_mod:blo
|
||||
// text players see
|
||||
export const text = z.string().min(1);
|
||||
export const vec3 = z.tuple([z.number(), z.number(), z.number()], "must be [x, y, z]");
|
||||
export const color = z.string('must be a color like "#79c05a"').regex(/^#[0-9a-fA-F]{6}$/);
|
||||
// any json object, for what's only stored, like components
|
||||
export const json_object = z.record(z.string(), z.unknown());
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// gets is the generator's biome rules (worldgen/biome_source), these say what a biome looks like once it's picked
|
||||
import * as z from "zod";
|
||||
import { EverythingRegistry } from "../everything_registry.ts";
|
||||
import { find_problems, id, type Problems } from "../schema.ts";
|
||||
import { color, find_problems, id, type Problems } from "../schema.ts";
|
||||
import { farming_day } from "../time.ts";
|
||||
|
||||
export const SEASONS = ["spring", "summer", "autumn", "winter"] as const;
|
||||
@@ -27,8 +27,6 @@ const surface_schema = z.object({
|
||||
|
||||
export type SurfaceJson = z.infer<typeof surface_schema>;
|
||||
|
||||
const color = z.string('must be a color like "#79c05a"').regex(/^#[0-9a-fA-F]{6}$/);
|
||||
|
||||
const biome_schema = z.object({
|
||||
id,
|
||||
// a season it's always in, like winter for snowy biomes. when not set it follows the calendar, see calendar_season
|
||||
|
||||
@@ -93,6 +93,7 @@ export async function load_bundle(bundle: WorldgenBundle): Promise<LoadedBundle>
|
||||
entities: [],
|
||||
entity_models: [],
|
||||
effects: [],
|
||||
fluids: [],
|
||||
loot_tables: [],
|
||||
},
|
||||
})));
|
||||
|
||||
Reference in New Issue
Block a user