Rename engine to cubi

This commit is contained in:
2026-11-03 17:17:37 -03:00
parent 68b78f053a
commit 98fa45ebd1
109 changed files with 643 additions and 788 deletions
+11 -11
View File
@@ -169,7 +169,7 @@ export interface PlacedModel {
collision_shape?: number[][];
}
export const DEFAULT_MODEL = "engine:cube";
export const DEFAULT_MODEL = "cubi:cube";
const cube_face = (texture: string, cullface: ModelFace): ModelFaceJson => ({ texture, cullface });
@@ -177,8 +177,8 @@ const cube_face = (texture: string, cullface: ModelFace): ModelFaceJson => ({ te
export const BUILTIN_MODELS: Record<string, ModelJson> = {
// a full block. "textures" can be one texture, { top, bottom, side } or { front, side }. the front is north, like
// minecraft's furnace, so a facing state turns it towards whoever placed it
"engine:cube": {
id: "engine:cube",
"cubi:cube": {
id: "cubi:cube",
textures: { top: "#side", bottom: "#side", front: "#side" },
elements: [{
from: [0, 0, 0],
@@ -194,16 +194,16 @@ export const BUILTIN_MODELS: Record<string, ModelJson> = {
}],
},
// two crossed planes, like flowers and saplings. uses the "cross" texture
"engine:cross": {
id: "engine:cross",
"cubi:cross": {
id: "cubi:cross",
elements: [
cross_plane(45),
cross_plane(-45),
],
},
// four planes in a # shape, like wheat. uses the "crop" texture
"engine:crop": {
id: "engine:crop",
"cubi:crop": {
id: "cubi:crop",
elements: [
{ from: [4, 0, 0], to: [4, 16, 16], shade: false, faces: both_ways("west", "east", "#crop") },
{ from: [12, 0, 0], to: [12, 16, 16], shade: false, faces: both_ways("west", "east", "#crop") },
@@ -241,10 +241,10 @@ export function resolve_texture(reference: string, textures: BlockTextures | und
const name = reference.slice(1);
if (typeof textures === "string") return textures;
const next = (textures as Record<string, string> | undefined)?.[name] ?? model?.textures?.[name];
if (next === undefined) return "engine:missing";
if (next === undefined) return "cubi:missing";
reference = next;
}
return reference.startsWith("#") ? "engine:missing" : reference;
return reference.startsWith("#") ? "cubi:missing" : reference;
}
// the variables a texture reference goes through before it's a texture id, "#front" on a cube is front then side
@@ -358,14 +358,14 @@ export function block_item_texture(block: BlockRegistry): string | undefined {
}
const textures = block.textures;
if (typeof textures === "string") return textures;
return Object.values(textures)[0] ?? "engine:missing";
return Object.values(textures)[0] ?? "cubi:missing";
}
export function cube_face_texture(block: BlockRegistry, face: "top" | "bottom" | "front" | "side") {
return resolve_texture(`#${face}`, cube_textures(block), BUILTIN_MODELS[DEFAULT_MODEL]);
}
// the block's textures as engine:cube's. a fluid's { still, flowing } are its top and bottom, and its sides, for its
// the block's textures as cubi:cube's. a fluid's { still, flowing } are its top and bottom, and its sides, for its
// item and its particles. the chunk mesher draws fluids itself
export function cube_textures(block: BlockRegistry): BlockTextures {
if (!block.fluid) return block.textures;
+1 -1
View File
@@ -203,7 +203,7 @@ export class BlockRules {
let neighbor: SharedBlock | undefined;
for (const { mod, id: rules_id, rules, params } of this.#of(block)) {
if (!rules.on_neighbor_change) continue;
const changed = neighbor ??= { ...from, id: this.get_block(from.x, from.y, from.z) ?? "bworld:air" };
const changed = neighbor ??= { ...from, id: this.get_block(from.x, from.y, from.z) ?? "cubi:air" };
const at = { x, y, z, id };
this.run(mod, `${rules_id} on_neighbor_change`, () => rules.on_neighbor_change!(at, params, changed));
}
-148
View File
@@ -1,148 +0,0 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
import { EverythingRegistry } from "$/common/everything_registry.ts";
interface CropsRegistry {
total_stages: number;
time_to_grow: number[];
item_drop: string;
sprite_ids: string[];
regrowable: boolean;
}
EverythingRegistry.register<CropsRegistry>("crops", "bworld:carrot", {
total_stages: 5,
time_to_grow: [60, 60 * 3, 60 * 3, 60 * 3],
sprite_ids: [
"bworld:carrot_seeds",
"bworld:carrot_stage_1",
"bworld:carrot_stage_2",
"bworld:carrot_stage_3",
"bworld:carrot_stage_4",
],
item_drop: "bworld:carrot",
regrowable: false,
});
EverythingRegistry.register<CropsRegistry>("crops", "bworld:potato", {
total_stages: 5,
time_to_grow: [45, 60 * 2, 60 * 2, 60 * 2],
sprite_ids: [
"bworld:potato_seeds",
"bworld:potato_stage_1",
"bworld:potato_stage_2",
"bworld:potato_stage_3",
"bworld:potato_stage_4",
],
item_drop: "bworld:potato",
regrowable: false,
});
EverythingRegistry.register<CropsRegistry>("crops", "bworld:tomato", {
total_stages: 5,
time_to_grow: [90, 60 * 2, 60 * 2, 60 * 3],
sprite_ids: [
"bworld:tomato_seeds",
"bworld:tomato_stage_1",
"bworld:tomato_stage_2",
"bworld:tomato_stage_3",
"bworld:tomato_stage_4",
],
item_drop: "bworld:tomato",
regrowable: true,
});
EverythingRegistry.register<CropsRegistry>("crops", "bworld:pumpkin", {
total_stages: 5,
time_to_grow: [60 * 2, 60 * 4, 60 * 4, 60 * 4],
sprite_ids: [
"bworld:pumpkin_seeds",
"bworld:pumpkin_stage_1",
"bworld:pumpkin_stage_2",
"bworld:pumpkin_stage_3",
"bworld:pumpkin_stage_4",
],
item_drop: "bworld:pumpkin",
regrowable: false,
});
interface TileCropData {
current_stage: number;
growth_time: number;
}
/*
function create_crop_tile(crop_id: string) {
const crop_info = EverythingRegistry.get<CropsRegistry>("crops", crop_id);
return {
has_collision: false,
on_create(_, tile) {
tile.data = {
current_stage: 0,
growth_time: 0,
};
},
texture_id(tile) {
return crop_info.sprite_ids[tile.data!.current_stage];
},
on_click(world, tile) {
const [player] = world.get_tag("player")!;
const player_inventory = player.get(PlayerComponent)!.player_inventory;
const item = player_inventory.container.get_item(player_inventory.hotbar_selected);
if (!item) {
return;
}
if (item.type_id === "bworld:pickaxe") {
world.dimension.delete_tile(world, tile);
}
},
on_interact(world, tile) {
if (tile.data!.current_stage + 1 !== crop_info.total_stages) {
return;
}
const [player] = world.get_tag("player")!;
const player_inventory = player.get(PlayerComponent)!.player_inventory;
player_inventory.container.add_item(new ItemStack(crop_info.item_drop));
if (crop_info.regrowable) {
tile.data!.current_stage -= 1;
} else {
world.dimension.delete_tile(world, tile);
}
},
on_second(_, tile, delta) {
const crop = tile.data!;
// finished growing
if (crop.current_stage + 1 === crop_info.total_stages) {
return;
}
// grow !
crop.growth_time += delta;
if (crop.growth_time >= crop_info.time_to_grow[crop.current_stage]) {
crop.current_stage += 1;
crop.growth_time = 0;
}
},
} as BlockRegistry<TileCropData>;
}
EverythingRegistry.register<BlockRegistry<TileCropData>>(
"blocks",
"bworld:tomato_crop",
create_crop_tile("bworld:tomato"),
);
EverythingRegistry.register<BlockRegistry<TileCropData>>(
"blocks",
"bworld:carrot_crop",
create_crop_tile("bworld:carrot"),
);
EverythingRegistry.register<BlockRegistry<TileCropData>>(
"blocks",
"bworld:potato_crop",
create_crop_tile("bworld:potato"),
);
EverythingRegistry.register<BlockRegistry<TileCropData>>(
"blocks",
"bworld:pumpkin_crop",
create_crop_tile("bworld:pumpkin"),
);
*/
+1 -1
View File
@@ -377,7 +377,7 @@ function registry_id(registry: string, what: string): ArgumentType<string> {
suggest(partial) {
return EverythingRegistry.entries(registry)
.map(([id]) => id)
.filter((id) => id !== "bworld:air" && (id.startsWith(partial) || id.split(":")[1].startsWith(partial)))
.filter((id) => id !== "cubi:air" && (id.startsWith(partial) || id.split(":")[1].startsWith(partial)))
.map((id) => ({ text: id }));
},
};
+1 -1
View File
@@ -49,7 +49,7 @@ export const PLAYER_EYE_HEIGHT = 1.69;
export const PLAYER_SWIM_HEIGHT = 0.8;
export const PLAYER_SWIM_EYE_HEIGHT = 0.6;
// the stages of cracks on a block being broken, 0 to this, each drawn with engine:break_<stage>
// the stages of cracks on a block being broken, 0 to this, each drawn with cubi:break_<stage>
export const BREAK_STAGES = 8;
// where a block placed against each face of another block goes
+3 -3
View File
@@ -71,7 +71,7 @@ export class EverythingRegistry {
}
// one texture for everything, or the model's texture variables: { top, bottom, side } or { front, side } for
// cubes, { crop } for engine:crop and so on
// cubes, { crop } for cubi:crop and so on
export type BlockTextures = string | Record<string, string>;
export interface BlockStateDefinition {
@@ -106,7 +106,7 @@ export interface BlockRegistry {
// what players see, like "Iron Ore". made from the id when not set, see display_name in common/utils.ts
name?: string;
textures: BlockTextures;
// the block model, engine:cube when not set. see common/block_models.ts
// the block model, cubi:cube when not set. see common/block_models.ts
model?: string;
// solid when not set. anything else doesn't hide its neighbors' faces
render_layer?: RenderLayer;
@@ -199,7 +199,7 @@ export function is_fluid_block(block: BlockRegistry | undefined): boolean {
// a fluid's textures as the top, bottom and sides of a cube, for its item and its particles
export function fluid_textures(textures: BlockTextures): { still: string; flowing: string } {
if (typeof textures === "string") return { still: textures, flowing: textures };
const still = textures.still ?? "engine:missing";
const still = textures.still ?? "cubi:missing";
return { still, flowing: textures.flowing ?? still };
}
+2 -2
View File
@@ -177,10 +177,10 @@ function generate_features(
return undefined;
}
const nid = blocks[y * CHUNK_AREA + local(x, z, "get_block")] & ID_MASK;
return nid === AIR ? "bworld:air" : ids_by_nid[nid];
return nid === AIR ? "cubi:air" : ids_by_nid[nid];
},
set_block(x, y, z, id) {
const nid = id === "bworld:air" ? AIR : block_ids[id];
const nid = id === "cubi:air" ? AIR : block_ids[id];
if (nid === undefined) {
throw new Error(`unknown block ${id}`);
}
+3 -3
View File
@@ -326,7 +326,7 @@ export interface ServerWorld {
// an item lying still at x y z, which players can pick up after half a second, like a new minecraft ItemEntity
spawn_item(x: number, y: number, z: number, item: ItemStack): EntityRef;
// the entities whose boxes touch the box between two corners, like minecraft's getEntitiesOfClass. only ones of type
// when given, like "bworld:item" for items lying around. players aren't among them, they're in ctx.players
// when given, like "cubi:item" for items lying around. players aren't among them, they're in ctx.players
entities_in(from: Position, to: Position, type?: Id): EntityRef[];
// uses item on face of the block at x y z the way a player holding it would, like a deployer: the block's
// on_interact, or the item's on_use, or placing it. a player that isn't anyone does it, standing in the block in
@@ -456,7 +456,7 @@ export interface Player {
set_worn(key: string, items: ItemStack[]): void;
teleport(x: number, y: number, z: number): void;
// health and hunger, like minecraft: 20 each, saturation is never above hunger. max_health is the
// bworld:max_health attribute
// cubi:max_health attribute
readonly health: number;
readonly max_health: number;
readonly food: number;
@@ -468,7 +468,7 @@ export interface Player {
feed(nutrition: number, saturation_modifier: number): void;
// tires them out: 4 costs a point of saturation, or of hunger once it's gone
add_exhaustion(amount: number): void;
// their stats, like minecraft's attributes: "bworld:attack_damage", "bworld:attack_speed", "bworld:max_health"...
// their stats, like minecraft's attributes: "cubi:attack_damage", "cubi:attack_speed", "cubi:max_health"...
// see docs/modding/entities/players.md. modifiers aren't saved, they're gone when the player leaves
attribute(id: Id): number;
// replaces one with the same id on that attribute
+1 -1
View File
@@ -189,7 +189,7 @@ export interface SharedContext {
}
export interface SharedWorld {
// undefined when the chunk isn't loaded, "bworld:air" for air
// undefined when the chunk isn't loaded, "cubi:air" for air
get_block(x: number, y: number, z: number): Id | undefined;
get_state(x: number, y: number, z: number, name: string): number | undefined;
// changing what a block is tells the blocks beside it, see BlockRules.on_neighbor_change
+4 -4
View File
@@ -134,7 +134,7 @@ export function load_order(mods: LoadedMod[]): LoadedMod[] {
// it has none, and an item file without a texture only adds to its block's item
export function registered_ids(mods: LoadedMod[]): Record<TagRegistry, Set<string>> {
const ids: Record<TagRegistry, Set<string>> = {
blocks: new Set(["bworld:air"]),
blocks: new Set(["cubi:air"]),
items: new Set(),
entities: new Set(),
biomes: new Set(),
@@ -151,7 +151,7 @@ export function registered_ids(mods: LoadedMod[]): Record<TagRegistry, Set<strin
return ids;
}
// engine_textures are the engine: texture ids, for telling whether a texture a mod uses exists
// engine_textures are the cubi: texture ids, for telling whether a texture a mod uses exists
export function check_references(mods: LoadedMod[], engine_textures: Iterable<string>) {
const block_owners = new Map<string, string[]>();
const item_owners = new Map<string, string[]>();
@@ -240,7 +240,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
const tag = id.startsWith("#");
const namespace = id.replace("#", "").split(":")[0];
if (tag && namespace === SHARED_TAG_NAMESPACE) return;
if (namespace !== mod.id && namespace !== "engine" && !dependencies.has(namespace)) {
if (namespace !== mod.id && namespace !== "cubi" && !dependencies.has(namespace)) {
warnings.push(`${file}: uses ${id} but doesn't list "${namespace}" in dependencies`);
}
};
@@ -290,7 +290,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
}
}
for (const id of [...(json.place_on ?? []), ...(json.place_in ?? [])]) {
if (id !== "bworld:air") uses(file, id, "block");
if (id !== "cubi:air") uses(file, id, "block");
}
}
for (const { file, json } of mod.models) {
+3 -3
View File
@@ -43,7 +43,7 @@ import {
export const FORMAT_VERSION = 1;
export const NAMESPACE_PATTERN = /^[a-z0-9_]{1,32}$/;
export const RESERVED_NAMESPACES = ["bworld", "engine"];
export const RESERVED_NAMESPACES = ["bworld", "cubi"];
// the namespace for tags every mod shares, like neoforge's. no mod owns it
export const SHARED_TAG_NAMESPACE = "c";
export const TAG_REGISTRIES = ["blocks", "items", "entities", "biomes"] as const;
@@ -256,7 +256,7 @@ function check_block(block: z.infer<typeof block_fields>, ctx: z.RefinementCtx)
problem(["states"], `can't have "${FLUID_LEVEL.name}", a fluid gets that state of its own`);
}
if (block.waterloggable !== undefined) problem(["waterloggable"], "isn't for fluids");
} else if (block.parts === undefined && (block.model ?? "engine:cube") === "engine:cube") {
} else if (block.parts === undefined && (block.model ?? "cubi:cube") === "cubi:cube") {
if (!cube_textures.safeParse(block.textures).success) {
problem(["textures"], "must be a texture id, { top, bottom, side } or { front, side }");
}
@@ -484,7 +484,7 @@ const fluid_schema = z.object({
name: text.optional(),
// for whatever shows it, like a layer tinted "fluid" on a full container
color,
// what a box of it is drawn with, tinted by its color, like neoforge's still texture. engine:missing when not set
// what a box of it is drawn with, tinted by its color, like neoforge's still texture. cubi:missing when not set
texture: z.string().optional(),
// what 1000 mB of it is worth when sold in a fluid container, like an item's base_sell_value
base_sell_value: z.int().min(0).optional(),
+1 -1
View File
@@ -111,7 +111,7 @@ export class ModLoadError extends Error {
// whether a block, item, entity or biome is registered, for tags. air isn't a registered block, but tags can hold it
export function is_registered(registry: TagRegistry, id: string): boolean {
return (registry === "blocks" && id === "bworld:air") || EverythingRegistry.get(registry, id) !== undefined;
return (registry === "blocks" && id === "cubi:air") || EverythingRegistry.get(registry, id) !== undefined;
}
// registers every mod's blocks, items, entities, effects, fluids, tags and recipes, in the order given (dependencies
+2 -2
View File
@@ -7,11 +7,11 @@ import type { ItemData } from "./inventory.ts";
import type { FluidVariant } from "./mod_api/shared.ts";
import type { ModListing } from "./mod_loader.ts";
export const AIR_ID = "bworld:air";
export const AIR_ID = "cubi:air";
// bump when a client and server of different versions can't play together.
// the server rejects a different version before the client downloads anything
export const PROTOCOL_VERSION = 25;
export const PROTOCOL_VERSION = 26;
export interface PlayerInfo {
id: string;
+2 -2
View File
@@ -74,7 +74,7 @@ export function item_texture(
item: ItemStack,
info = EverythingRegistry.get<ItemRegistry>("items", item.type_id),
): string {
if (!info) return "engine:missing";
if (!info) return "cubi:missing";
const data = item.data as Record<string, unknown> | undefined;
for (const [key, texture] of Object.entries(info.data_textures ?? {})) {
if (data?.[key]) return texture;
@@ -234,7 +234,7 @@ export function can_place(
below: string,
): boolean {
if (!block) return false;
const into = current?.id ?? "bworld:air";
const into = current?.id ?? "cubi:air";
const replaceable = !current || current.replaceable === true;
const in_ok = block.place_in ? list_matches("blocks", block.place_in, into) : replaceable;
// one that's only ever waterlogged goes into a source of its fluid and nothing else