Phase 11: real block textures for 2D tiles
Layers texture-averaged colors on top of palette.rs's hand-picked table as a fallback (color_for_textured), not a hard replacement — biome-tinted/animated blocks (grass top, leaves, water, lava) deliberately keep the hand-picked color since averaging their raw jar textures would be wrong, not just imprecise. Vanilla: worker/src/textures.rs downloads Mojang's official client jar directly from launchermeta/piston-meta/piston-data (same endpoints the real launcher uses, gated behind ACCEPT_MINECRAFT_EULA=true, off by default, mirrors BlueMap's accept-download) and averages every block texture, cached to disk so it's not re-downloaded every restart. Modded: ingests block_registry/block_textures messages from the mod (new Postgres tables + MinIO storage in api/src/textures.ts) — sent once per connection over the existing WS gateway. texturepacks/<name>/ (Dynmap-style flat PNGs) lets an operator override the vanilla defaults worker-wide via TEXTURE_PACK. A per-server texturePack admin column/API exists for the same purpose, but render-time per-server resolution (of both the admin selection and the ingested modded textures) is explicitly deferred — the worker still applies one process-wide palette; true per-server resolution needs the render pipeline to thread a server-scoped palette through the batch/GPU-dispatch path, judged too big a change for this phase. Documented in README. Docker was unavailable in this dev environment for the usual integration-test verification; bunx tsc --noEmit was used as a fallback static check instead (clean except 2 pre-existing unrelated errors in markers.test.ts).
This commit is contained in:
@@ -8,6 +8,24 @@ pub use hybrid::HybridRenderBackend;
|
||||
|
||||
use image::{ImageEncoder, RgbImage};
|
||||
use std::io::Cursor;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use crate::textures::TexturePalette;
|
||||
|
||||
/// Set once at startup (see main.rs) if `ACCEPT_MINECRAFT_EULA` is set and a texture palette was
|
||||
/// built/loaded successfully — read by `base_colors` below so every `RenderBackend` (cpu/gpu/
|
||||
/// hybrid all share `base_colors`) automatically picks up texture-averaged colors without the
|
||||
/// `RenderBackend` trait itself needing a new parameter. Left unset in tests and when the operator
|
||||
/// hasn't opted into the EULA, which keeps `base_colors`/hand-picked-color test assertions valid —
|
||||
/// `palette::color_for_textured` falls back to `palette::color_for` whenever this is `None`.
|
||||
static TEXTURE_PALETTE: OnceLock<TexturePalette> = OnceLock::new();
|
||||
|
||||
/// Called at most once, before the first render (see main.rs). A second call is a no-op (`OnceLock`
|
||||
/// semantics) — main.rs only ever calls this once anyway, since the palette is resolved once at
|
||||
/// startup, not per-request.
|
||||
pub fn set_texture_palette(palette: TexturePalette) {
|
||||
let _ = TEXTURE_PALETTE.set(palette);
|
||||
}
|
||||
|
||||
/// One rendered column within a chunk, in chunk-local coordinates (0..16).
|
||||
pub struct ColumnPixel {
|
||||
@@ -53,12 +71,13 @@ pub trait RenderBackend: Send + Sync {
|
||||
/// — palette lookup is cheap (256 entries at most) and keeping it in one place avoids maintaining
|
||||
/// two copies of `palette::color_for`'s logic (one in Rust, one duplicated into WGSL).
|
||||
pub(crate) fn base_colors(columns: &[ColumnPixel]) -> [[u8; 3]; 256] {
|
||||
let textures = TEXTURE_PALETTE.get();
|
||||
let mut base = [crate::palette::color_for(0, 0); 256]; // air everywhere until overwritten
|
||||
for col in columns {
|
||||
if col.local_x as u32 >= CHUNK_SIZE || col.local_z as u32 >= CHUNK_SIZE {
|
||||
continue;
|
||||
}
|
||||
let color = crate::palette::color_for(col.block_id, col.block_meta);
|
||||
let color = crate::palette::color_for_textured(col.block_id, col.block_meta, textures);
|
||||
base[(col.local_z as usize) * 16 + col.local_x as usize] = color;
|
||||
}
|
||||
base
|
||||
|
||||
Reference in New Issue
Block a user