Improve a buuuunch of textures and some reworks

This commit is contained in:
2026-09-27 18:05:20 -03:00
parent 9f47c709f1
commit b7ded817d9
186 changed files with 1486 additions and 124 deletions
+8 -3
View File
@@ -239,6 +239,7 @@ program**, so the server and each client can number blocks differently. Saves an
| `variants` | none | `variants` | A different `model`, `textures` or `y` rotation for some states, see [block models](#block-models). |
| `render_layer` | `solid` | `render_layer` | `solid`, `cutout` (texels fully opaque or fully clear, like leaves) or `translucent` (blended, like water and glass). Non-solid blocks don't hide their neighbors' faces. |
| `cull_same` | see meaning | `cull_same` | Hide faces between two of this block. Defaults to `true` for translucent blocks, `false` otherwise. |
| `tint` | none | `tint` | Draws its textures in a color: `{ "color": "grass" }` or `"foliage"` for the biome's (blended across biome edges, like minecraft's grass and leaves), or a fixed one like `"#80a755"`. `"textures": ["top"]` tints only those texture variables, like the grass block's top. Paint the textures grey. Its item uses plains' color. |
| `light_emission` | `0` | `light_emission` | Light level 0-15 it gives off, like a torch (14). |
| `light_opacity` | see meaning | `light_opacity` | How much light passing through it loses, 0-15. Defaults to `15` (blocks all light) for solid blocks and `0` otherwise. Leaves and water use `1`. |
| `alpha` | `1` | `alpha` | Opacity for translucent blocks. |
@@ -445,9 +446,9 @@ clients as part of the container it's in, so client screens can show it.
| `type` | Fields | Notes |
| --------- | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| `shaped` | `pattern` rows (space is empty), `key` letter to item id, `result` `{ id, count }` | Used by the crafting grid, fits anywhere in it |
| `furnace` | `input` item id, `output` `{ id, count }`, `cook_time` in ticks | Used by the furnace |
| `fuel` | `item` id, `burn_time` in ticks | Used by the furnace |
| `shaped` | `pattern` rows (space is empty), `key` letter to item id (or a list of ids), `result` `{ id, count }` | Used by the crafting grid, fits anywhere in it |
| `furnace` | `input` item id (or a list of ids), `output` `{ id, count }`, `cook_time` in ticks | Used by the furnace |
| `fuel` | `item` id (or a list of ids), `burn_time` in ticks | Used by the furnace |
| `smithing` | `tool` item id, `material` `{ id, count }`, optional `addition` item id, `result` item id | Used by the smithing table: upgrades the tool, keeping its data. Uses up the tool, `count` of the material and the addition |
A smithing recipe, `recipes/smithing_stone_pickaxe.json`:
@@ -478,6 +479,10 @@ A shaped recipe, for the crafting grid in the player's inventory screen:
}
```
Where a recipe takes an item, a list of ids means any of them fits, like every kind of planks in the stick recipe:
`"key": { "P": ["bworld:planks", "bworld:birch_planks"] }`. In a crafting grid each slot can hold a different one of
them, so a stick can be made from oak and birch planks together. The recipe viewer takes turns showing them.
Two furnace recipes with the same `input`, two smithing recipes with the same tool, material and addition, or two
shaped recipes with the same pattern and key, are a load error.
+10 -3
View File
@@ -45,6 +45,8 @@ export interface Chunk {
// blocks its generation put in neighboring chunks (leaves), as x, y, z, numeric id. kept so a neighbor that
// generates later, or unloads and comes back, still gets them
spills?: Int32Array;
// each column's biome grass then foliage color, once it's generated
biome_colors?: Uint32Array;
}
export interface ChunkMesh {
@@ -446,9 +448,12 @@ export class ClientLevel {
chunk.mesh_version += 1;
// copies, the worker lights the whole 3x3 area
const chunks: (Uint32Array | null)[] = [];
const biome_colors: (Uint32Array | null)[] = [];
for (let dz = -1; dz <= 1; dz++) {
for (let dx = -1; dx <= 1; dx++) {
chunks.push(this.get_chunk(chunk.x + dx, chunk.z + dz)?.blocks.slice() ?? null);
const neighbor = this.get_chunk(chunk.x + dx, chunk.z + dz);
chunks.push(neighbor?.blocks.slice() ?? null);
biome_colors.push(neighbor?.biome_colors ?? null);
}
}
this.workers.post({
@@ -457,6 +462,7 @@ export class ClientLevel {
chunk_z: chunk.z,
version: chunk.mesh_version,
chunks,
biome_colors,
camera: [camera.x, camera.y, camera.z],
}, chunks.filter((blocks) => blocks !== null).map((blocks) => blocks.buffer));
}
@@ -487,7 +493,7 @@ export class ClientLevel {
#on_worker_message(message: FromChunkWorker) {
if (message.type === "generated") {
this.#on_generated(message.chunk_x, message.chunk_z, message.blocks, message.spills);
this.#on_generated(message.chunk_x, message.chunk_z, message.blocks, message.spills, message.biome_colors);
} else if (message.type === "meshed") {
this.#on_meshed(message);
} else {
@@ -495,7 +501,7 @@ export class ClientLevel {
}
}
#on_generated(cx: number, cz: number, blocks: Uint32Array, spills: Int32Array) {
#on_generated(cx: number, cz: number, blocks: Uint32Array, spills: Int32Array, biome_colors: Uint32Array) {
const key = chunk_key(cx, cz);
// unloaded or cancelled while the worker was busy
if (!this.pending_generation.delete(key)) {
@@ -517,6 +523,7 @@ export class ClientLevel {
chunk.generated = true;
chunk.dirty = true;
chunk.spills = spills;
chunk.biome_colors = biome_colors;
// the same rules as the server (server/game/world.ts): a chunk's own blocks, then what its neighbors'
// features put in it, only where it has air. both ways, since the neighbors may have generated first
+5 -4
View File
@@ -5,7 +5,7 @@ import { get_sprite_region } from "$/client/sprites.ts";
import type { ItemEntity } from "$/client/entity/item_entity.ts";
import type { ItemStack } from "$/common/inventory.ts";
import { push_vertex, Texture } from "$/client/renderer/mod.ts";
import { block_item_texture, cube_face_texture } from "$/common/block_models.ts";
import { block_item_texture, cube_face_texture, cube_face_tint } from "$/common/block_models.ts";
import { item_model } from "./item_model.ts";
// how big items on the ground are drawn, minecraft's ground transform
@@ -82,7 +82,8 @@ export function push_item(atlas: Texture, item: ItemStack, transform: ItemTransf
for (const face of CUBE_FACES) {
const region = get_sprite_region(cube_face_texture(block, face.texture));
const corners = face.corners.map(([cx, cy, cz]) => transform(cx - 0.5, cy, cz - 0.5));
push_textured_quad(atlas, region, corners, face.shade);
const [r, g, b] = cube_face_tint(block, face.texture);
push_textured_quad(atlas, region, corners, [face.shade * r, face.shade * g, face.shade * b]);
}
return;
}
@@ -100,7 +101,7 @@ export function push_item(atlas: Texture, item: ItemStack, transform: ItemTransf
}
}
function push_textured_quad(atlas: Texture, region: { x: number; y: number }, corners: number[][], shade: number) {
function push_textured_quad(atlas: Texture, region: { x: number; y: number }, corners: number[][], color: number[]) {
const u0 = (region.x * TEXTURE_SIZE + UV_PAD) / atlas.width;
const v0 = (region.y * TEXTURE_SIZE + UV_PAD) / atlas.height;
const u1 = ((region.x + 1) * TEXTURE_SIZE - UV_PAD) / atlas.width;
@@ -109,7 +110,7 @@ function push_textured_quad(atlas: Texture, region: { x: number; y: number }, co
for (const i of [0, 1, 2, 0, 2, 3]) {
const [px, py, pz] = corners[i];
const [cu, cv] = CORNER_UVS[i];
push_vertex(px, py, pz, cu ? u1 : u0, cv ? v1 : v0, shade, shade, shade, 1);
push_vertex(px, py, pz, cu ? u1 : u0, cv ? v1 : v0, color[0], color[1], color[2], 1);
}
}
+4 -1
View File
@@ -3,7 +3,7 @@ import { get_sprite_region } from "$/client/sprites.ts";
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
import { AssetManager } from "$/client/assets.ts";
import { ItemStack } from "$/common/inventory.ts";
import { block_item_texture, cube_face_texture } from "$/common/block_models.ts";
import { block_item_texture, cube_face_texture, cube_face_tint } from "$/common/block_models.ts";
import { draw_text, draw_texture_region, draw_texture_region_skewed, Texture } from "$/client/renderer/mod.ts";
// the corners keep their size (times scale), the edges stretch along and the middle fills the rest, like minecraft's
@@ -146,6 +146,7 @@ function draw_item_block(block_info: BlockRegistry, x: number, y: number) {
{ x: cx, y: cy + half_h },
{ x: cx - half_w, y: cy },
],
...cube_face_tint(block_info, "top"),
);
draw_texture_region_skewed(
atlas,
@@ -159,6 +160,7 @@ function draw_item_block(block_info: BlockRegistry, x: number, y: number) {
{ x: cx, y: cy + half_h + height },
{ x: cx - half_w, y: cy + height },
],
...cube_face_tint(block_info, "side"),
);
draw_texture_region_skewed(
atlas,
@@ -172,5 +174,6 @@ function draw_item_block(block_info: BlockRegistry, x: number, y: number) {
{ x: cx, y: cy + half_h + height },
{ x: cx + half_w, y: cy + height },
],
...cube_face_tint(block_info, "front"),
);
}
+4
View File
@@ -46,6 +46,8 @@ export type ToChunkWorker =
version: number;
// copies of the blocks of the 3x3 chunks around it, going +x then +z from -x -z, for lighting
chunks: (Uint32Array | null)[];
// the same chunks' biome colors (see "generated"), blended across their edges
biome_colors: (Uint32Array | null)[];
// where the camera is, to sort the translucent quads
camera: number[];
}
@@ -75,6 +77,8 @@ export type FromChunkWorker =
blocks: Uint32Array;
// blocks that landed in other chunks (from features like a mod's trees), flattened as x, y, z, numeric id
spills: Int32Array;
// each column's biome grass color as 0xRRGGBB, x then z, then each column's foliage color
biome_colors: Uint32Array;
}
| {
type: "meshed";
+94 -10
View File
@@ -26,9 +26,17 @@ import {
UNALIGNED_GROUP,
} from "./chunk_messages.ts";
import { generate_raw_chunk, WorldgenSetup } from "$/common/generation.ts";
import { foliage_color, grass_color } from "$/common/worldgen/biome_colors.ts";
import { load_worldgen } from "$/common/worldgen_loader.ts";
import { default_block_value, get_state_value } from "$/common/utils.ts";
import { bake_model, block_variant, FACE_CORNERS, find_model, type ModelJson } from "$/common/block_models.ts";
import {
bake_model,
block_variant,
FACE_CORNERS,
find_model,
is_tinted,
type ModelJson,
} from "$/common/block_models.ts";
import {
choose_sort_type,
FACE_AXIS,
@@ -105,6 +113,8 @@ interface MeshQuad {
sprite: SpriteRegion;
// 4 weights per corner
light_weights: number[];
// 0xRRGGBB it's drawn in, GRASS or FOLIAGE for the biome's (see "tint"), or white
tint: number;
}
let models: Record<string, ModelJson> = {};
@@ -142,6 +152,7 @@ self.onmessage = async (event: MessageEvent<ToChunkWorker>) => {
case "mesh": {
region.fill(message.chunks);
region.compute(light_tables);
blend_biome_colors(message.biome_colors);
const { solid, cutout, translucent, min_y, max_y } = make_chunk_mesh(
message.chunk_x,
message.chunk_z,
@@ -193,8 +204,66 @@ function post(message: FromChunkWorker, transfer: Transferable[]) {
}
function generate(chunk_x: number, chunk_z: number, seed: string) {
const { blocks, spills } = generate_raw_chunk(chunk_x, chunk_z, seed, block_ids, worldgen, default_values);
post({ type: "generated", chunk_x, chunk_z, blocks, spills }, [blocks.buffer, spills.buffer]);
const { blocks, spills, biomes } = generate_raw_chunk(chunk_x, chunk_z, seed, block_ids, worldgen, default_values);
const biome_colors = new Uint32Array(CHUNK_AREA * 2);
biomes.forEach((biome, column) => {
biome_colors[column] = grass_color(biome);
biome_colors[CHUNK_AREA + column] = foliage_color(biome);
});
post({ type: "generated", chunk_x, chunk_z, blocks, spills, biome_colors }, [
blocks.buffer,
spills.buffer,
biome_colors.buffer,
]);
}
// like minecraft's biome blend at its default radius: each column's grass and foliage color is the average of the 5x5
// columns around it, so biome edges fade instead of being a line. neighbors that aren't there are left out
const BLEND_RADIUS = 2;
// the middle chunk's blended colors, x then z, grass then foliage
const blended = new Uint32Array(CHUNK_AREA * 2);
// what MeshQuad.tint is for the biome's colors, they aren't colors since those only go up to 0xffffff
const GRASS = -1;
const FOLIAGE = -2;
function blend_biome_colors(colors: (Uint32Array | null)[]) {
for (const offset of [0, CHUNK_AREA]) {
for (let z = 0; z < CHUNK_SIZE; z++) {
for (let x = 0; x < CHUNK_SIZE; x++) {
let r = 0;
let g = 0;
let b = 0;
let count = 0;
for (let dz = -BLEND_RADIUS; dz <= BLEND_RADIUS; dz++) {
for (let dx = -BLEND_RADIUS; dx <= BLEND_RADIUS; dx++) {
// which of the 3x3 chunks, and where in it
const sx = x + dx + CHUNK_SIZE;
const sz = z + dz + CHUNK_SIZE;
const chunk = colors[Math.floor(sz / CHUNK_SIZE) * 3 + Math.floor(sx / CHUNK_SIZE)];
if (!chunk) continue;
const color = chunk[offset + (sz % CHUNK_SIZE) * CHUNK_SIZE + (sx % CHUNK_SIZE)];
r += color >> 16;
g += (color >> 8) & 0xff;
b += color & 0xff;
count++;
}
}
const color = count === 0
? 0xffffff
: (Math.round(r / count) << 16) | (Math.round(g / count) << 8) | Math.round(b / count);
blended[offset + z * CHUNK_SIZE + x] = color;
}
}
}
}
// a quad's MeshQuad.tint from its block's "tint"
function quad_tint(block: BlockRegistry, variables: string[]) {
if (!is_tinted(block, variables)) return 0xffffff;
const color = block.tint!.color;
if (color === "grass") return GRASS;
if (color === "foliage") return FOLIAGE;
return parseInt(color.slice(1), 16);
}
function build_block_tables() {
@@ -319,7 +388,16 @@ class QuadBuffer {
let mesh_min_y = Infinity;
let mesh_max_y = -Infinity;
function push_quad(buffer: QuadBuffer, quad: MeshQuad, x: number, y: number, z: number, alpha: number) {
// tint is 0xRRGGBB, multiplied into the quad's color
function push_quad(
buffer: QuadBuffer,
quad: MeshQuad,
x: number,
y: number,
z: number,
alpha: number,
tint = 0xffffff,
) {
buffer.reserve();
const { f32, u16, bytes } = buffer;
const sprite = quad.sprite;
@@ -336,10 +414,10 @@ function push_quad(buffer: QuadBuffer, quad: MeshQuad, x: number, y: number, z:
f32[byte / 4 + 2] = z + quad.positions[corner * 3 + 2];
u16[byte / 2 + 6] = Math.round(atlas_u(sprite, quad.uvs[corner * 2]) * 65535);
u16[byte / 2 + 7] = Math.round(atlas_v(sprite, quad.uvs[corner * 2 + 1]) * 65535);
const brightness = Math.round(quad.shade * corner_ao[corner] * 255);
bytes[byte + 16] = brightness;
bytes[byte + 17] = brightness;
bytes[byte + 18] = brightness;
const brightness = quad.shade * corner_ao[corner];
bytes[byte + 16] = Math.round(brightness * (tint >> 16));
bytes[byte + 17] = Math.round(brightness * ((tint >> 8) & 0xff));
bytes[byte + 18] = Math.round(brightness * (tint & 0xff));
bytes[byte + 19] = alpha_byte;
// where to read the lightmap, block light across and sky light down
bytes[byte + 20] = Math.round((corner_block[corner] + 0.5) / 16 * 255);
@@ -385,6 +463,7 @@ function block_quads(value: number): MeshQuad[] {
shade: quad.shade ? FACE_SHADE[quad.face] : 1,
sprite: textures_info[quad.texture] ?? textures_info["engine:missing"],
light_weights: light_weights(quad.face, quad.positions),
tint: quad_tint(block, quad.variables),
}));
baked.set(key, quads);
return quads;
@@ -490,10 +569,15 @@ function make_chunk_mesh(chunk_x: number, chunk_z: number, values: Uint32Array,
}
light_quad(quad, index, y, face_offsets);
const tint = quad.tint === GRASS
? blended[z * CHUNK_SIZE + x]
: quad.tint === FOLIAGE
? blended[CHUNK_AREA + z * CHUNK_SIZE + x]
: quad.tint;
if (layer_id !== TRANSLUCENT) {
const group = opaque[layer_id][quad.group];
push_quad(group.buffer, quad, wx, y, wz, alpha);
push_quad(group.buffer, quad, wx, y, wz, alpha, tint);
if (quad.group !== UNALIGNED_GROUP) {
const axis = FACE_AXIS[quad.face];
const plane = (axis === 0 ? wx : axis === 1 ? y : wz) + quad.positions[axis];
@@ -501,7 +585,7 @@ function make_chunk_mesh(chunk_x: number, chunk_z: number, values: Uint32Array,
if (plane > group.max) group.max = plane;
}
} else {
push_quad(translucent_quads, quad, wx, y, wz, alpha);
push_quad(translucent_quads, quad, wx, y, wz, alpha, tint);
// sorting treats every quad as facing along an axis, rotated ones too
const q = translucent_quads.count - 1;
centers = ensure_capacity(centers, (q + 1) * 3);
+33
View File
@@ -2,6 +2,7 @@
// a block picks one with "model" and fills in its texture variables with "textures". baking turns a model
// into quads in block space (0 to 1) that the chunk mesher and the item renderers draw
import type { BlockRegistry, BlockTextures } from "./everything_registry.ts";
import { tint_without_biome } from "./worldgen/biome_colors.ts";
export type ModelFace = "top" | "bottom" | "north" | "south" | "west" | "east";
export const MODEL_FACES: ModelFace[] = ["top", "bottom", "north", "south", "west", "east"];
@@ -126,6 +127,20 @@ export function resolve_texture(reference: string, textures: BlockTextures | und
return reference.startsWith("#") ? "engine:missing" : reference;
}
// the variables a texture reference goes through before it's a texture id, "#front" on a cube is front then side
export function texture_variables(reference: string, textures: BlockTextures | undefined, model?: ModelJson) {
const variables: string[] = [];
for (let depth = 0; depth < 8 && reference.startsWith("#"); depth++) {
const name = reference.slice(1);
variables.push(name);
if (typeof textures === "string") break;
const next = (textures as Record<string, string> | undefined)?.[name] ?? model?.textures?.[name];
if (next === undefined) break;
reference = next;
}
return variables;
}
// the block's model and textures for a value with state bits, from the first variant whose conditions match
export function block_variant(block: BlockRegistry, states?: Record<string, number>): Required<BlockVariant> {
const variant: Required<BlockVariant> = {
@@ -168,6 +183,21 @@ export function cube_face_texture(block: BlockRegistry, face: "top" | "bottom" |
return resolve_texture(`#${face}`, block.textures, BUILTIN_MODELS[DEFAULT_MODEL]);
}
// the color to draw a face of a block's item in, as r g b from 0 to 1. items aren't in a biome, so a biome "tint"
// gets the default grass or foliage color, like minecraft's grass block item
export function cube_face_tint(block: BlockRegistry, face: "top" | "bottom" | "front" | "side"): number[] {
const variables = texture_variables(`#${face}`, block.textures, BUILTIN_MODELS[DEFAULT_MODEL]);
if (!is_tinted(block, variables)) return [1, 1, 1];
const color = tint_without_biome(block.tint!.color);
return [color >> 16, (color >> 8) & 0xff, color & 0xff].map((c) => c / 255);
}
// whether a face that got its texture through these variables is drawn in the block's tint
export function is_tinted(block: BlockRegistry, variables: string[]) {
if (!block.tint) return false;
return !block.tint.textures || block.tint.textures.some((name) => variables.includes(name));
}
// baking
export interface BakedQuad {
@@ -176,6 +206,8 @@ export interface BakedQuad {
// u v per corner, in pixels of the texture (0-16)
uvs: number[];
texture: string;
// the texture variables it went through to get there, like ["front", "side"], for "tint"
variables: string[];
// the side it faces most, as the mesher's face index (see FACE_INDEX)
face: number;
// the side whose neighbor can hide it, or -1
@@ -257,6 +289,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
positions,
uvs,
texture: resolve_texture(face_json.texture, textures, model),
variables: texture_variables(face_json.texture, textures, model),
face: facing,
cull,
flush,
+4
View File
@@ -1,3 +1,4 @@
import type { TintColor } from "./worldgen/biome_colors.ts";
import type { ItemStack } from "./inventory.ts";
import type { BlockVariant } from "./block_models.ts";
@@ -108,6 +109,9 @@ export interface BlockRegistry {
render_layer?: RenderLayer;
// hide faces between two of this block, like glass and water. defaults to true for translucent blocks
cull_same?: boolean;
// drawn in a color: the biome's grass or foliage color, like minecraft's grass block and leaves, or a fixed one
// like "#80a755". only the texture variables listed (like "top"), or all of them
tint?: { color: TintColor; textures?: string[] };
// light level 0-15 it gives off
light_emission?: number;
// how much light going through it loses, 0-15. see block_light_opacity for the default
+11 -3
View File
@@ -5,6 +5,7 @@ import { AIR, CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, ID_MASK } from "$/common/con
import type { FeatureChunk } from "$/common/mod_api/worldgen.ts";
import type { OreJson } from "$/common/mod_data.ts";
import { generate_overworld } from "./worldgen/overworld.ts";
import { type Wood, WOODS } from "./worldgen/trees.ts";
import { named_noise_2d, named_noise_3d } from "./worldgen/noise.ts";
export { named_noise_2d, named_noise_3d };
@@ -29,6 +30,8 @@ export interface RawChunk {
blocks: Uint32Array;
// blocks it generated in other chunks (from features like a mod's trees), flattened as x, y, z, numeric id
spills: Int32Array;
// each column's biome id, x then z
biomes: string[];
}
// features that threw, so each is only reported once
@@ -70,6 +73,11 @@ export function generate_raw_chunk(
const nid = block_ids[name];
return nid === undefined ? AIR : default_values?.[nid] ?? nid;
};
// oak's are the plain bworld:log and bworld:leaves, the others are named after their wood
const wood_ids = (part: "log" | "leaves") =>
Object.fromEntries(
WOODS.map((wood) => [wood, id(wood === "oak" ? `bworld:${part}` : `bworld:${wood}_${part}`)]),
) as Record<Wood, number>;
generate_overworld(blocks, heights, biomes, chunk_x, chunk_z, seed, {
stone: id("bworld:stone"),
dirt: id("bworld:dirt"),
@@ -77,8 +85,8 @@ export function generate_raw_chunk(
sand: id("bworld:sand"),
snow: id("bworld:snow"),
water: id("bworld:water"),
log: id("bworld:log"),
leaves: id("bworld:leaves"),
logs: wood_ids("log"),
leaves: wood_ids("leaves"),
}, (x, y, z, block) => spills.push(x, y, z, block));
generate_ores(blocks, chunk_x, chunk_z, seed, block_ids, BASE_ORES, default_values);
@@ -87,7 +95,7 @@ export function generate_raw_chunk(
generate_features(blocks, heights, biomes, set, chunk_x, chunk_z, seed, block_ids, worldgen.features);
}
return { blocks, spills: new Int32Array(spills) };
return { blocks, spills: new Int32Array(spills), biomes };
}
// each block an ore replaces becomes the first ore whose noise is above its threshold
+4 -4
View File
@@ -1,6 +1,6 @@
// checks between mods: dependencies, load order, and ids one mod uses from another. pure, so the build, check-mods
// and the server (on .bmod files) all use it
import type { BlockJson, ItemJson, OreJson, RecipeJson } from "./mod_data.ts";
import { type BlockJson, choice_ids, type ItemJson, type OreJson, type RecipeJson } from "./mod_data.ts";
import { BUILTIN_MODELS, type ModelJson } from "./block_models.ts";
export interface ModReport {
@@ -135,15 +135,15 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
for (const { file, json } of mod.recipes) {
switch (json.type) {
case "shaped":
for (const id of Object.values(json.key)) uses(file, id, "item");
for (const id of Object.values(json.key).flatMap(choice_ids)) uses(file, id, "item");
uses(file, json.result.id, "item");
break;
case "furnace":
uses(file, json.input, "item");
for (const id of choice_ids(json.input)) uses(file, id, "item");
uses(file, json.output.id, "item");
break;
case "fuel":
uses(file, json.item, "item");
for (const id of choice_ids(json.item)) uses(file, id, "item");
break;
case "smithing":
uses(file, json.tool, "item");
+47 -17
View File
@@ -1,5 +1,6 @@
// the json formats from MODS.md, and converting them to and from the engine's registry entries.
// the mod loader uses the from_json direction, tests use both to check nothing is lost
import { is_tint_color, type TintColor } from "./worldgen/biome_colors.ts";
import {
type BlockRegistry,
type BlockStateDefinition,
@@ -38,6 +39,7 @@ export interface BlockJson {
variants?: Record<string, BlockVariant>;
render_layer?: RenderLayer;
cull_same?: boolean;
tint?: { color: TintColor; textures?: string[] };
light_emission?: number;
light_opacity?: number;
// replaced by render_layer, true means translucent
@@ -76,15 +78,22 @@ export interface ItemJson {
components?: Record<string, unknown>;
}
// an item a recipe takes: its id, or a list of ids any of which fits, like every kind of planks
export type ItemChoice = string | string[];
export function choice_ids(choice: ItemChoice): string[] {
return typeof choice === "string" ? [choice] : choice;
}
export type RecipeJson =
| {
type: "shaped";
pattern: string[];
key: Record<string, string>;
key: Record<string, ItemChoice>;
result: { id: string; count: number };
}
| { type: "furnace"; input: string; output: { id: string; count: number }; cook_time: number }
| { type: "fuel"; item: string; burn_time: number }
| { type: "furnace"; input: ItemChoice; output: { id: string; count: number }; cook_time: number }
| { type: "fuel"; item: ItemChoice; burn_time: number }
// upgrades a tool at a smithing table, with some of a material and maybe one more item
| {
type: "smithing";
@@ -111,7 +120,7 @@ export function is_mod_recipe(recipe: RecipeJson): recipe is ModRecipeJson {
export interface GridRecipe {
width: number;
height: number;
pattern: (string | undefined)[];
pattern: (ItemChoice | undefined)[];
result: { id: string; count: number };
}
@@ -124,6 +133,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (block.variants !== undefined) json.variants = block.variants;
if (block.render_layer && block.render_layer !== "solid") json.render_layer = block.render_layer;
if (block.cull_same !== undefined) json.cull_same = block.cull_same;
if (block.tint !== undefined) json.tint = block.tint;
if (block.light_emission !== undefined) json.light_emission = block.light_emission;
if (block.light_opacity !== undefined) json.light_opacity = block.light_opacity;
if (block.alpha !== undefined) json.alpha = block.alpha;
@@ -156,6 +166,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
const render_layer = json.render_layer ?? (json.transparent ? "translucent" : undefined);
if (render_layer && render_layer !== "solid") block.render_layer = render_layer;
if (json.cull_same !== undefined) block.cull_same = json.cull_same;
if (json.tint !== undefined) block.tint = json.tint;
if (json.light_emission !== undefined) block.light_emission = json.light_emission;
if (json.light_opacity !== undefined) block.light_opacity = json.light_opacity;
if (json.alpha !== undefined) block.alpha = json.alpha;
@@ -206,21 +217,22 @@ export function item_from_json(json: ItemJson): ItemRegistry {
// shaped recipes <-> the grid format
export function grid_recipe_to_json(recipe: GridRecipe): RecipeJson {
const key: Record<string, string> = {};
const key: Record<string, ItemChoice> = {};
// by the choice as json, so equal lists share a letter
const letters = new Map<string, string>();
for (const id of recipe.pattern) {
if (id === undefined || letters.has(id)) continue;
const letter = pick_letter(id, new Set(letters.values()));
letters.set(id, letter);
key[letter] = id;
for (const choice of recipe.pattern) {
if (choice === undefined || letters.has(JSON.stringify(choice))) continue;
const letter = pick_letter(choice_ids(choice)[0], new Set(letters.values()));
letters.set(JSON.stringify(choice), letter);
key[letter] = choice;
}
const pattern: string[] = [];
for (let y = 0; y < recipe.height; y++) {
let row = "";
for (let x = 0; x < recipe.width; x++) {
const id = recipe.pattern[y * recipe.width + x];
row += id === undefined ? " " : letters.get(id);
const choice = recipe.pattern[y * recipe.width + x];
row += choice === undefined ? " " : letters.get(JSON.stringify(choice));
}
pattern.push(row);
}
@@ -231,7 +243,7 @@ export function grid_recipe_to_json(recipe: GridRecipe): RecipeJson {
export function grid_recipe_from_json(json: Extract<RecipeJson, { type: "shaped" }>): GridRecipe {
const height = json.pattern.length;
const width = Math.max(...json.pattern.map((row) => row.length));
const pattern: (string | undefined)[] = [];
const pattern: (ItemChoice | undefined)[] = [];
for (const row of json.pattern) {
for (let x = 0; x < width; x++) {
const letter = row[x] ?? " ";
@@ -351,6 +363,17 @@ export function validate_block(json: unknown): Problems {
for (const key of ["cull_same", "transparent", "collision", "item", "interactive", "replaceable"]) {
if (json[key] !== undefined && typeof json[key] !== "boolean") problems.push(`${key} must be true or false`);
}
if (json.tint !== undefined) {
const tint = json.tint;
if (!is_object(tint) || !is_tint_color(tint.color)) {
problems.push('tint.color must be "grass", "foliage" or a color like "#80a755"');
} else if (
tint.textures !== undefined &&
!(Array.isArray(tint.textures) && tint.textures.every((name) => typeof name === "string"))
) {
problems.push('tint.textures must be a list of texture variables, like ["top"]');
}
}
if (json.alpha !== undefined && (typeof json.alpha !== "number" || json.alpha < 0 || json.alpha > 1)) {
problems.push("alpha must be between 0 and 1");
}
@@ -493,21 +516,21 @@ export function validate_recipe(json: unknown): Problems {
}
}
if (!is_object(json.key)) {
problems.push("key must map letters to item ids");
problems.push("key must map letters to item ids, or lists of them");
} else {
for (const id of Object.values(json.key)) problems.push(...validate_id(id, "key"));
for (const choice of Object.values(json.key)) problems.push(...validate_choice(choice, "key"));
}
problems.push(...validate_stack(json.result, "result"));
break;
}
case "furnace":
problems.push(...validate_id(json.input, "input"), ...validate_stack(json.output, "output"));
problems.push(...validate_choice(json.input, "input"), ...validate_stack(json.output, "output"));
if (!Number.isInteger(json.cook_time) || (json.cook_time as number) < 1) {
problems.push("cook_time must be a positive number of ticks");
}
break;
case "fuel":
problems.push(...validate_id(json.item, "item"));
problems.push(...validate_choice(json.item, "item"));
if (!Number.isInteger(json.burn_time) || (json.burn_time as number) < 1) {
problems.push("burn_time must be a positive number of ticks");
}
@@ -544,6 +567,13 @@ export function validate_ore(json: unknown): Problems {
return problems;
}
// an item id, or a list of them any of which fits
function validate_choice(value: unknown, field: string): Problems {
if (!Array.isArray(value)) return validate_id(value, field);
if (value.length === 0) return [`${field} must list at least one item`];
return value.flatMap((id) => validate_id(id, field));
}
// optional text players see
function validate_text(value: unknown, field: string): Problems {
return value === undefined || (typeof value === "string" && value.length > 0) ? [] : [`${field} must be text`];
+6 -3
View File
@@ -3,6 +3,7 @@ import { BlockRegistry, EverythingRegistry, ItemRegistry } from "./everything_re
import {
block_from_json,
BlockJson,
choice_ids,
grid_recipe_from_json,
GridRecipe,
is_mod_recipe,
@@ -95,11 +96,13 @@ export function register_mod_data(mods: { id: string; data: ModData }[]): Recipe
recipes.shaped.push(grid_recipe_from_json(recipe));
break;
case "furnace":
if (recipes.furnace.has(recipe.input)) fail(`two furnace recipes for ${recipe.input}`);
recipes.furnace.set(recipe.input, { output: recipe.output, cook_time: recipe.cook_time });
for (const input of choice_ids(recipe.input)) {
if (recipes.furnace.has(input)) fail(`two furnace recipes for ${input}`);
recipes.furnace.set(input, { output: recipe.output, cook_time: recipe.cook_time });
}
break;
case "fuel":
recipes.fuel.set(recipe.item, recipe.burn_time);
for (const item of choice_ids(recipe.item)) recipes.fuel.set(item, recipe.burn_time);
break;
case "smithing":
if (
+99
View File
@@ -0,0 +1,99 @@
// what color each biome tints grass and leaves, as 0xRRGGBB. minecraft's grass and foliage colors, with the terralith
// style biomes given the ones of the vanilla biome closest to them. blocks pick them with "tint"
export const BIOME_GRASS_COLORS: Record<string, number> = {
"bworld:deep_ocean": 0x8eb971,
"bworld:deep_frozen_ocean": 0x80b497,
"bworld:deep_lukewarm_ocean": 0x8eb971,
"bworld:ocean": 0x8eb971,
"bworld:frozen_ocean": 0x80b497,
"bworld:warm_ocean": 0x8eb971,
"bworld:river": 0x8eb971,
"bworld:frozen_river": 0x80b497,
"bworld:beach": 0x91bd59,
"bworld:snowy_beach": 0x83b593,
"bworld:stony_shore": 0x8ab689,
"bworld:plains": 0x91bd59,
"bworld:meadow": 0x83bb6d,
"bworld:forest": 0x79c05a,
"bworld:dark_forest": 0x507a32,
"bworld:swamp": 0x6a7039,
"bworld:taiga": 0x86b783,
"bworld:snowy_plains": 0x80b497,
"bworld:snowy_taiga": 0x80b497,
"bworld:savanna": 0xbfb755,
"bworld:jungle": 0x59c93c,
"bworld:desert": 0xbfb755,
"bworld:alpine_highlands": 0x8ab689,
"bworld:snowy_slopes": 0x80b497,
"bworld:stony_peaks": 0x9abe4b,
"bworld:jagged_peaks": 0x80b497,
"bworld:frozen_peaks": 0x80b497,
"bworld:yosemite_cliffs": 0x86b783,
"bworld:snowy_cliffs": 0x80b497,
"bworld:painted_mountains": 0x90814d,
"bworld:stony_spires": 0x8ab689,
"bworld:shattered_savanna": 0xbfb755,
"bworld:skylands": 0x79c05a,
};
export const BIOME_FOLIAGE_COLORS: Record<string, number> = {
"bworld:deep_ocean": 0x71a74d,
"bworld:deep_frozen_ocean": 0x60a17b,
"bworld:deep_lukewarm_ocean": 0x71a74d,
"bworld:ocean": 0x71a74d,
"bworld:frozen_ocean": 0x60a17b,
"bworld:warm_ocean": 0x71a74d,
"bworld:river": 0x71a74d,
"bworld:frozen_river": 0x60a17b,
"bworld:beach": 0x77ab2f,
"bworld:snowy_beach": 0x64a278,
"bworld:stony_shore": 0x6da36b,
"bworld:plains": 0x77ab2f,
"bworld:meadow": 0x63a948,
"bworld:forest": 0x59ae30,
"bworld:dark_forest": 0x59ae30,
"bworld:swamp": 0x6a7039,
"bworld:taiga": 0x68a464,
"bworld:snowy_plains": 0x60a17b,
"bworld:snowy_taiga": 0x60a17b,
"bworld:savanna": 0xaea42a,
"bworld:jungle": 0x30bb0b,
"bworld:desert": 0xaea42a,
"bworld:alpine_highlands": 0x6da36b,
"bworld:snowy_slopes": 0x60a17b,
"bworld:stony_peaks": 0x82ac1e,
"bworld:jagged_peaks": 0x60a17b,
"bworld:frozen_peaks": 0x60a17b,
"bworld:yosemite_cliffs": 0x68a464,
"bworld:snowy_cliffs": 0x60a17b,
"bworld:painted_mountains": 0x9e814d,
"bworld:stony_spires": 0x6da36b,
"bworld:shattered_savanna": 0xaea42a,
"bworld:skylands": 0x59ae30,
};
// biomes mods add without a color, and items, which aren't in any biome
export const DEFAULT_GRASS_COLOR = BIOME_GRASS_COLORS["bworld:plains"];
export const DEFAULT_FOLIAGE_COLOR = BIOME_FOLIAGE_COLORS["bworld:plains"];
export function grass_color(biome: string | undefined) {
return (biome !== undefined ? BIOME_GRASS_COLORS[biome] : undefined) ?? DEFAULT_GRASS_COLOR;
}
export function foliage_color(biome: string | undefined) {
return (biome !== undefined ? BIOME_FOLIAGE_COLORS[biome] : undefined) ?? DEFAULT_FOLIAGE_COLOR;
}
// a block's "tint" color: the biome's grass or foliage color, or a fixed one like "#80a755"
export type TintColor = "grass" | "foliage" | `#${string}`;
export function is_tint_color(value: unknown): value is TintColor {
return value === "grass" || value === "foliage" || (typeof value === "string" && /^#[0-9a-fA-F]{6}$/.test(value));
}
// the color outside any biome, for items: the default grass or foliage color, or the fixed one
export function tint_without_biome(color: TintColor) {
if (color === "grass") return DEFAULT_GRASS_COLOR;
if (color === "foliage") return DEFAULT_FOLIAGE_COLOR;
return parseInt(color.slice(1), 16);
}
+12 -8
View File
@@ -3,7 +3,7 @@
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, SEA_LEVEL } from "$/common/constants.ts";
import { OctaveNoise2D } from "./noise.ts";
import { OverworldTerrain, TerrainColumn } from "./terrain.ts";
import { BIOME_TREES, grow_tree, tree_sites } from "./trees.ts";
import { BIOME_TREES, grow_tree, tree_sites, tree_wood, type Wood } from "./trees.ts";
// density is sampled every CELL_WIDTH blocks across and CELL_HEIGHT up, caves every CAVE_CELL_HEIGHT up since
// tunnels are thinner than terrain features
@@ -29,8 +29,8 @@ export interface OverworldBlocks {
sand: number;
snow: number;
water: number;
log: number;
leaves: number;
logs: Record<Wood, number>;
leaves: Record<Wood, number>;
}
type Palette = "stone" | "dirt" | "grass" | "sand" | "snow";
@@ -244,19 +244,22 @@ export function generate_overworld(
grow_trees();
function grow_trees() {
const place = (x: number, y: number, z: number, block: "log" | "leaves") => {
// logs replace any tree's leaves
const all_leaves = new Set(Object.values(ids.leaves));
const place = (x: number, y: number, z: number, block: "log" | "leaves", wood: Wood) => {
if (y < 0 || y >= CHUNK_HEIGHT) return;
const id = block === "log" ? ids.logs[wood] : ids.leaves[wood];
const lx = x - x0;
const lz = z - z0;
if (lx < 0 || lx >= CHUNK_SIZE || lz < 0 || lz >= CHUNK_SIZE) {
// the other chunk only takes it where it has air
spill(x, y, z, ids[block]);
spill(x, y, z, id);
return;
}
const i = y * CHUNK_AREA + lz * CHUNK_SIZE + lx;
const current = blocks[i];
if (current === 0 || (block === "log" && current === ids.leaves)) {
blocks[i] = ids[block];
if (current === 0 || (block === "log" && all_leaves.has(current))) {
blocks[i] = id;
}
};
@@ -272,7 +275,8 @@ export function generate_overworld(
if ((ground !== ids.grass && ground !== ids.dirt && ground !== ids.snow) || above !== 0) continue;
const kind = trees.kinds[Math.floor(site.rng.next() * trees.kinds.length)];
grow_tree(kind, site.x, ground_y + 1, site.z, site.rng, place);
const wood = tree_wood(kind, biomes[column]);
grow_tree(kind, site.x, ground_y + 1, site.z, site.rng, (x, y, z, block) => place(x, y, z, block, wood));
}
}
+45 -3
View File
@@ -15,14 +15,32 @@ const REACH = Math.ceil(MIN_DISTANCE / CELL);
// the widest a canopy layer gets
const MAX_CANOPY = 3;
export type TreeKind = "oak" | "big_oak" | "spruce" | "jungle" | "acacia";
export type TreeKind = "oak" | "big_oak" | "birch" | "spruce" | "jungle" | "acacia" | "cherry";
export const WOODS = ["oak", "spruce", "birch", "jungle", "acacia", "dark_oak", "cherry"] as const;
export type Wood = typeof WOODS[number];
// the logs and leaves a tree grows, big oaks are dark oak in the dark forest like minecraft's
export function tree_wood(kind: TreeKind, biome: string): Wood {
switch (kind) {
case "big_oak":
return biome === "bworld:dark_forest" ? "dark_oak" : "oak";
case "birch":
case "spruce":
case "jungle":
case "acacia":
case "cherry":
return kind;
default:
return "oak";
}
}
// how likely each biome's cells are to have a tree, and which kinds grow there
export const BIOME_TREES: Record<string, { chance: number; kinds: TreeKind[] }> = {
"bworld:forest": { chance: 0.85, kinds: ["oak", "oak", "big_oak"] },
"bworld:forest": { chance: 0.85, kinds: ["oak", "oak", "big_oak", "birch"] },
"bworld:dark_forest": { chance: 1, kinds: ["big_oak", "big_oak", "oak"] },
"bworld:plains": { chance: 0.05, kinds: ["oak"] },
"bworld:meadow": { chance: 0.04, kinds: ["oak"] },
"bworld:meadow": { chance: 0.06, kinds: ["oak", "birch", "cherry", "cherry"] },
"bworld:swamp": { chance: 0.4, kinds: ["big_oak"] },
"bworld:river": { chance: 0.05, kinds: ["oak"] },
"bworld:taiga": { chance: 0.75, kinds: ["spruce"] },
@@ -126,6 +144,30 @@ export function grow_tree(kind: TreeKind, x: number, y: number, z: number, rng:
layer(y + height + 1, 1, false);
break;
}
case "birch": {
// oak's canopy on a taller, straight trunk
const height = random(5, 7);
top = y + height + 1;
if (top >= CHUNK_HEIGHT - 1) return false;
trunk(height);
layer(y + height - 2, 2, true);
layer(y + height - 1, 2, true);
layer(y + height, 1, true);
layer(y + height + 1, 1, false);
break;
}
case "cherry": {
// a short trunk under a wide, rounded canopy
const height = random(4, 6);
top = y + height + 1;
if (top >= CHUNK_HEIGHT - 1) return false;
trunk(height);
layer(y + height - 2, 2, false);
layer(y + height - 1, MAX_CANOPY, false);
layer(y + height, MAX_CANOPY, false);
layer(y + height + 1, 2, false);
break;
}
case "big_oak": {
const height = random(6, 8);
top = y + height + 1;
+13
View File
@@ -0,0 +1,13 @@
{
"format_version": 1,
"block": {
"id": "bworld:acacia_leaves",
"textures": "bworld:acacia_leaves",
"render_layer": "cutout",
"light_opacity": 1,
"mining": {
"toughness": 3,
"tool": "hoe"
}
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"format_version": 1,
"block": {
"id": "bworld:acacia_log",
"textures": {
"side": "bworld:acacia_log",
"top": "bworld:acacia_log_top",
"bottom": "bworld:acacia_log_top"
},
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:acacia_log"
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"format_version": 1,
"block": {
"id": "bworld:acacia_planks",
"textures": "bworld:acacia_planks",
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:acacia_planks"
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"format_version": 1,
"block": {
"id": "bworld:birch_leaves",
"textures": "bworld:birch_leaves",
"tint": {
"color": "#80a755"
},
"render_layer": "cutout",
"light_opacity": 1,
"mining": {
"toughness": 3,
"tool": "hoe"
}
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"format_version": 1,
"block": {
"id": "bworld:birch_log",
"textures": {
"side": "bworld:birch_log",
"top": "bworld:birch_log_top",
"bottom": "bworld:birch_log_top"
},
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:birch_log"
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"format_version": 1,
"block": {
"id": "bworld:birch_planks",
"textures": "bworld:birch_planks",
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:birch_planks"
}
}
+13
View File
@@ -0,0 +1,13 @@
{
"format_version": 1,
"block": {
"id": "bworld:cherry_leaves",
"textures": "bworld:cherry_leaves",
"render_layer": "cutout",
"light_opacity": 1,
"mining": {
"toughness": 3,
"tool": "hoe"
}
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"format_version": 1,
"block": {
"id": "bworld:cherry_log",
"textures": {
"side": "bworld:cherry_log",
"top": "bworld:cherry_log_top",
"bottom": "bworld:cherry_log_top"
},
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:cherry_log"
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"format_version": 1,
"block": {
"id": "bworld:cherry_planks",
"textures": "bworld:cherry_planks",
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:cherry_planks"
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
"format_version": 1,
"block": {
"id": "bworld:chest",
"textures": "bworld:planks",
"textures": "bworld:oak_planks",
"mining": {
"toughness": 8,
"tool": "axe"
+13
View File
@@ -0,0 +1,13 @@
{
"format_version": 1,
"block": {
"id": "bworld:dark_oak_leaves",
"textures": "bworld:dark_oak_leaves",
"render_layer": "cutout",
"light_opacity": 1,
"mining": {
"toughness": 3,
"tool": "hoe"
}
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"format_version": 1,
"block": {
"id": "bworld:dark_oak_log",
"textures": {
"side": "bworld:dark_oak_log",
"top": "bworld:dark_oak_log_top",
"bottom": "bworld:dark_oak_log_top"
},
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:dark_oak_log"
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"format_version": 1,
"block": {
"id": "bworld:dark_oak_planks",
"textures": "bworld:dark_oak_planks",
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:dark_oak_planks"
}
}
+1 -1
View File
@@ -10,7 +10,7 @@
"drops": "bworld:dirt",
"components": {
"bworld:hoeable": {
"tool": "bworld:hoe",
"tool": "hoe",
"into": "bworld:hoed_dirt"
}
}
+4 -3
View File
@@ -3,10 +3,11 @@
"block": {
"id": "bworld:grass",
"textures": {
"top": "bworld:grass_top",
"top": "bworld:grass_block_top",
"bottom": "bworld:dirt",
"side": "bworld:grass_side"
"side": "bworld:grass_block_side"
},
"tint": { "color": "grass", "textures": ["top"] },
"mining": {
"toughness": 2,
"tool": "shovel"
@@ -15,7 +16,7 @@
"item": false,
"components": {
"bworld:hoeable": {
"tool": "bworld:hoe",
"tool": "hoe",
"into": "bworld:hoed_dirt"
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"format_version": 1,
"block": {
"id": "bworld:jungle_leaves",
"textures": "bworld:jungle_leaves",
"tint": {
"color": "foliage"
},
"render_layer": "cutout",
"light_opacity": 1,
"mining": {
"toughness": 3,
"tool": "hoe"
}
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"format_version": 1,
"block": {
"id": "bworld:jungle_log",
"textures": {
"side": "bworld:jungle_log",
"top": "bworld:jungle_log_top",
"bottom": "bworld:jungle_log_top"
},
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:jungle_log"
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"format_version": 1,
"block": {
"id": "bworld:jungle_planks",
"textures": "bworld:jungle_planks",
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:jungle_planks"
}
}
+5 -1
View File
@@ -2,7 +2,11 @@
"format_version": 1,
"block": {
"id": "bworld:leaves",
"textures": "bworld:leaves",
"name": "Oak Leaves",
"textures": "bworld:oak_leaves",
"tint": {
"color": "foliage"
},
"render_layer": "cutout",
"light_opacity": 1,
"mining": {
+4 -3
View File
@@ -2,10 +2,11 @@
"format_version": 1,
"block": {
"id": "bworld:log",
"name": "Oak Log",
"textures": {
"side": "bworld:log_side",
"top": "bworld:log_top",
"bottom": "bworld:log_top"
"side": "bworld:oak_log",
"top": "bworld:oak_log_top",
"bottom": "bworld:oak_log_top"
},
"mining": {
"toughness": 3,
+2 -1
View File
@@ -2,7 +2,8 @@
"format_version": 1,
"block": {
"id": "bworld:planks",
"textures": "bworld:planks",
"name": "Oak Planks",
"textures": "bworld:oak_planks",
"mining": {
"toughness": 3,
"tool": "axe"
+13
View File
@@ -0,0 +1,13 @@
{
"format_version": 1,
"block": {
"id": "bworld:spruce_leaves",
"textures": "bworld:spruce_leaves",
"render_layer": "cutout",
"light_opacity": 1,
"mining": {
"toughness": 3,
"tool": "hoe"
}
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"format_version": 1,
"block": {
"id": "bworld:spruce_log",
"textures": {
"side": "bworld:spruce_log",
"top": "bworld:spruce_log_top",
"bottom": "bworld:spruce_log_top"
},
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:spruce_log"
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"format_version": 1,
"block": {
"id": "bworld:spruce_planks",
"textures": "bworld:spruce_planks",
"mining": {
"toughness": 3,
"tool": "axe"
},
"drops": "bworld:spruce_planks"
}
}
-8
View File
@@ -1,8 +0,0 @@
{
"format_version": 1,
"item": {
"id": "bworld:axe",
"texture": "bworld:axe",
"tool": "axe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:copper_axe",
"texture": "bworld:copper_axe",
"tool": "axe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:copper_hoe",
"texture": "bworld:copper_hoe",
"tool": "hoe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:copper_pickaxe",
"texture": "bworld:copper_pickaxe",
"tool": "pickaxe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:copper_shovel",
"texture": "bworld:copper_shovel",
"tool": "shovel"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:golden_axe",
"texture": "bworld:golden_axe",
"tool": "axe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:golden_hoe",
"texture": "bworld:golden_hoe",
"tool": "hoe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:golden_pickaxe",
"texture": "bworld:golden_pickaxe",
"tool": "pickaxe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:golden_shovel",
"texture": "bworld:golden_shovel",
"tool": "shovel"
}
}
-7
View File
@@ -1,7 +0,0 @@
{
"format_version": 1,
"item": {
"id": "bworld:hoe",
"texture": "bworld:hoe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:iron_axe",
"texture": "bworld:iron_axe",
"tool": "axe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:iron_hoe",
"texture": "bworld:iron_hoe",
"tool": "hoe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:iron_pickaxe",
"texture": "bworld:iron_pickaxe",
"tool": "pickaxe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:iron_shovel",
"texture": "bworld:iron_shovel",
"tool": "shovel"
}
}
-7
View File
@@ -1,7 +0,0 @@
{
"format_version": 1,
"item": {
"id": "bworld:pickaxe",
"texture": "bworld:pickaxe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:stone_axe",
"texture": "bworld:stone_axe",
"tool": "axe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:stone_hoe",
"texture": "bworld:stone_hoe",
"tool": "hoe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:stone_shovel",
"texture": "bworld:stone_shovel",
"tool": "shovel"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:wood_axe",
"texture": "bworld:wood_axe",
"tool": "axe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:wood_hoe",
"texture": "bworld:wood_hoe",
"tool": "hoe"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"format_version": 1,
"item": {
"id": "bworld:wood_shovel",
"texture": "bworld:wood_shovel",
"tool": "shovel"
}
}
@@ -0,0 +1,16 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"L"
],
"key": {
"L": "bworld:acacia_log"
},
"result": {
"id": "bworld:acacia_planks",
"count": 2
}
}
}
@@ -0,0 +1,16 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"L"
],
"key": {
"L": "bworld:birch_log"
},
"result": {
"id": "bworld:birch_planks",
"count": 2
}
}
}
+9 -1
View File
@@ -7,7 +7,15 @@
" P "
],
"key": {
"P": "bworld:planks"
"P": [
"bworld:planks",
"bworld:spruce_planks",
"bworld:birch_planks",
"bworld:jungle_planks",
"bworld:acacia_planks",
"bworld:dark_oak_planks",
"bworld:cherry_planks"
]
},
"result": {
"id": "bworld:bowl",
@@ -0,0 +1,16 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"L"
],
"key": {
"L": "bworld:cherry_log"
},
"result": {
"id": "bworld:cherry_planks",
"count": 2
}
}
}
+9 -1
View File
@@ -8,7 +8,15 @@
"PPP"
],
"key": {
"P": "bworld:planks"
"P": [
"bworld:planks",
"bworld:spruce_planks",
"bworld:birch_planks",
"bworld:jungle_planks",
"bworld:acacia_planks",
"bworld:dark_oak_planks",
"bworld:cherry_planks"
]
},
"result": {
"id": "bworld:chest",
@@ -0,0 +1,16 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"L"
],
"key": {
"L": "bworld:dark_oak_log"
},
"result": {
"id": "bworld:dark_oak_planks",
"count": 2
}
}
}
@@ -0,0 +1,16 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"L"
],
"key": {
"L": "bworld:jungle_log"
},
"result": {
"id": "bworld:jungle_planks",
"count": 2
}
}
}
@@ -0,0 +1,16 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"L"
],
"key": {
"L": "bworld:spruce_log"
},
"result": {
"id": "bworld:spruce_planks",
"count": 2
}
}
}
+9 -1
View File
@@ -7,7 +7,15 @@
"P"
],
"key": {
"P": "bworld:planks"
"P": [
"bworld:planks",
"bworld:spruce_planks",
"bworld:birch_planks",
"bworld:jungle_planks",
"bworld:acacia_planks",
"bworld:dark_oak_planks",
"bworld:cherry_planks"
]
},
"result": {
"id": "bworld:stick",
@@ -0,0 +1,27 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"PP",
"PS",
" S"
],
"key": {
"P": [
"bworld:planks",
"bworld:spruce_planks",
"bworld:birch_planks",
"bworld:jungle_planks",
"bworld:acacia_planks",
"bworld:dark_oak_planks",
"bworld:cherry_planks"
],
"S": "bworld:stick"
},
"result": {
"id": "bworld:wood_axe",
"count": 1
}
}
}
@@ -0,0 +1,27 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"PP",
" S",
" S"
],
"key": {
"P": [
"bworld:planks",
"bworld:spruce_planks",
"bworld:birch_planks",
"bworld:jungle_planks",
"bworld:acacia_planks",
"bworld:dark_oak_planks",
"bworld:cherry_planks"
],
"S": "bworld:stick"
},
"result": {
"id": "bworld:wood_hoe",
"count": 1
}
}
}
@@ -8,7 +8,15 @@
" S "
],
"key": {
"P": "bworld:planks",
"P": [
"bworld:planks",
"bworld:spruce_planks",
"bworld:birch_planks",
"bworld:jungle_planks",
"bworld:acacia_planks",
"bworld:dark_oak_planks",
"bworld:cherry_planks"
],
"S": "bworld:stick"
},
"result": {
@@ -0,0 +1,27 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"P",
"S",
"S"
],
"key": {
"P": [
"bworld:planks",
"bworld:spruce_planks",
"bworld:birch_planks",
"bworld:jungle_planks",
"bworld:acacia_planks",
"bworld:dark_oak_planks",
"bworld:cherry_planks"
],
"S": "bworld:stick"
},
"result": {
"id": "bworld:wood_shovel",
"count": 1
}
}
}
+9 -1
View File
@@ -2,7 +2,15 @@
"format_version": 1,
"recipe": {
"type": "fuel",
"item": "bworld:log",
"item": [
"bworld:log",
"bworld:spruce_log",
"bworld:birch_log",
"bworld:jungle_log",
"bworld:acacia_log",
"bworld:dark_oak_log",
"bworld:cherry_log"
],
"burn_time": 100
}
}
+9 -1
View File
@@ -2,7 +2,15 @@
"format_version": 1,
"recipe": {
"type": "furnace",
"input": "bworld:log",
"input": [
"bworld:log",
"bworld:spruce_log",
"bworld:birch_log",
"bworld:jungle_log",
"bworld:acacia_log",
"bworld:dark_oak_log",
"bworld:cherry_log"
],
"output": {
"id": "bworld:coal",
"count": 1
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_axe",
"material": {
"id": "bworld:copper_ingot",
"count": 3
},
"result": "bworld:copper_axe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_hoe",
"material": {
"id": "bworld:copper_ingot",
"count": 2
},
"result": "bworld:copper_hoe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_pickaxe",
"material": {
"id": "bworld:copper_ingot",
"count": 3
},
"result": "bworld:copper_pickaxe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_shovel",
"material": {
"id": "bworld:copper_ingot",
"count": 1
},
"result": "bworld:copper_shovel"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_axe",
"material": {
"id": "bworld:gold_ingot",
"count": 3
},
"result": "bworld:golden_axe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_hoe",
"material": {
"id": "bworld:gold_ingot",
"count": 2
},
"result": "bworld:golden_hoe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_pickaxe",
"material": {
"id": "bworld:gold_ingot",
"count": 3
},
"result": "bworld:golden_pickaxe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_shovel",
"material": {
"id": "bworld:gold_ingot",
"count": 1
},
"result": "bworld:golden_shovel"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_axe",
"material": {
"id": "bworld:iron_ingot",
"count": 3
},
"result": "bworld:iron_axe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_hoe",
"material": {
"id": "bworld:iron_ingot",
"count": 2
},
"result": "bworld:iron_hoe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_pickaxe",
"material": {
"id": "bworld:iron_ingot",
"count": 3
},
"result": "bworld:iron_pickaxe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_shovel",
"material": {
"id": "bworld:iron_ingot",
"count": 1
},
"result": "bworld:iron_shovel"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:wood_axe",
"material": {
"id": "bworld:stone",
"count": 3
},
"result": "bworld:stone_axe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:wood_hoe",
"material": {
"id": "bworld:stone",
"count": 2
},
"result": "bworld:stone_hoe"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:wood_shovel",
"material": {
"id": "bworld:stone",
"count": 1
},
"result": "bworld:stone_shovel"
}
}
+3 -2
View File
@@ -9,11 +9,12 @@ export function setup(ctx: ServerContext) {
register_farming(ctx);
}
// right clicking with a tool turns the block into another, like a hoe on grass
// right clicking with a type of tool turns the block into another, like any hoe on grass
function register_hoeable(ctx: ServerContext) {
ctx.components.register_block<{ tool: string; into: string }>("bworld:hoeable", {
on_interact(block, params, player) {
if (player.held_item?.id !== params.tool) {
const held = player.held_item;
if (!held || ctx.items.tool(held.id) !== params.tool) {
return false;
}
ctx.world.set_block(block.x, block.y, block.z, params.into);
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Some files were not shown because too many files have changed in this diff Show More