Compare commits
16
Commits
dee07eaa0c
..
native
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ced27d3400 | ||
|
|
90dd86b336 | ||
|
|
cbd662dc2a | ||
|
|
ed6f5fe0df | ||
|
|
25937f2c31 | ||
|
|
0d770c7bc4 | ||
|
|
a552883795 | ||
|
|
681d3afb4d | ||
|
|
527f2fb5a7 | ||
|
|
df7a1a94d6 | ||
|
|
a26d801f4e | ||
|
|
fe09e0cdd7 | ||
|
|
b9deda1a55 | ||
|
|
784bac7dd2 | ||
|
|
ac791b886e | ||
|
|
e751d22c6e |
@@ -16,7 +16,8 @@ Always ask before making even the simplest models, unless it's coming from ports
|
||||
## Layout
|
||||
|
||||
- `server/`: the game server, world, saves and server-side game logic
|
||||
- `client/`: the browser client: rendering, meshing and lighting workers, UI
|
||||
- `client/`: the client: rendering, meshing and lighting workers, UI. `client/native/` runs it in the desktop app
|
||||
- `desktop/`: the desktop app: its window, sound, singleplayer and client updates (see "Desktop first")
|
||||
- `common/`: code shared by both, including world generation, the protocol and the modding API (`common/mod_api/`)
|
||||
- `mods/`: mods, with JSON data (blocks, items, recipes, worldgen, tags), textures and TypeScript scripts
|
||||
- `docs/`: modding docs and `docs/modding_plan.md`
|
||||
@@ -33,6 +34,8 @@ deno test -A tests/door_test.ts # one test file, prefer this while working
|
||||
deno task check-mods # validate and typecheck every mod in mods/
|
||||
deno task build # pack mods and build the client, then keeps rebuilding on changes
|
||||
deno task server # start a server with the mods from the last build
|
||||
deno task desktop # run the desktop app with what the last build made
|
||||
deno task compile [linux] [windows] # build the desktop app's executables into dist/
|
||||
deno fmt # format (tabs, 120 columns), applies to JSON too
|
||||
deno task import KIND IN --output OUT # convert a java mod's resources, see tools/importer.ts
|
||||
```
|
||||
@@ -50,6 +53,24 @@ engine, since other mods would hit the same wall. See "The Engine and the Base G
|
||||
When changing the modding API, update the docs that cover it: `MODS.md` and `docs/modding/`, which follows the layout of
|
||||
`ports/neoforge-docs`.
|
||||
|
||||
## Desktop first
|
||||
|
||||
The desktop app is the main target and the browser a secondary one, so build and try new features in the desktop app
|
||||
first. The app (`desktop/`) is an SDL3 window that the client draws into with Deno's WebGPU, running in a Deno worker
|
||||
(`client/native/`), with sound through OpenAL Soft and a singleplayer server of its own.
|
||||
|
||||
- The client keeps using web APIs: WebGPU, Web Audio, fetch, WebSocket. Where Deno doesn't have one, polyfill the part
|
||||
the game uses, like `client/native/web_audio.ts` does over OpenAL, instead of writing engine code only the desktop app
|
||||
can run.
|
||||
- What has to differ between the two goes through `Platform` (`client/platform.ts`), which `client/browser_platform.ts`
|
||||
and `client/native/main.ts` implement, rather than checks for the DOM in shared code.
|
||||
- Keep the browser working, but a browser limitation doesn't block a feature: it can be missing or simpler there.
|
||||
- The client worker runs servers' mods, so it only gets the network and reading its own files, and gives up FFI once the
|
||||
window's surface exists. Don't widen its permissions.
|
||||
- The Windows build ships SDL3 and OpenAL Soft from `desktop/windows/`: unmodified files from their tagged releases,
|
||||
with their licenses and where they came from in `credits.txt` there, which the app shows in its credits. Update it
|
||||
along with the DLLs.
|
||||
|
||||
## Conventions
|
||||
|
||||
- Classes are PascalCase, everything else is snake_case: functions, variables, fields, files and ids.
|
||||
|
||||
@@ -131,6 +131,14 @@ async function build_client() {
|
||||
minify: false,
|
||||
keepNames: true,
|
||||
});
|
||||
// the desktop app's client, a deno worker next to main.js so it finds the same chunk worker, see client/native/
|
||||
await Deno.bundle({
|
||||
entrypoints: ["./client/native/main.ts"],
|
||||
outputPath: `${BUILD_FOLDER}/client/native.js`,
|
||||
platform: "deno",
|
||||
minify: false,
|
||||
keepNames: true,
|
||||
});
|
||||
await copy("./client/index.html", `${BUILD_FOLDER}/client/index.html`);
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { load_texture, Texture } from "./renderer/mod.ts";
|
||||
import { decode_png } from "./png.ts";
|
||||
import { platform } from "./platform.ts";
|
||||
|
||||
type Asset = Texture | string | Record<string, unknown>;
|
||||
|
||||
@@ -18,26 +20,24 @@ export class AssetManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// the client's own files are next to the page, see platform.page
|
||||
const url = new URL(src, platform.page);
|
||||
if (src.endsWith(".png")) {
|
||||
const img = new Image();
|
||||
const promise = new Promise<void>((resolve, reject) => {
|
||||
img.onload = () => {
|
||||
this.assets[key] = load_texture(img);
|
||||
resolve();
|
||||
};
|
||||
img.onerror = () => reject(new Error(`Failed to load image: ${src}`));
|
||||
});
|
||||
img.src = src;
|
||||
this.loading_promises.push(promise);
|
||||
const promise = async () => {
|
||||
const resp = await fetch(url);
|
||||
if (!resp.ok) throw new Error(`Failed to load image: ${src}`);
|
||||
this.assets[key] = load_texture(decode_png(new Uint8Array(await resp.arrayBuffer())));
|
||||
};
|
||||
this.loading_promises.push(promise());
|
||||
} else if (src.endsWith(".txt") || src.endsWith(".md") || src.endsWith(".fnt")) {
|
||||
const promise = async () => {
|
||||
const resp = await fetch(src);
|
||||
const resp = await fetch(url);
|
||||
this.assets[key] = await resp.text();
|
||||
};
|
||||
this.loading_promises.push(promise());
|
||||
} else if (src.endsWith(".json")) {
|
||||
const promise = async () => {
|
||||
const resp = await fetch(src);
|
||||
const resp = await fetch(url);
|
||||
this.assets[key] = await resp.json();
|
||||
};
|
||||
this.loading_promises.push(promise());
|
||||
|
||||
+46
-41
@@ -7,6 +7,8 @@ import { TEXTURE_SIZE } from "@/common/constants.ts";
|
||||
import type { SpriteRegion } from "@/common/constants.ts";
|
||||
import { type Animation, texture_animation, type TextureJson } from "@/common/texture_animation.ts";
|
||||
import { AnimatedTexture } from "./texture_animations.ts";
|
||||
import { decode_png, type Pixels } from "./png.ts";
|
||||
import { platform } from "./platform.ts";
|
||||
|
||||
export interface AtlasLayout {
|
||||
// in pixels, a power of two
|
||||
@@ -67,17 +69,16 @@ function pack_shelves(entries: [string, TextureSize][], size: number) {
|
||||
// textures are png bytes by id, texture_json the .json of the ones that have one. ones that don't decode show as
|
||||
// missing. an animated texture takes one frame's room, its first frame, and plays from animated (see
|
||||
// texture_animations.ts)
|
||||
export async function build_atlas(textures: Map<string, Uint8Array>, texture_json = new Map<string, TextureJson>()) {
|
||||
const images = new Map<string, ImageBitmap>();
|
||||
await Promise.all([...textures].map(async ([id, png]) => {
|
||||
export function build_atlas(textures: Map<string, Uint8Array>, texture_json = new Map<string, TextureJson>()) {
|
||||
const images = new Map<string, Pixels>();
|
||||
for (const [id, png] of textures) {
|
||||
if (id === "cubi:missing") continue;
|
||||
try {
|
||||
images.set(id, await createImageBitmap(new Blob([png as Uint8Array<ArrayBuffer>], { type: "image/png" })));
|
||||
images.set(id, decode_png(png));
|
||||
} catch {
|
||||
console.warn(`Texture ${id} isn't a png that can be shown, it will show as missing`);
|
||||
}
|
||||
}));
|
||||
images.get("cubi:missing")?.close();
|
||||
images.delete("cubi:missing");
|
||||
}
|
||||
|
||||
const animations = new Map<string, Animation>();
|
||||
for (const [id, image] of images) {
|
||||
@@ -91,43 +92,36 @@ export async function build_atlas(textures: Map<string, Uint8Array>, texture_jso
|
||||
}));
|
||||
|
||||
const { size, regions } = atlas_layout(sizes);
|
||||
const canvas = new OffscreenCanvas(size, size);
|
||||
const ctx = canvas.getContext("2d")!;
|
||||
const pixels = new Uint8ClampedArray(size * size * 4);
|
||||
const atlas = { width: size, height: size, data: pixels };
|
||||
|
||||
// magenta and black checker
|
||||
const missing = regions["cubi:missing"];
|
||||
const half = TEXTURE_SIZE / 2;
|
||||
ctx.fillStyle = "magenta";
|
||||
ctx.fillRect(missing.x, missing.y, half, half);
|
||||
ctx.fillRect(missing.x + half, missing.y + half, half, half);
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillRect(missing.x + half, missing.y, half, half);
|
||||
ctx.fillRect(missing.x, missing.y + half, half, half);
|
||||
for (let py = 0; py < TEXTURE_SIZE; py++) {
|
||||
for (let px = 0; px < TEXTURE_SIZE; px++) {
|
||||
const i = ((missing.y + py) * size + missing.x + px) * 4;
|
||||
const magenta = (px < half) === (py < half);
|
||||
pixels.set(magenta ? [255, 0, 255, 255] : [0, 0, 0, 255], i);
|
||||
}
|
||||
}
|
||||
|
||||
const animated: AnimatedTexture[] = [];
|
||||
for (const [id, image] of images) {
|
||||
const animation = animations.get(id);
|
||||
const { x, y, width, height } = regions[id];
|
||||
if (animation) {
|
||||
const first = animation.frames[0];
|
||||
ctx.drawImage(image, first.x, first.y, width, height, x, y, width, height);
|
||||
animated.push(new AnimatedTexture(regions[id], animation, image_pixels(image), image.width));
|
||||
} else {
|
||||
ctx.drawImage(image, x, y);
|
||||
}
|
||||
image.close();
|
||||
const first = animation?.frames[0] ?? { x: 0, y: 0 };
|
||||
copy_pixels(image, first.x, first.y, width, height, atlas, x, y);
|
||||
if (animation) animated.push(new AnimatedTexture(regions[id], animation, image.data, image.width));
|
||||
}
|
||||
for (const id of textures.keys()) {
|
||||
regions[id] ??= missing;
|
||||
}
|
||||
|
||||
const image_data = ctx.getImageData(0, 0, size, size);
|
||||
const pixels = image_data.data;
|
||||
extrude_borders(pixels, size, regions);
|
||||
ctx.putImageData(image_data, 0, 0);
|
||||
|
||||
// which pixels of each texture can be seen, for the 3d models of dropped items (see item_model.ts)
|
||||
built_atlas = image_data;
|
||||
built_atlas = atlas;
|
||||
opaque.clear();
|
||||
for (const [id, region] of Object.entries(regions)) {
|
||||
const mask = new Uint8Array(region.width * region.height);
|
||||
@@ -140,7 +134,24 @@ export async function build_atlas(textures: Map<string, Uint8Array>, texture_jso
|
||||
opaque.set(id, { width: region.width, height: region.height, mask });
|
||||
}
|
||||
|
||||
return { image: canvas.transferToImageBitmap(), regions, animated };
|
||||
return { image: atlas, regions, animated };
|
||||
}
|
||||
|
||||
// a width × height part of from, starting at from_x from_y, into to at to_x to_y
|
||||
function copy_pixels(
|
||||
from: Pixels,
|
||||
from_x: number,
|
||||
from_y: number,
|
||||
width: number,
|
||||
height: number,
|
||||
to: Pixels,
|
||||
to_x: number,
|
||||
to_y: number,
|
||||
) {
|
||||
for (let row = 0; row < height; row++) {
|
||||
const start = ((from_y + row) * from.width + from_x) * 4;
|
||||
to.data.set(from.data.subarray(start, start + width * 4), ((to_y + row) * to.width + to_x) * 4);
|
||||
}
|
||||
}
|
||||
|
||||
// fills each region's border with copies of its edge pixels, the corners with its corners. pixels is a size × size
|
||||
@@ -169,13 +180,6 @@ export function extrude_borders(pixels: Uint8ClampedArray, size: number, regions
|
||||
}
|
||||
}
|
||||
|
||||
// every frame of an animated texture stays in memory, to copy into the atlas when it's that frame's turn
|
||||
function image_pixels(image: ImageBitmap) {
|
||||
const ctx = new OffscreenCanvas(image.width, image.height).getContext("2d")!;
|
||||
ctx.drawImage(image, 0, 0);
|
||||
return ctx.getImageData(0, 0, image.width, image.height).data;
|
||||
}
|
||||
|
||||
// a texture's pixels, 1 (can be seen) or 0, row by row from the top
|
||||
export interface OpaqueMask {
|
||||
width: number;
|
||||
@@ -192,22 +196,23 @@ export function opaque_pixels(texture_id: string): OpaqueMask | undefined {
|
||||
}
|
||||
|
||||
// the last atlas built, before any animated texture moved on from its first frame
|
||||
let built_atlas: ImageData | undefined;
|
||||
let built_atlas: Pixels | undefined;
|
||||
|
||||
// the atlas as a png, undefined before one is built. for the f3 screen's copy button
|
||||
// the atlas as a png, undefined before one is built or where there's no canvas to encode it (the desktop app). for
|
||||
// the f3 screen's copy button
|
||||
export function atlas_png(): Promise<Blob> | undefined {
|
||||
if (!built_atlas) return undefined;
|
||||
if (!built_atlas || typeof document === "undefined") return undefined;
|
||||
const canvas = new OffscreenCanvas(built_atlas.width, built_atlas.height);
|
||||
canvas.getContext("2d")!.putImageData(built_atlas, 0, 0);
|
||||
canvas.getContext("2d")!.putImageData(new ImageData(built_atlas.data, built_atlas.width), 0, 0);
|
||||
return canvas.convertToBlob({ type: "image/png" });
|
||||
}
|
||||
|
||||
// the engine's own textures, which come with the client instead of a mod. see build_engine_textures in build.ts
|
||||
export async function engine_textures(): Promise<Map<string, Uint8Array>> {
|
||||
const names: string[] = await (await fetch("/assets/textures/index.json")).json();
|
||||
const names: string[] = await (await fetch(new URL("/assets/textures/index.json", platform.page))).json();
|
||||
const textures = new Map<string, Uint8Array>();
|
||||
await Promise.all(names.map(async (name) => {
|
||||
const response = await fetch(`/assets/textures/${name}.png`);
|
||||
const response = await fetch(new URL(`/assets/textures/${name}.png`, platform.page));
|
||||
textures.set(`cubi:${name}`, new Uint8Array(await response.arrayBuffer()));
|
||||
}));
|
||||
return textures;
|
||||
|
||||
@@ -15,8 +15,13 @@ export class WebAudioOutput implements SoundOutput {
|
||||
#buffers = new WeakMap<Uint8Array, Promise<AudioBuffer | undefined>>();
|
||||
#volumes: Volumes | undefined;
|
||||
|
||||
constructor() {
|
||||
// browsers keep audio off until the player clicks or presses a key, so it starts then
|
||||
// browsers keep audio off until the player clicks or presses a key, so it starts then. the desktop app's web audio
|
||||
// (client/native/web_audio.ts) has no such rule and starts right away
|
||||
constructor(wait_for_input = true) {
|
||||
if (!wait_for_input) {
|
||||
this.#unlock();
|
||||
return;
|
||||
}
|
||||
const unlock = () => {
|
||||
this.#unlock();
|
||||
if (this.#context?.state === "running") {
|
||||
|
||||
@@ -13,6 +13,7 @@ import type { GameRenderer } from "@/client/rendering/game_renderer.ts";
|
||||
import { block_visuals } from "@/client/rendering/visuals.ts";
|
||||
import { draw_item } from "@/client/rendering/render_utils.ts";
|
||||
import { InputManager } from "@/client/input_manager.ts";
|
||||
import { platform } from "@/client/platform.ts";
|
||||
import { type FrameSample, profiler } from "@/client/profiler.ts";
|
||||
import { RemotePlayer } from "@/client/entity/remote_player.ts";
|
||||
import { RemoteEntity } from "@/client/entity/remote_entity.ts";
|
||||
@@ -129,8 +130,9 @@ export class RenderBenchmark {
|
||||
// a line of names for each row of the gui scene's slots
|
||||
#gui_lines: string[];
|
||||
#system: SystemInfo;
|
||||
// the page was hidden, which stops frames
|
||||
// the game was hidden, which held frames back
|
||||
#hidden = false;
|
||||
#stop_watching_shown: () => void;
|
||||
#saved_debug = { ...render_debug };
|
||||
#saved_draw: Record<string, boolean>;
|
||||
|
||||
@@ -157,7 +159,7 @@ export class RenderBenchmark {
|
||||
for (const key of Object.keys(draw) as (keyof typeof draw)[]) draw[key] = true;
|
||||
Object.assign(render_debug, { msaa: false, split_passes: false, uncapped: false });
|
||||
set_canvas_size(RESOLUTION);
|
||||
document.addEventListener("visibilitychange", this.#on_visibility);
|
||||
this.#stop_watching_shown = platform.on_shown(() => this.#hidden = true);
|
||||
this.#flow = this.#run();
|
||||
}
|
||||
|
||||
@@ -167,7 +169,7 @@ export class RenderBenchmark {
|
||||
if (InputManager.is_key_pressed("Escape")) {
|
||||
this.#end("The benchmark was stopped");
|
||||
} else if (this.#hidden) {
|
||||
this.#end("The benchmark stopped since the page was hidden, which holds frames back");
|
||||
this.#end("The benchmark stopped since the game was hidden, which holds frames back");
|
||||
} else {
|
||||
this.#flow.next();
|
||||
}
|
||||
@@ -216,14 +218,10 @@ export class RenderBenchmark {
|
||||
set_canvas_size(undefined);
|
||||
profiler.samples = undefined;
|
||||
if (gpu_timer) gpu_timer.samples = undefined;
|
||||
document.removeEventListener("visibilitychange", this.#on_visibility);
|
||||
this.#stop_watching_shown();
|
||||
this.#on_end(result);
|
||||
}
|
||||
|
||||
#on_visibility = () => {
|
||||
if (document.hidden) this.#hidden = true;
|
||||
};
|
||||
|
||||
// the whole benchmark, a frame at each yield
|
||||
*#run(): Generator<void, void> {
|
||||
yield* this.#build();
|
||||
@@ -559,8 +557,9 @@ function system_info(workers: number): SystemInfo {
|
||||
gpu_features: [...device.features].sort(),
|
||||
timestamps: gpu_timer?.supported ?? false,
|
||||
canvas_format: navigator.gpu.getPreferredCanvasFormat(),
|
||||
device_pixel_ratio: devicePixelRatio,
|
||||
screen: `${screen.width}x${screen.height}`,
|
||||
// the desktop app's window is drawn a pixel to a pixel
|
||||
device_pixel_ratio: globalThis.devicePixelRatio ?? 1,
|
||||
screen: globalThis.screen && `${screen.width}x${screen.height}`,
|
||||
workers,
|
||||
};
|
||||
const hints = (navigator as { userAgentData?: UserAgentData }).userAgentData;
|
||||
|
||||
@@ -62,7 +62,8 @@ export interface SystemInfo {
|
||||
// the median fps where nothing is drawn, which is the display's refresh when the browser holds frames to it
|
||||
refresh_hz?: number;
|
||||
device_pixel_ratio: number;
|
||||
screen: string;
|
||||
// the browser's, the desktop app doesn't know it
|
||||
screen?: string;
|
||||
// meshing workers, see ChunkWorkerPool
|
||||
workers: number;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the page's keys and mouse for InputManager, and grabbing the mouse with the browser's pointer lock
|
||||
import { InputManager } from "./input_manager.ts";
|
||||
|
||||
// the keys the game keeps in fullscreen, see "fullscreenchange". not every key: with all of them locked, chromium
|
||||
// can keep alt+tab and the windows key from the os too
|
||||
const FULLSCREEN_LOCKED_KEYS = ["Escape", "KeyW"];
|
||||
|
||||
// chromium's keyboard lock api, typescript's dom types don't have it yet
|
||||
interface KeyboardLock {
|
||||
lock(codes?: string[]): Promise<void>;
|
||||
unlock(): void;
|
||||
}
|
||||
|
||||
let canvas: HTMLCanvasElement;
|
||||
|
||||
let pointer_lock_flag = false;
|
||||
let mouse_ungrab_timer = 0;
|
||||
let mouse_ungrab_timeout = -1;
|
||||
let pointer_lock_waiting = false;
|
||||
// chrome sometimes sends a huge movement with the first mouse event after the lock starts
|
||||
let skip_look_event = false;
|
||||
// the browser let go of the mouse while the game wanted it, like escape or switching windows
|
||||
let lost_pointer_lock = false;
|
||||
|
||||
export function listen_to_page(page_canvas: HTMLCanvasElement) {
|
||||
canvas = page_canvas;
|
||||
|
||||
self.addEventListener("keydown", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
InputManager.key_down(e.code, e.key, is_shortcut(e));
|
||||
});
|
||||
|
||||
self.addEventListener("blur", () => InputManager.release_all());
|
||||
|
||||
self.addEventListener("keyup", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
InputManager.key_up(e.code);
|
||||
});
|
||||
|
||||
self.addEventListener("mousedown", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!document.hasFocus() && document.pointerLockElement !== canvas) {
|
||||
set_mouse_grabbed(true);
|
||||
return;
|
||||
}
|
||||
InputManager.mouse_down(e.button);
|
||||
});
|
||||
|
||||
self.addEventListener("mouseup", (e) => {
|
||||
e.preventDefault();
|
||||
InputManager.mouse_up(e.button);
|
||||
});
|
||||
|
||||
// ctrl+scroll (and pinching a trackpad, which browsers send as that) would zoom the page. only a listener that
|
||||
// isn't passive can stop it, and on the window they're passive unless told otherwise
|
||||
self.addEventListener("wheel", (e) => {
|
||||
if (e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
}
|
||||
InputManager.scroll(e.deltaY);
|
||||
}, { passive: false });
|
||||
|
||||
document.addEventListener("mousemove", (e) => {
|
||||
e.preventDefault();
|
||||
if (document.pointerLockElement === canvas) {
|
||||
if (skip_look_event) {
|
||||
skip_look_event = false;
|
||||
return;
|
||||
}
|
||||
InputManager.look(e.movementX, e.movementY);
|
||||
} else {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
InputManager.move_cursor(e.clientX - rect.left, e.clientY - rect.top);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("pointerlockchange", () => {
|
||||
skip_look_event = document.pointerLockElement === canvas;
|
||||
self.setTimeout(() => {
|
||||
const grab = document.pointerLockElement === canvas;
|
||||
if (!grab) {
|
||||
if (pointer_lock_flag) {
|
||||
mouse_ungrab_timer = performance.now();
|
||||
lost_pointer_lock = true;
|
||||
}
|
||||
}
|
||||
pointer_lock_flag = grab;
|
||||
}, 60);
|
||||
pointer_lock_waiting = false;
|
||||
});
|
||||
|
||||
// in fullscreen, chromium's keyboard lock gives the game escape (holding it still leaves fullscreen) and ctrl+w,
|
||||
// instead of the browser leaving fullscreen or closing the tab. other browsers don't have it and work as before
|
||||
document.addEventListener("fullscreenchange", () => {
|
||||
const keyboard = (navigator as Navigator & { keyboard?: KeyboardLock }).keyboard;
|
||||
if (!keyboard?.lock) return;
|
||||
if (document.fullscreenElement) {
|
||||
keyboard.lock(FULLSCREEN_LOCKED_KEYS).catch(() => {});
|
||||
} else {
|
||||
keyboard.unlock();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("pointerlockerror", () => {
|
||||
pointer_lock_waiting = false;
|
||||
});
|
||||
}
|
||||
|
||||
// ctrl (cmd on macs) held for a shortcut. altgr types characters like @ and comes as ctrl+alt on windows, so it
|
||||
// isn't one. getModifierState("AltGraph") isn't used, some linux layouts report it along with plain ctrl
|
||||
function is_shortcut(e: KeyboardEvent) {
|
||||
return e.metaKey || (e.ctrlKey && !e.altKey);
|
||||
}
|
||||
|
||||
export async function set_mouse_grabbed(grab: boolean) {
|
||||
pointer_lock_flag = grab;
|
||||
// a retry to grab it again mustn't happen once it shouldn't be grabbed
|
||||
if (!grab && mouse_ungrab_timeout !== -1) {
|
||||
self.clearTimeout(mouse_ungrab_timeout);
|
||||
mouse_ungrab_timeout = -1;
|
||||
}
|
||||
// already how it should be, the game calls this every frame
|
||||
const locked = document.pointerLockElement === canvas;
|
||||
if (grab ? locked : !locked && !pointer_lock_waiting) {
|
||||
return;
|
||||
}
|
||||
const t = performance.now();
|
||||
if (grab) {
|
||||
InputManager.mouse_x = -1;
|
||||
InputManager.mouse_y = -1;
|
||||
pointer_lock_waiting = true;
|
||||
try {
|
||||
await canvas.requestPointerLock();
|
||||
} catch (_) { /* */ }
|
||||
if (mouse_ungrab_timeout !== -1) {
|
||||
self.clearTimeout(mouse_ungrab_timeout);
|
||||
}
|
||||
mouse_ungrab_timeout = -1;
|
||||
if (t - mouse_ungrab_timer < 3000) {
|
||||
mouse_ungrab_timeout = self.setTimeout(async () => {
|
||||
try {
|
||||
await canvas.requestPointerLock();
|
||||
} catch (_) { /* */ }
|
||||
}, 3100 - (t - mouse_ungrab_timer));
|
||||
}
|
||||
} else {
|
||||
if (!pointer_lock_waiting) {
|
||||
document.exitPointerLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// whether the browser took the mouse away since the last call, it eats the escape that does it
|
||||
export function take_lost_pointer_lock() {
|
||||
const lost = lost_pointer_lock;
|
||||
lost_pointer_lock = false;
|
||||
return lost;
|
||||
}
|
||||
|
||||
export function is_mouse_grabbed() {
|
||||
return document.hasFocus() && document.pointerLockElement === canvas;
|
||||
}
|
||||
|
||||
export function toggle_fullscreen() {
|
||||
if (!document.fullscreenElement) {
|
||||
canvas.requestFullscreen();
|
||||
} else {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the client in a browser page, see platform.ts
|
||||
import type { Platform } from "./platform.ts";
|
||||
import { render_debug } from "./renderer/mod.ts";
|
||||
import { CreditsScreen } from "./gui/credits_screen.ts";
|
||||
import { is_mouse_grabbed, set_mouse_grabbed, take_lost_pointer_lock, toggle_fullscreen } from "./browser_input.ts";
|
||||
|
||||
// with render_debug.uncapped, the most frames between two of the display's refreshes. it's the highest fps that shows,
|
||||
// 960 on a 60 hz display, and what the gpu can be behind by
|
||||
const UNCAPPED_FRAMES_PER_REFRESH = 16;
|
||||
|
||||
// with render_debug.uncapped: frames since the display last refreshed, and the frame waiting for the next one
|
||||
let frames_this_refresh = 0;
|
||||
let waiting_for_refresh: ((time: number) => void) | undefined;
|
||||
let refresh_requested = false;
|
||||
let next_task: MessageChannel | undefined;
|
||||
let next_task_frame: ((time: number) => void) | undefined;
|
||||
|
||||
// with the display's refresh, or with render_debug.uncapped right away, so frames aren't held to vsync and show what
|
||||
// they cost. up to UNCAPPED_FRAMES_PER_REFRESH, then it waits for the next refresh, which the browser holds back
|
||||
// while the gpu is behind, so frames the gpu can't keep up with don't pile up. the browser saying a frame is done
|
||||
// can't be waited on instead, firefox only says so every 100 ms when nothing else is sent to the gpu
|
||||
function request_frame(frame: (time: number) => void) {
|
||||
if (!render_debug.uncapped) {
|
||||
requestAnimationFrame(frame);
|
||||
return;
|
||||
}
|
||||
if (!refresh_requested) {
|
||||
refresh_requested = true;
|
||||
requestAnimationFrame(() => {
|
||||
refresh_requested = false;
|
||||
frames_this_refresh = 0;
|
||||
const waiting = waiting_for_refresh;
|
||||
waiting_for_refresh = undefined;
|
||||
waiting?.(performance.now());
|
||||
});
|
||||
}
|
||||
frames_this_refresh += 1;
|
||||
if (frames_this_refresh < UNCAPPED_FRAMES_PER_REFRESH) {
|
||||
// a task of its own, so input and the workers' messages get handled in between
|
||||
if (!next_task) {
|
||||
next_task = new MessageChannel();
|
||||
next_task.port1.onmessage = () => next_task_frame?.(performance.now());
|
||||
}
|
||||
next_task_frame = frame;
|
||||
next_task.port2.postMessage(null);
|
||||
} else {
|
||||
waiting_for_refresh = frame;
|
||||
}
|
||||
}
|
||||
|
||||
// pages that aren't https or localhost have no clipboard api, like a server on another computer, but the old way
|
||||
// still copies from a click
|
||||
function write_clipboard(text: string): Promise<void> {
|
||||
if (navigator.clipboard) return navigator.clipboard.writeText(text);
|
||||
const area = document.createElement("textarea");
|
||||
area.value = text;
|
||||
document.body.append(area);
|
||||
area.select();
|
||||
const copied = document.execCommand("copy");
|
||||
area.remove();
|
||||
return copied ? Promise.resolve() : Promise.reject(new Error("Couldn't copy"));
|
||||
}
|
||||
|
||||
function show_fatal_error(message: string) {
|
||||
document.exitPointerLock?.();
|
||||
|
||||
const overlay = document.createElement("div");
|
||||
overlay.style.cssText =
|
||||
"position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;" +
|
||||
"gap:12px;background:rgba(0,0,0,0.85);color:white;font:20px system-ui,sans-serif;text-align:center;";
|
||||
const text = document.createElement("div");
|
||||
text.textContent = message;
|
||||
const hint = document.createElement("div");
|
||||
hint.textContent = "Reload the page to try again.";
|
||||
hint.style.cssText = "font-size:14px;opacity:0.7;";
|
||||
overlay.append(text, hint);
|
||||
document.body.append(overlay);
|
||||
}
|
||||
|
||||
export const browser_platform: Platform = {
|
||||
get page() {
|
||||
return new URL(location.href);
|
||||
},
|
||||
restart(url) {
|
||||
location.href = url.href;
|
||||
},
|
||||
request_frame,
|
||||
get storage() {
|
||||
return localStorage;
|
||||
},
|
||||
on_shown(shown) {
|
||||
const listener = () => {
|
||||
if (!document.hidden) shown();
|
||||
};
|
||||
document.addEventListener("visibilitychange", listener);
|
||||
return () => document.removeEventListener("visibilitychange", listener);
|
||||
},
|
||||
// sprinting is ctrl and walking is w, and ctrl+w closes the tab without the page getting a say. in fullscreen
|
||||
// the keyboard lock catches it instead (see browser_input.ts)
|
||||
confirm_leaving(confirm) {
|
||||
self.onbeforeunload = confirm ? (event) => event.preventDefault() : null;
|
||||
},
|
||||
show_fatal_error,
|
||||
credits_screen: (on_back) => new CreditsScreen(on_back),
|
||||
read_clipboard: () =>
|
||||
navigator.clipboard ? navigator.clipboard.readText() : Promise.reject(new Error("No clipboard")),
|
||||
write_clipboard,
|
||||
set_mouse_grabbed,
|
||||
is_mouse_grabbed,
|
||||
take_lost_mouse: take_lost_pointer_lock,
|
||||
toggle_fullscreen,
|
||||
};
|
||||
+12
-3
@@ -318,7 +318,7 @@ export class Client {
|
||||
player.entity_interaction_range,
|
||||
(entity) =>
|
||||
entity instanceof RemotePlayer ||
|
||||
(entity instanceof RemoteEntity && !entity.dead && is_hittable(entity)),
|
||||
(entity instanceof RemoteEntity && !entity.dead && is_pickable(entity)),
|
||||
);
|
||||
// a block in front of the entity hides it
|
||||
this.hit_result = this.level.pick(
|
||||
@@ -352,6 +352,12 @@ export class Client {
|
||||
return;
|
||||
}
|
||||
|
||||
// middle click in creative gives the block under the crosshair, like minecraft's pick block
|
||||
if (hit && this.player.creative && InputManager.is_mouse_pressed(1)) {
|
||||
const block = EverythingRegistry.get_by_id<BlockRegistry>("blocks", hit.block);
|
||||
if (block) this.connection.send({ type: "chat", text: `/give ${block.id}` });
|
||||
}
|
||||
|
||||
// a click uses right away, holding it on blocks keeps using every USE_REPEAT_MS. not while it's using an item
|
||||
const now = performance.now();
|
||||
const use_pressed = InputManager.is_mouse_pressed(2) && !this.player.using_item;
|
||||
@@ -377,6 +383,8 @@ export class Client {
|
||||
if (!attacking && using) {
|
||||
this.game_mode.use_item_on(hit);
|
||||
}
|
||||
} else if (use_pressed && this.entity_hit) {
|
||||
this.game_mode.interact(this.entity_hit);
|
||||
} else if (use_pressed) {
|
||||
this.game_mode.use_item();
|
||||
} else if (!this.entity_hit && InputManager.is_mouse_pressed(0)) {
|
||||
@@ -413,7 +421,8 @@ export class Client {
|
||||
}
|
||||
}
|
||||
|
||||
// mobs can be hit, scripted entities like the fishing hook can't. kinds the client doesn't know are left to the server
|
||||
function is_hittable(entity: RemoteEntity) {
|
||||
// what the crosshair can be on: mobs and objects, not scripted entities like the fishing hook. kinds the client doesn't
|
||||
// know are left to the server
|
||||
function is_pickable(entity: RemoteEntity) {
|
||||
return EverythingRegistry.get<EntityJson>("entities", entity.type)?.behavior !== "scripted";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { AssetManager } from "./assets.ts";
|
||||
import { Client } from "./client.ts";
|
||||
import { InputManager } from "./input_manager.ts";
|
||||
import { Connection } from "./network.ts";
|
||||
import { Options } from "./options.ts";
|
||||
import { connect, HandshakeError, is_trusted, join, remember_trust, ServerAddress, type Welcome } from "./handshake.ts";
|
||||
import { build_atlas, engine_textures } from "./atlas.ts";
|
||||
import { set_texture_animations } from "./texture_animations.ts";
|
||||
import type { TextureJson } from "@/common/texture_animation.ts";
|
||||
import { ModLoadError } from "@/common/mod_loader.ts";
|
||||
import { begin_drawing, clear_background, device, end_drawing, init_font, load_texture } from "./renderer/mod.ts";
|
||||
import { is_stopped } from "./fatal.ts";
|
||||
import { download_mods, load_client_mods, set_mods_client } from "./mods.ts";
|
||||
import type { GuiScreen } from "./gui/gui_screen.ts";
|
||||
import { in_desktop_app, type JoinServer, TitleScreen } from "./gui/title_screen.ts";
|
||||
import { MainMenuScreen } from "./gui/main_menu.ts";
|
||||
import { DisconnectedScreen } from "./gui/disconnected_screen.ts";
|
||||
import { ConfirmModsScreen } from "./gui/confirm_mods_screen.ts";
|
||||
import { profiler } from "./profiler.ts";
|
||||
import { platform } from "./platform.ts";
|
||||
|
||||
// runs whatever is showing every frame: a menu screen before joining (and after leaving), or the game
|
||||
class ClientLoop {
|
||||
running = false;
|
||||
last_time = 0;
|
||||
client: Client | undefined;
|
||||
screen: GuiScreen | undefined;
|
||||
// over the screen, it gets the input while it's there
|
||||
overlay: GuiScreen | undefined;
|
||||
|
||||
frame_count = 0;
|
||||
last_fps_time = 0;
|
||||
|
||||
start() {
|
||||
platform.on_shown(() => {
|
||||
this.last_time = performance.now();
|
||||
});
|
||||
|
||||
this.running = true;
|
||||
const now = performance.now();
|
||||
this.last_time = now;
|
||||
this.frame_count = 0;
|
||||
this.last_fps_time = this.last_time;
|
||||
platform.request_frame((time) => this.loop(time));
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
show_screen(screen: GuiScreen) {
|
||||
this.screen?.on_close();
|
||||
this.client = undefined;
|
||||
platform.confirm_leaving(false);
|
||||
this.screen = screen;
|
||||
InputManager.set_mouse_grabbed(false);
|
||||
}
|
||||
|
||||
// shown over whatever screen is joining, see ConfirmModsScreen
|
||||
confirm_mods(address: ServerAddress, welcome: Welcome): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
this.overlay = new ConfirmModsScreen(address, welcome, (join) => {
|
||||
this.overlay = undefined;
|
||||
resolve(join);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
play(connection: Connection) {
|
||||
const client = new Client(connection, (message) => this.show_screen(new DisconnectedScreen(message)));
|
||||
set_mods_client(client);
|
||||
client.chat.add("Connected to the server");
|
||||
this.screen?.on_close();
|
||||
this.screen = undefined;
|
||||
this.client = client;
|
||||
platform.confirm_leaving(true);
|
||||
console.log("Game started");
|
||||
}
|
||||
|
||||
loop(time: number) {
|
||||
if (!this.running || is_stopped()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const delta = (time - this.last_time) / 1000;
|
||||
|
||||
profiler.begin_frame();
|
||||
profiler.section("begin frame", begin_drawing);
|
||||
clear_background(0.69, 0.8, 1, 1.0);
|
||||
if (this.client) {
|
||||
this.client.run_frame(delta);
|
||||
} else if (this.screen) {
|
||||
(this.overlay ?? this.screen).on_tick(delta);
|
||||
this.screen.on_render();
|
||||
this.overlay?.on_render();
|
||||
}
|
||||
profiler.section("submit", end_drawing);
|
||||
profiler.end_frame();
|
||||
|
||||
this.frame_count += 1;
|
||||
const now = performance.now();
|
||||
if (now - this.last_fps_time >= 1000) {
|
||||
const fps = (this.frame_count * 1000) / (now - this.last_fps_time);
|
||||
console.log(`FPS: ${fps.toFixed(2)}`);
|
||||
this.frame_count = 0;
|
||||
this.last_fps_time = now;
|
||||
}
|
||||
|
||||
InputManager.update();
|
||||
|
||||
this.last_time = time;
|
||||
platform.request_frame((time) => this.loop(time));
|
||||
}
|
||||
}
|
||||
|
||||
// a server's blocks, items and scripts can't be taken back out once loaded, so a failure after that point
|
||||
// can't go back to the title screen to try again, the page has to start over
|
||||
class FailedAfterLoadingMods extends Error {}
|
||||
|
||||
// the game only runs against a server, it owns the world and everything in it. see docs/modding/networking/index.md
|
||||
async function join_server(
|
||||
address: ServerAddress,
|
||||
name: string,
|
||||
status: (text: string) => void,
|
||||
confirm_mods: (address: ServerAddress, welcome: Welcome) => Promise<boolean>,
|
||||
): Promise<Connection> {
|
||||
const { socket, welcome } = await connect(address, name);
|
||||
console.log(`Connected to ${address.ws_url}`);
|
||||
|
||||
let loaded_mods = false;
|
||||
try {
|
||||
if (address.cross_origin && !is_trusted(address, welcome)) {
|
||||
status("Waiting for you to accept the server's mods...");
|
||||
if (!await confirm_mods(address, welcome)) {
|
||||
throw new HandshakeError(`You didn't join ${address.base.host}`);
|
||||
}
|
||||
remember_trust(address, welcome);
|
||||
}
|
||||
|
||||
// textures, blocks and items all come from the server's mods, so this happens before anything else
|
||||
status("Downloading the server's mods...");
|
||||
const mods = await download_mods(welcome.mods, address.base);
|
||||
const textures = await engine_textures();
|
||||
const texture_json = new Map<string, TextureJson>();
|
||||
for (const mod of mods) {
|
||||
for (const [id, png] of mod.textures) textures.set(id, png);
|
||||
for (const [id, json] of mod.texture_json ?? []) texture_json.set(id, json);
|
||||
}
|
||||
const atlas = build_atlas(textures, texture_json);
|
||||
loaded_mods = true;
|
||||
const atlas_texture = load_texture(atlas.image);
|
||||
set_texture_animations(atlas_texture.tex, device.queue, atlas.animated);
|
||||
AssetManager.instance.assets["cubi:textures"] = atlas_texture;
|
||||
AssetManager.instance.assets["cubi:textures_info"] = atlas.regions;
|
||||
await load_client_mods(welcome.mods, mods);
|
||||
console.log(`Mods: ${welcome.mods.map((mod) => `${mod.id} ${mod.version}`).join(", ") || "none"}`);
|
||||
|
||||
status("Joining...");
|
||||
const joined = await join(socket, new Options().render_distance);
|
||||
return new Connection(socket, welcome, joined);
|
||||
} catch (e) {
|
||||
socket.close();
|
||||
const message = error_message(e);
|
||||
throw loaded_mods ? new FailedAfterLoadingMods(message) : new HandshakeError(message);
|
||||
}
|
||||
}
|
||||
|
||||
function error_message(e: unknown) {
|
||||
if (e instanceof HandshakeError) {
|
||||
return e.message;
|
||||
}
|
||||
if (e instanceof ModLoadError) {
|
||||
return `Couldn't load the server's mods: ${e.message}`;
|
||||
}
|
||||
return `Something went wrong joining the server: ${e instanceof Error ? e.message : e}`;
|
||||
}
|
||||
|
||||
// the title screen (the main menu in the desktop app), and the game once it joins a server. the platform is set, the
|
||||
// window was set up with init_window, and input comes in
|
||||
export async function start_client() {
|
||||
AssetManager.instance.load("cubi:assets_text", "/assets/ASSETS.md");
|
||||
|
||||
AssetManager.instance.load("cubi:skin", "/assets/sprites/skin_template.png");
|
||||
AssetManager.instance.load("cubi:gui", "/assets/sprites/gui.png");
|
||||
|
||||
AssetManager.instance.load("cubi:m6x11", "/assets/fonts/m6x11.png");
|
||||
AssetManager.instance.load("cubi:m6x11_fnt", "/assets/fonts/m6x11.fnt");
|
||||
|
||||
await AssetManager.instance.load_all();
|
||||
|
||||
init_font();
|
||||
|
||||
const loop = new ClientLoop();
|
||||
const join_game: JoinServer = async (address, name, status) => {
|
||||
let connection: Connection;
|
||||
try {
|
||||
connection = await join_server(
|
||||
address,
|
||||
name,
|
||||
status,
|
||||
(address, welcome) => loop.confirm_mods(address, welcome),
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof FailedAfterLoadingMods) {
|
||||
loop.show_screen(new DisconnectedScreen(e.message));
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
loop.play(connection);
|
||||
};
|
||||
loop.show_screen(
|
||||
in_desktop_app()
|
||||
? new MainMenuScreen((screen) => loop.show_screen(screen), join_game)
|
||||
: new TitleScreen(join_game),
|
||||
);
|
||||
loop.start();
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type { ServerAddress, Welcome } from "./handshake.ts";
|
||||
|
||||
// asks before running a server's mods when the page came from somewhere else, see docs/modding/concepts/security.md.
|
||||
// resolves with whether the player wants to join
|
||||
export function confirm_mods(address: ServerAddress, welcome: Welcome): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
const overlay = document.createElement("div");
|
||||
overlay.style.cssText =
|
||||
"position:fixed;inset:0;display:flex;align-items:center;justify-content:center;padding:16px;" +
|
||||
"background:rgba(0,0,0,0.85);color:white;font:16px system-ui,sans-serif;";
|
||||
|
||||
const panel = document.createElement("div");
|
||||
panel.style.cssText = "max-width:480px;display:flex;flex-direction:column;gap:12px;";
|
||||
|
||||
const title = document.createElement("div");
|
||||
title.style.cssText = "font-size:20px;";
|
||||
title.textContent = `Join ${address.base.host}?`;
|
||||
|
||||
const warning = document.createElement("div");
|
||||
warning.style.cssText = "opacity:0.8;";
|
||||
warning.textContent = "This server runs these mods in your browser. They can do anything this page can, " +
|
||||
"including reading what it saved. Only join servers you trust.";
|
||||
|
||||
const list = document.createElement("ul");
|
||||
list.style.cssText = "margin:0;padding-left:20px;";
|
||||
for (const mod of welcome.mods) {
|
||||
const item = document.createElement("li");
|
||||
// it can change anything about the game, not just add to it
|
||||
const access = mod.engine_access ? ", changes the engine" : "";
|
||||
item.textContent = `${mod.name} ${mod.version} (${mod.id}${access})`;
|
||||
list.append(item);
|
||||
}
|
||||
|
||||
const buttons = document.createElement("div");
|
||||
buttons.style.cssText = "display:flex;gap:8px;justify-content:flex-end;";
|
||||
const button = (label: string, answer: boolean) => {
|
||||
const element = document.createElement("button");
|
||||
element.textContent = label;
|
||||
element.style.cssText = "font:inherit;padding:6px 16px;cursor:pointer;";
|
||||
element.addEventListener("click", () => {
|
||||
overlay.remove();
|
||||
resolve(answer);
|
||||
});
|
||||
return element;
|
||||
};
|
||||
buttons.append(button("Cancel", false), button("Join", true));
|
||||
|
||||
panel.append(title, warning, list, buttons);
|
||||
overlay.append(panel);
|
||||
document.body.append(overlay);
|
||||
});
|
||||
}
|
||||
+3
-10
@@ -36,7 +36,6 @@ export abstract class Player extends Entity {
|
||||
// which way the body lies while swimming, radians up from flat: the way they're going, or looking when still
|
||||
swim_pitch = 0;
|
||||
prev_swim_pitch = 0;
|
||||
#skin_version = 0;
|
||||
|
||||
constructor(level: ClientLevel, id: string, name: string) {
|
||||
super(level, id, PLAYER_WIDTH, PLAYER_HEIGHT, PLAYER_EYE_HEIGHT);
|
||||
@@ -72,15 +71,9 @@ export abstract class Player extends Entity {
|
||||
};
|
||||
}
|
||||
|
||||
// a base64 png from the server, or undefined for the default. the old skin stays until the new one is decoded
|
||||
async set_skin(skin: string | undefined, slim = false) {
|
||||
const version = ++this.#skin_version;
|
||||
const texture = skin ? await decode_skin(skin) : undefined;
|
||||
if (version !== this.#skin_version) {
|
||||
// a newer skin came while this one was decoding
|
||||
texture?.tex.destroy();
|
||||
return;
|
||||
}
|
||||
// a base64 png from the server, or undefined for the default
|
||||
set_skin(skin: string | undefined, slim = false) {
|
||||
const texture = skin ? decode_skin(skin) : undefined;
|
||||
this.skin?.tex.destroy();
|
||||
this.skin = texture;
|
||||
this.slim = slim;
|
||||
|
||||
+3
-13
@@ -1,6 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { platform } from "./platform.ts";
|
||||
|
||||
let stopped = false;
|
||||
|
||||
// replaces the game with a message, for when it can't go on (no server, lost connection)
|
||||
@@ -9,19 +11,7 @@ export function show_fatal_error(message: string) {
|
||||
return;
|
||||
}
|
||||
stopped = true;
|
||||
document.exitPointerLock?.();
|
||||
|
||||
const overlay = document.createElement("div");
|
||||
overlay.style.cssText =
|
||||
"position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;" +
|
||||
"gap:12px;background:rgba(0,0,0,0.85);color:white;font:20px system-ui,sans-serif;text-align:center;";
|
||||
const text = document.createElement("div");
|
||||
text.textContent = message;
|
||||
const hint = document.createElement("div");
|
||||
hint.textContent = "Reload the page to try again.";
|
||||
hint.style.cssText = "font-size:14px;opacity:0.7;";
|
||||
overlay.append(text, hint);
|
||||
document.body.append(overlay);
|
||||
platform.show_fatal_error(message);
|
||||
}
|
||||
|
||||
export function is_stopped() {
|
||||
|
||||
+10
-2
@@ -196,20 +196,28 @@ export class MultiPlayerGameMode {
|
||||
this.client.player.last_attack = performance.now();
|
||||
}
|
||||
|
||||
// right click on an entity or another player, for mods' entity_interact. the server uses the held item when none
|
||||
// of them stops it
|
||||
interact(entity: Entity) {
|
||||
this.client.player.send_position_now();
|
||||
this.client.connection.send({ type: "interact_entity", id: entity.id });
|
||||
}
|
||||
|
||||
// right click on nothing
|
||||
use_item() {
|
||||
this.client.connection.send({ type: "use_item" });
|
||||
}
|
||||
|
||||
// whether a mob's or player's collision box overlaps the block, the server doesn't let solid blocks go there. mobs
|
||||
// are the mod entities that aren't scripted, players are this one and the others
|
||||
// are the mod entities that aren't scripted or objects, players are this one and the others
|
||||
#occupied(x: number, y: number, z: number, block: BlockRegistry, value: number) {
|
||||
const shape = collision_shape_at(block, value);
|
||||
for (const entity of this.client.level.entities.values()) {
|
||||
const json = entity instanceof RemoteEntity
|
||||
? EverythingRegistry.get<EntityJson>("entities", entity.type)
|
||||
: undefined;
|
||||
const blocks = entity instanceof Player || (json !== undefined && json.behavior !== "scripted");
|
||||
const blocks = entity instanceof Player ||
|
||||
(json !== undefined && json.behavior !== "scripted" && json.behavior !== "object");
|
||||
if (blocks && box_overlaps_block(entity, x, y, z, shape)) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { InputManager } from "@/client/input_manager.ts";
|
||||
import { canvas, draw_rect, draw_text, measure_text } from "@/client/renderer/mod.ts";
|
||||
import type { ServerAddress, Welcome } from "@/client/handshake.ts";
|
||||
import { GuiScreen } from "./gui_screen.ts";
|
||||
import { Button, LIST_ROW_HEIGHT, ListBox, TEXT_HEIGHT, TEXT_SCALE, wrap_text } from "./widgets.ts";
|
||||
|
||||
const MAX_WIDTH = 720;
|
||||
const MARGIN = 32;
|
||||
const GAP = 20;
|
||||
const BUTTON_HEIGHT = 48;
|
||||
const TITLE_SCALE = 4;
|
||||
const LINE_HEIGHT = TEXT_HEIGHT * TEXT_SCALE + 6;
|
||||
const WARNING = "This server runs these mods in the game. They can do anything the game can, including reading what " +
|
||||
"it saved. Only join servers you trust.";
|
||||
|
||||
// asks before running the mods of a server that isn't the page's own, see docs/modding/concepts/security.md. it's
|
||||
// shown over the screen that's joining, and answer gets whether the player wants to join
|
||||
export class ConfirmModsScreen extends GuiScreen {
|
||||
#title: string;
|
||||
#warning: string[] = [];
|
||||
// what the warning was wrapped for
|
||||
#wrapped_width = 0;
|
||||
#list = new ListBox(0, 0, () => {});
|
||||
#cancel: Button;
|
||||
#join: Button;
|
||||
|
||||
constructor(address: ServerAddress, welcome: Welcome, answer: (join: boolean) => void) {
|
||||
super();
|
||||
this.#title = `Join ${address.base.host}?`;
|
||||
this.#list.rows = welcome.mods.map((mod) => {
|
||||
// it can change anything about the game, not just add to it
|
||||
const access = mod.engine_access ? ", changes the engine" : "";
|
||||
return { text: `${mod.name} ${mod.version} (${mod.id}${access})` };
|
||||
});
|
||||
this.#cancel = new Button("Cancel", 0, BUTTON_HEIGHT, () => answer(false));
|
||||
this.#join = new Button("Join", 0, BUTTON_HEIGHT, () => answer(true));
|
||||
}
|
||||
|
||||
on_tick(_delta: number): void {
|
||||
const width = Math.min(MAX_WIDTH, canvas.width - MARGIN * 2);
|
||||
if (width !== this.#wrapped_width) {
|
||||
this.#wrapped_width = width;
|
||||
this.#warning = wrap_text(WARNING, width);
|
||||
}
|
||||
// the list gets what room the title, the warning and the buttons leave
|
||||
const above = this.#warning_y + this.#warning.length * LINE_HEIGHT + GAP;
|
||||
const room = canvas.height - MARGIN * 2 - above - GAP - BUTTON_HEIGHT;
|
||||
const list = this.#list;
|
||||
list.width = width;
|
||||
list.height = Math.max(LIST_ROW_HEIGHT, Math.min(list.rows.length * LIST_ROW_HEIGHT, room));
|
||||
this.x = (canvas.width - width) / 2;
|
||||
this.y = Math.max(MARGIN, (canvas.height - above - list.height - GAP - BUTTON_HEIGHT) / 2);
|
||||
list.x = this.x;
|
||||
list.y = this.y + above;
|
||||
const half = (width - GAP) / 2;
|
||||
for (const [i, button] of [this.#cancel, this.#join].entries()) {
|
||||
button.width = half;
|
||||
button.x = this.x + i * (half + GAP);
|
||||
button.y = list.y + list.height + GAP;
|
||||
}
|
||||
|
||||
// only a click joins, never a key pressed for something else, like the enter that joined the server
|
||||
if (InputManager.is_key_pressed("Escape")) return this.#cancel.on_press();
|
||||
list.handle_input();
|
||||
this.#cancel.handle_input();
|
||||
this.#join.handle_input();
|
||||
}
|
||||
|
||||
on_render(): void {
|
||||
draw_rect(0, 0, canvas.width, canvas.height, [0, 0, 0, 0.85]);
|
||||
draw_text(this.#title, (canvas.width - measure_text(this.#title, TITLE_SCALE)) / 2, this.y, TITLE_SCALE);
|
||||
for (const [i, line] of this.#warning.entries()) {
|
||||
draw_text(line, this.x, this.y + this.#warning_y + i * LINE_HEIGHT, TEXT_SCALE, [0.85, 0.85, 0.85, 1]);
|
||||
}
|
||||
this.#list.render();
|
||||
this.#cancel.render();
|
||||
this.#join.render();
|
||||
}
|
||||
|
||||
on_close(): void {}
|
||||
|
||||
// below the title, from the screen's top
|
||||
get #warning_y() {
|
||||
return TEXT_HEIGHT * TITLE_SCALE + GAP;
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ export class CreditsScreen extends GuiScreen {
|
||||
|
||||
const content = document.createElement("div");
|
||||
content.style.cssText = "overflow-y:auto;flex:1;min-height:0;padding-right:8px;";
|
||||
content.innerHTML = this.#sections().map(({ heading, text }) =>
|
||||
content.innerHTML = credit_sections().map(({ heading, text }) =>
|
||||
`<section><h2 style="border-bottom:1px solid #374151;padding-bottom:4px">${escape_html(heading)}</h2>` +
|
||||
`${markdown.parse(text, { async: false })}</section>`
|
||||
).join("");
|
||||
@@ -72,14 +72,6 @@ export class CreditsScreen extends GuiScreen {
|
||||
document.body.append(this.#overlay);
|
||||
}
|
||||
|
||||
#sections() {
|
||||
const sections = [{ heading: "cubi", text: AssetManager.instance.get<string>("cubi:assets_text") ?? "" }];
|
||||
for (const mod of mod_credits) {
|
||||
sections.push({ heading: `${mod.name} ${mod.version}`, text: mod.text });
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
|
||||
on_tick(_delta: number): void {}
|
||||
|
||||
on_render(): void {
|
||||
@@ -91,6 +83,15 @@ export class CreditsScreen extends GuiScreen {
|
||||
}
|
||||
}
|
||||
|
||||
// the engine's assets/ASSETS.md, then each loaded mod's credits file, as markdown
|
||||
export function credit_sections(): { heading: string; text: string }[] {
|
||||
const sections = [{ heading: "cubi", text: AssetManager.instance.get<string>("cubi:assets_text") ?? "" }];
|
||||
for (const mod of mod_credits) {
|
||||
sections.push({ heading: `${mod.name} ${mod.version}`, text: mod.text });
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
|
||||
function escape_html(text: string) {
|
||||
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { RENDER_LAYERS } from "@/common/everything_registry.ts";
|
||||
import { atlas_png } from "@/client/atlas.ts";
|
||||
import { RenderBenchmark } from "@/client/benchmark/benchmark.ts";
|
||||
import { format_report } from "@/client/benchmark/report.ts";
|
||||
import { platform } from "@/client/platform.ts";
|
||||
|
||||
// how often the totals that go through every chunk are worked out again, so the overlay doesn't slow the frames it's
|
||||
// measuring
|
||||
@@ -113,7 +114,7 @@ export class DebugOverlay {
|
||||
if (copy) {
|
||||
const switches = { ...render_debug, ...level_renderer.draw };
|
||||
lines.push(Object.entries(switches).map(([key, on]) => ` ${key}: ${on}`).join("\n"));
|
||||
copy_text(lines.join("\n")).catch(() => {});
|
||||
platform.write_clipboard(lines.join("\n")).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +138,7 @@ export class DebugOverlay {
|
||||
|
||||
// right after the benchmark, firefox and safari only let the page copy from a click
|
||||
#copy_benchmark() {
|
||||
copy_text(this.#benchmark_report!).then(
|
||||
platform.write_clipboard(this.#benchmark_report!).then(
|
||||
() => this.#benchmark_status = "The benchmark's results are on the clipboard",
|
||||
() => this.#benchmark_status = "Click above to copy the benchmark's results",
|
||||
);
|
||||
@@ -187,16 +188,3 @@ export class DebugOverlay {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pages that aren't https or localhost have no clipboard api, like a server on another computer, but the old way
|
||||
// still copies from a click
|
||||
function copy_text(text: string): Promise<void> {
|
||||
if (navigator.clipboard) return navigator.clipboard.writeText(text);
|
||||
const area = document.createElement("textarea");
|
||||
area.value = text;
|
||||
document.body.append(area);
|
||||
area.select();
|
||||
const copied = document.execCommand("copy");
|
||||
area.remove();
|
||||
return copied ? Promise.resolve() : Promise.reject(new Error("Couldn't copy"));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { InputManager } from "@/client/input_manager.ts";
|
||||
import { canvas, draw_rect, draw_text, measure_text } from "@/client/renderer/mod.ts";
|
||||
import { server_address } from "@/client/handshake.ts";
|
||||
import { GuiScreen } from "./gui_screen.ts";
|
||||
import { CreditsScreen } from "./credits_screen.ts";
|
||||
import { platform } from "../platform.ts";
|
||||
import type { JoinServer } from "./title_screen.ts";
|
||||
import { Button, EditBox, ListBox, TEXT_HEIGHT, TEXT_SCALE, TextInput } from "./widgets.ts";
|
||||
|
||||
@@ -37,7 +37,7 @@ export class MainMenuScreen extends GuiScreen {
|
||||
new Button("Singleplayer", WIDTH, ROW_HEIGHT, () => show(new WorldListScreen(show, join))),
|
||||
multiplayer,
|
||||
mods,
|
||||
new Button("Credits", WIDTH, ROW_HEIGHT, () => show(new CreditsScreen(back))),
|
||||
new Button("Credits", WIDTH, ROW_HEIGHT, () => show(platform.credits_screen(back))),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class WorldListScreen extends GuiScreen {
|
||||
this.#status.set(`Starting ${world.name}...`);
|
||||
try {
|
||||
await desktop("play", { world: world.name });
|
||||
await this.#join(server_address(location.host), SINGLEPLAYER_NAME, (text) => this.#status.set(text));
|
||||
await this.#join(server_address(platform.page.host), SINGLEPLAYER_NAME, (text) => this.#status.set(text));
|
||||
} catch (e) {
|
||||
this.#status.fail(e);
|
||||
this.#busy = false;
|
||||
@@ -294,7 +294,10 @@ function draw_centered(text: string, y: number, scale: number) {
|
||||
|
||||
// asks the desktop app, see desktop/main.ts. throws with what the app said went wrong
|
||||
async function desktop(path: string, body: unknown = {}): Promise<Response> {
|
||||
const response = await fetch(`/desktop/${path}`, { method: "POST", body: JSON.stringify(body) });
|
||||
const response = await fetch(new URL(`/desktop/${path}`, platform.page), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!response.ok) throw new Error(await response.text());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Client } from "@/client/client.ts";
|
||||
import { canvas, draw_rect, draw_text, measure_text } from "@/client/renderer/mod.ts";
|
||||
import { GuiScreen } from "./gui_screen.ts";
|
||||
import { Button, TEXT_HEIGHT } from "./widgets.ts";
|
||||
import { CreditsScreen } from "./credits_screen.ts";
|
||||
import { platform } from "../platform.ts";
|
||||
|
||||
const BUTTON_WIDTH = 440;
|
||||
const BUTTON_HEIGHT = 48;
|
||||
@@ -20,7 +20,7 @@ export class PauseScreen extends GuiScreen {
|
||||
this.buttons = [
|
||||
new Button("Back to game", BUTTON_WIDTH, BUTTON_HEIGHT, () => client.pop_screen()),
|
||||
new Button("Credits", BUTTON_WIDTH, BUTTON_HEIGHT, () => {
|
||||
client.push_screen(new CreditsScreen(() => client.pop_screen()));
|
||||
client.push_screen(platform.credits_screen(() => client.pop_screen()));
|
||||
}),
|
||||
new Button("Disconnect", BUTTON_WIDTH, BUTTON_HEIGHT, () => client.disconnect()),
|
||||
];
|
||||
|
||||
+11
-11
@@ -7,7 +7,7 @@ import { canvas, draw_rect, draw_text, measure_text } from "@/client/renderer/mo
|
||||
import { default_server, HandshakeError, server_address, ServerAddress } from "@/client/handshake.ts";
|
||||
import { default_player_name } from "@/client/network.ts";
|
||||
import { GuiScreen } from "./gui_screen.ts";
|
||||
import { CreditsScreen } from "./credits_screen.ts";
|
||||
import { platform } from "../platform.ts";
|
||||
import { Button, EditBox, TEXT_HEIGHT, TEXT_SCALE, TextInput } from "./widgets.ts";
|
||||
|
||||
const LAST_SERVER_KEY = "cubi:last_server";
|
||||
@@ -40,7 +40,7 @@ export class TitleScreen extends GuiScreen {
|
||||
// the desktop app for this computer's os
|
||||
download_button = new Button(`Download for ${download_os().name}`, WIDTH, ROW_HEIGHT, download_desktop_app);
|
||||
// open over the title screen, it gets the input while it's there
|
||||
#credits: CreditsScreen | undefined;
|
||||
#credits: GuiScreen | undefined;
|
||||
|
||||
status = "";
|
||||
status_is_error = false;
|
||||
@@ -118,7 +118,7 @@ export class TitleScreen extends GuiScreen {
|
||||
}
|
||||
|
||||
#open_credits() {
|
||||
this.#credits ??= new CreditsScreen(() => this.#close_credits());
|
||||
this.#credits ??= platform.credits_screen(() => this.#close_credits());
|
||||
}
|
||||
|
||||
#close_credits() {
|
||||
@@ -188,18 +188,18 @@ export class TitleScreen extends GuiScreen {
|
||||
|
||||
// what was typed last time, unless the page was opened with ?server= or ?name=
|
||||
function initial_server() {
|
||||
const page = new URL(location.href);
|
||||
const page = platform.page;
|
||||
return page.searchParams.has("server") ? default_server(page) : recall(LAST_SERVER_KEY) ?? default_server(page);
|
||||
}
|
||||
|
||||
function initial_name() {
|
||||
const page = new URL(location.href);
|
||||
const page = platform.page;
|
||||
return page.searchParams.has("name") ? default_player_name() : recall(LAST_NAME_KEY) ?? "";
|
||||
}
|
||||
|
||||
function recall(key: string): string | undefined {
|
||||
try {
|
||||
return localStorage.getItem(key) ?? undefined;
|
||||
return platform.storage.getItem(key) ?? undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ function recall(key: string): string | undefined {
|
||||
|
||||
function remember(key: string, value: string) {
|
||||
try {
|
||||
localStorage.setItem(key, value);
|
||||
platform.storage.setItem(key, value);
|
||||
} catch {
|
||||
// private windows and blocked storage just start empty next time
|
||||
}
|
||||
@@ -215,7 +215,7 @@ function remember(key: string, value: string) {
|
||||
|
||||
// the page is the desktop app's, see desktop/main.ts
|
||||
export function in_desktop_app() {
|
||||
return new URL(location.href).searchParams.has("singleplayer");
|
||||
return platform.page.searchParams.has("singleplayer");
|
||||
}
|
||||
|
||||
// the desktop app's build for the os the browser is on, which the server has in /dist/, see DESKTOP_DOWNLOADS. everything that isn't windows
|
||||
@@ -237,11 +237,11 @@ function download_desktop_app() {
|
||||
// or ?name=, so the fields show what was used last. the desktop app keeps its ?singleplayer and ?server=, for its
|
||||
// main menu
|
||||
export function back_to_title() {
|
||||
const page = new URL(location.href);
|
||||
const next = new URL(location.pathname, location.href);
|
||||
const page = platform.page;
|
||||
const next = new URL(page.pathname, page);
|
||||
if (in_desktop_app()) {
|
||||
next.searchParams.set("server", page.searchParams.get("server") ?? "");
|
||||
next.searchParams.set("singleplayer", "");
|
||||
}
|
||||
location.href = next.href;
|
||||
platform.restart(next);
|
||||
}
|
||||
|
||||
+23
-3
@@ -5,6 +5,7 @@ import { point_inside_rec } from "@/common/utils.ts";
|
||||
import { InputManager, type KeyCode } from "@/client/input_manager.ts";
|
||||
import { draw_rect, draw_rect_stroke, draw_text, measure_text } from "@/client/renderer/mod.ts";
|
||||
import { draw_gui_sprite } from "./gui_sprites.ts";
|
||||
import { platform } from "@/client/platform.ts";
|
||||
|
||||
export const TEXT_SCALE = 2;
|
||||
// how tall the font is at scale 1
|
||||
@@ -124,14 +125,14 @@ export class TextInput {
|
||||
const copy = InputManager.is_shortcut_pressed("c");
|
||||
const cut = InputManager.is_shortcut_pressed("x");
|
||||
if ((copy || cut) && this.anchor !== this.caret) {
|
||||
navigator.clipboard?.writeText(this.selected_text()).catch(() => {});
|
||||
platform.write_clipboard(this.selected_text()).catch(() => {});
|
||||
if (cut) {
|
||||
this.delete_to(this.caret);
|
||||
}
|
||||
}
|
||||
if (InputManager.is_shortcut_pressed("v")) {
|
||||
// the browser may ask first, it's put in once it answers
|
||||
navigator.clipboard?.readText().then((text) => this.insert(text), () => {});
|
||||
platform.read_clipboard().then((text) => this.insert(text), () => {});
|
||||
}
|
||||
for (const char of InputManager.get_typed_characters()) {
|
||||
this.insert(char);
|
||||
@@ -346,7 +347,7 @@ export class EditBox {
|
||||
}
|
||||
}
|
||||
|
||||
const LIST_ROW_HEIGHT = 40;
|
||||
export const LIST_ROW_HEIGHT = 40;
|
||||
const CHECK_SIZE = 20;
|
||||
|
||||
// rows of text that scroll with the mouse wheel, like minecraft's selection lists. a row can have a box ticked or not
|
||||
@@ -420,3 +421,22 @@ export class ListBox {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// text split into lines no wider than width pixels at TEXT_SCALE, at spaces and at its own line breaks
|
||||
export function wrap_text(text: string, width: number): string[] {
|
||||
const lines: string[] = [];
|
||||
for (const line of text.split("\n")) {
|
||||
let current = "";
|
||||
for (const word of line.split(" ")) {
|
||||
const next = current ? `${current} ${word}` : word;
|
||||
if (current && measure_text(next, TEXT_SCALE) > width) {
|
||||
lines.push(current);
|
||||
current = word;
|
||||
} else {
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
lines.push(current);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
+5
-4
@@ -4,6 +4,7 @@
|
||||
// connecting to a server and getting what it needs before joining, see docs/modding/networking/index.md:
|
||||
// hello -> welcome, download and check everything, ready -> join
|
||||
import { ClientMessage, PROTOCOL_VERSION, ServerMessage } from "@/common/protocol.ts";
|
||||
import { platform } from "./platform.ts";
|
||||
|
||||
const CONNECT_TIMEOUT_MS = 5000;
|
||||
const TRUST_KEY_PREFIX = "cubi:trusted:";
|
||||
@@ -23,12 +24,12 @@ export interface ServerAddress {
|
||||
export class HandshakeError extends Error {}
|
||||
|
||||
// what the server field starts as: ?server=host:port, otherwise the server that served the page
|
||||
export function default_server(page = new URL(location.href)): string {
|
||||
export function default_server(page = platform.page): string {
|
||||
return page.searchParams.get("server") ?? page.host;
|
||||
}
|
||||
|
||||
// what a player typed as the server: host:port, or a full http(s) or ws(s) url to pick the scheme
|
||||
export function server_address(input: string, page = new URL(location.href)): ServerAddress {
|
||||
export function server_address(input: string, page = platform.page): ServerAddress {
|
||||
const text = input.trim();
|
||||
let host = text;
|
||||
let secure: boolean;
|
||||
@@ -209,7 +210,7 @@ function mod_versions(welcome: Welcome) {
|
||||
|
||||
export function is_trusted(address: ServerAddress, welcome: Welcome): boolean {
|
||||
try {
|
||||
return localStorage.getItem(trust_key(address)) === mod_versions(welcome);
|
||||
return platform.storage.getItem(trust_key(address)) === mod_versions(welcome);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
@@ -217,7 +218,7 @@ export function is_trusted(address: ServerAddress, welcome: Welcome): boolean {
|
||||
|
||||
export function remember_trust(address: ServerAddress, welcome: Welcome) {
|
||||
try {
|
||||
localStorage.setItem(trust_key(address), mod_versions(welcome));
|
||||
platform.storage.setItem(trust_key(address), mod_versions(welcome));
|
||||
} catch {
|
||||
// private windows and blocked storage just ask again next time
|
||||
}
|
||||
|
||||
+70
-224
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { canvas } from "./renderer/core.ts";
|
||||
import { platform } from "./platform.ts";
|
||||
|
||||
export type KeyCode =
|
||||
// letters
|
||||
@@ -79,16 +79,8 @@ export type KeyCode =
|
||||
| "F11"
|
||||
| "F12";
|
||||
|
||||
// the keys the game keeps in fullscreen, see "fullscreenchange". not every key: with all of them locked, chromium
|
||||
// can keep alt+tab and the windows key from the os too
|
||||
const FULLSCREEN_LOCKED_KEYS = ["Escape", "KeyW"];
|
||||
|
||||
// chromium's keyboard lock api, typescript's dom types don't have it yet
|
||||
interface KeyboardLock {
|
||||
lock(codes?: string[]): Promise<void>;
|
||||
unlock(): void;
|
||||
}
|
||||
|
||||
// what the player presses and how the mouse moves, kept for the frame. where it runs feeds it events: the page's
|
||||
// (browser_input.ts) or the desktop app's window (native/), and grabs the mouse for it (see platform.ts)
|
||||
export class InputManager {
|
||||
static keys_down = new Set<string>();
|
||||
static keys_pressed = new Set<string>();
|
||||
@@ -108,8 +100,6 @@ export class InputManager {
|
||||
// around a screen can never turn it
|
||||
static look_delta_x = 0;
|
||||
static look_delta_y = 0;
|
||||
// chrome sometimes sends a huge movement with the first mouse event after the lock starts
|
||||
static #skip_look_event = false;
|
||||
static wheel_delta = 0;
|
||||
|
||||
// in the order they were typed. a list, since the same letter can be typed twice in one frame
|
||||
@@ -117,147 +107,71 @@ export class InputManager {
|
||||
// letters pressed with ctrl (cmd on macs) held, like "a" for select all
|
||||
static shortcuts: string[] = [];
|
||||
|
||||
static pointer_lock_flag = false;
|
||||
static mouse_grab_timer = 0;
|
||||
static mouse_ungrab_timer = 0;
|
||||
static mouse_ungrab_timeout = -1;
|
||||
static pointer_lock_waiting = false;
|
||||
// the browser let go of the mouse while the game wanted it, like escape or switching windows
|
||||
static #lost_pointer_lock = false;
|
||||
// the canvas had the pointer lock at the last pointerlockchange
|
||||
static #was_locked = false;
|
||||
// the desktop app moving the cursor after the mouse was let go, see center_desktop_mouse. grabbing it again waits
|
||||
// for that, or the move would come while it's locked and turn the camera
|
||||
static #centering = Promise.resolve();
|
||||
static #awaiting_centering = false;
|
||||
// the locked mouse doesn't turn the camera until then, the move can still reach chromium after the app answered,
|
||||
// or the mouse was locked again before chromium said it let go
|
||||
static #ignore_look_until = 0;
|
||||
// what the game last asked for, it can change while grabbing waits
|
||||
static #want_grab = false;
|
||||
|
||||
static initialize(canvas: HTMLCanvasElement) {
|
||||
self.addEventListener("keydown", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!this.keys_down.has(e.code)) {
|
||||
this.keys_pressed.add(e.code);
|
||||
}
|
||||
this.keys_down.add(e.code);
|
||||
if (e.key.length === 1) {
|
||||
if (this.#is_shortcut(e)) {
|
||||
this.shortcuts.push(e.key.toLowerCase());
|
||||
} else {
|
||||
this.typed_characters.push(e.key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// keys let go while the window isn't focused never send keyup, so they'd stay held
|
||||
self.addEventListener("blur", () => {
|
||||
this.keys_down.clear();
|
||||
this.mouse_buttons_down.clear();
|
||||
});
|
||||
|
||||
self.addEventListener("keyup", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.keys_down.delete(e.code);
|
||||
this.keys_released.add(e.code);
|
||||
});
|
||||
|
||||
self.addEventListener("mousedown", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!document.hasFocus() && document.pointerLockElement !== canvas) {
|
||||
this.set_mouse_grabbed(true);
|
||||
return;
|
||||
}
|
||||
if (!this.mouse_buttons_down.has(e.button)) {
|
||||
this.mouse_buttons_pressed.add(e.button);
|
||||
}
|
||||
this.mouse_buttons_down.add(e.button);
|
||||
});
|
||||
|
||||
self.addEventListener("mouseup", (e) => {
|
||||
e.preventDefault();
|
||||
this.mouse_buttons_down.delete(e.button);
|
||||
this.mouse_buttons_released.add(e.button);
|
||||
});
|
||||
|
||||
// ctrl+scroll (and pinching a trackpad, which browsers send as that) would zoom the page. only a listener that
|
||||
// isn't passive can stop it, and on the window they're passive unless told otherwise
|
||||
self.addEventListener("wheel", (e) => {
|
||||
if (e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
}
|
||||
this.wheel_delta += e.deltaY;
|
||||
}, { passive: false });
|
||||
|
||||
document.addEventListener("mousemove", (e) => {
|
||||
e.preventDefault();
|
||||
if (document.pointerLockElement === canvas) {
|
||||
if (this.#skip_look_event) {
|
||||
this.#skip_look_event = false;
|
||||
return;
|
||||
}
|
||||
if (performance.now() < this.#ignore_look_until) return;
|
||||
this.look_delta_x += e.movementX;
|
||||
this.look_delta_y += e.movementY;
|
||||
// code is a KeyCode, key what it types: a character, or a name like "Enter". shortcut is whether ctrl (cmd on
|
||||
// macs) is held for one, then a letter is a shortcut instead of being typed
|
||||
static key_down(code: string, key: string, shortcut: boolean) {
|
||||
if (!this.keys_down.has(code)) {
|
||||
this.keys_pressed.add(code);
|
||||
}
|
||||
this.keys_down.add(code);
|
||||
if (key.length === 1) {
|
||||
if (shortcut) {
|
||||
this.shortcuts.push(key.toLowerCase());
|
||||
} else {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const new_x = e.clientX - rect.left;
|
||||
const new_y = e.clientY - rect.top;
|
||||
|
||||
// not from where it was before the mouse was grabbed, that's -1
|
||||
if (this.mouse_x >= 0 && this.mouse_y >= 0) {
|
||||
this.mouse_delta_x += new_x - this.mouse_x;
|
||||
this.mouse_delta_y += new_y - this.mouse_y;
|
||||
}
|
||||
|
||||
this.mouse_x = new_x;
|
||||
this.mouse_y = new_y;
|
||||
this.typed_characters.push(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("pointerlockchange", () => {
|
||||
const locked = document.pointerLockElement === canvas;
|
||||
if (this.#was_locked && !locked) {
|
||||
this.#ignore_look_until = Infinity;
|
||||
this.#centering = center_desktop_mouse().then(() => {
|
||||
this.#ignore_look_until = performance.now() + CENTERING_SETTLE_MS;
|
||||
});
|
||||
}
|
||||
this.#was_locked = locked;
|
||||
this.#skip_look_event = locked;
|
||||
self.setTimeout(() => {
|
||||
const grab = document.pointerLockElement === canvas;
|
||||
if (!grab) {
|
||||
if (this.pointer_lock_flag) {
|
||||
this.mouse_ungrab_timer = performance.now();
|
||||
this.#lost_pointer_lock = true;
|
||||
}
|
||||
}
|
||||
this.pointer_lock_flag = grab;
|
||||
}, 60);
|
||||
this.pointer_lock_waiting = false;
|
||||
});
|
||||
// for where typing comes apart from keys, the desktop app's window
|
||||
static type_text(text: string) {
|
||||
this.typed_characters.push(...text);
|
||||
}
|
||||
|
||||
// in fullscreen, chromium's keyboard lock gives the game escape (holding it still leaves fullscreen) and ctrl+w,
|
||||
// instead of the browser leaving fullscreen or closing the tab. other browsers don't have it and work as before
|
||||
document.addEventListener("fullscreenchange", () => {
|
||||
const keyboard = (navigator as Navigator & { keyboard?: KeyboardLock }).keyboard;
|
||||
if (!keyboard?.lock) return;
|
||||
if (document.fullscreenElement) {
|
||||
keyboard.lock(FULLSCREEN_LOCKED_KEYS).catch(() => {});
|
||||
} else {
|
||||
keyboard.unlock();
|
||||
}
|
||||
});
|
||||
static key_up(code: string) {
|
||||
this.keys_down.delete(code);
|
||||
this.keys_released.add(code);
|
||||
}
|
||||
|
||||
document.addEventListener("pointerlockerror", () => {
|
||||
this.pointer_lock_waiting = false;
|
||||
});
|
||||
// buttons are numbered like the dom's: 0 left, 1 middle, 2 right
|
||||
static mouse_down(button: number) {
|
||||
if (!this.mouse_buttons_down.has(button)) {
|
||||
this.mouse_buttons_pressed.add(button);
|
||||
}
|
||||
this.mouse_buttons_down.add(button);
|
||||
}
|
||||
|
||||
static mouse_up(button: number) {
|
||||
this.mouse_buttons_down.delete(button);
|
||||
this.mouse_buttons_released.add(button);
|
||||
}
|
||||
|
||||
// the cursor at x y, in the canvas's pixels
|
||||
static move_cursor(x: number, y: number) {
|
||||
// not from where it was before the mouse was grabbed, that's -1
|
||||
if (this.mouse_x >= 0 && this.mouse_y >= 0) {
|
||||
this.mouse_delta_x += x - this.mouse_x;
|
||||
this.mouse_delta_y += y - this.mouse_y;
|
||||
}
|
||||
this.mouse_x = x;
|
||||
this.mouse_y = y;
|
||||
}
|
||||
|
||||
// the grabbed mouse moved
|
||||
static look(x: number, y: number) {
|
||||
this.look_delta_x += x;
|
||||
this.look_delta_y += y;
|
||||
}
|
||||
|
||||
// down is positive, about 100 for a notch of a wheel
|
||||
static scroll(amount: number) {
|
||||
this.wheel_delta += amount;
|
||||
}
|
||||
|
||||
// keys and buttons let go while the game didn't have focus never come up, so they'd stay held
|
||||
static release_all() {
|
||||
this.keys_down.clear();
|
||||
this.mouse_buttons_down.clear();
|
||||
}
|
||||
|
||||
static is_key_down(code: KeyCode): boolean {
|
||||
@@ -306,12 +220,6 @@ export class InputManager {
|
||||
this.mouse_buttons_consumed.add(button);
|
||||
}
|
||||
|
||||
// ctrl (cmd on macs) held for a shortcut. altgr types characters like @ and comes as ctrl+alt on windows, so it
|
||||
// isn't one. getModifierState("AltGraph") isn't used, some linux layouts report it along with plain ctrl
|
||||
static #is_shortcut(e: KeyboardEvent) {
|
||||
return e.metaKey || (e.ctrlKey && !e.altKey);
|
||||
}
|
||||
|
||||
static is_shortcut_pressed(letter: string): boolean {
|
||||
return this.shortcuts.includes(letter);
|
||||
}
|
||||
@@ -337,83 +245,21 @@ export class InputManager {
|
||||
this.mouse_buttons_consumed.clear();
|
||||
}
|
||||
|
||||
static async set_mouse_grabbed(grab: boolean) {
|
||||
this.pointer_lock_flag = grab;
|
||||
this.#want_grab = grab;
|
||||
// a retry to grab it again mustn't happen once it shouldn't be grabbed
|
||||
if (!grab && this.mouse_ungrab_timeout !== -1) {
|
||||
self.clearTimeout(this.mouse_ungrab_timeout);
|
||||
this.mouse_ungrab_timeout = -1;
|
||||
}
|
||||
// already how it should be, the game calls this every frame
|
||||
const locked = document.pointerLockElement === canvas;
|
||||
if (grab ? locked : !locked && !this.pointer_lock_waiting) {
|
||||
return;
|
||||
}
|
||||
if (grab) {
|
||||
// called every frame, once is enough
|
||||
if (this.#awaiting_centering) return;
|
||||
this.#awaiting_centering = true;
|
||||
await this.#centering;
|
||||
this.#awaiting_centering = false;
|
||||
// a gui opened again meanwhile
|
||||
if (!this.#want_grab || document.pointerLockElement === canvas) return;
|
||||
}
|
||||
const t = performance.now();
|
||||
this.mouse_grab_timer = t;
|
||||
if (grab) {
|
||||
this.mouse_x = -1;
|
||||
this.mouse_y = -1;
|
||||
this.pointer_lock_waiting = true;
|
||||
try {
|
||||
await canvas.requestPointerLock();
|
||||
} catch (_) { /* */ }
|
||||
if (this.mouse_ungrab_timeout !== -1) {
|
||||
self.clearTimeout(this.mouse_ungrab_timeout);
|
||||
}
|
||||
this.mouse_ungrab_timeout = -1;
|
||||
if (t - this.mouse_ungrab_timer < 3000) {
|
||||
this.mouse_ungrab_timeout = self.setTimeout(async () => {
|
||||
try {
|
||||
await canvas.requestPointerLock();
|
||||
} catch (_) { /* */ }
|
||||
}, 3100 - (t - this.mouse_ungrab_timer));
|
||||
}
|
||||
} else {
|
||||
if (!this.pointer_lock_waiting) {
|
||||
document.exitPointerLock();
|
||||
}
|
||||
}
|
||||
// the game calls this every frame
|
||||
static set_mouse_grabbed(grab: boolean) {
|
||||
platform.set_mouse_grabbed(grab);
|
||||
}
|
||||
|
||||
// whether the mouse was taken away since the last call, browsers eat the escape that does it
|
||||
// whether the mouse was taken away since the last call, like browsers do with escape
|
||||
static take_lost_pointer_lock() {
|
||||
const lost = this.#lost_pointer_lock;
|
||||
this.#lost_pointer_lock = false;
|
||||
return lost;
|
||||
return platform.take_lost_mouse();
|
||||
}
|
||||
|
||||
static is_mouse_grabbed() {
|
||||
return document.hasFocus() && document.pointerLockElement === canvas;
|
||||
return platform.is_mouse_grabbed();
|
||||
}
|
||||
|
||||
static toggle_fullscreen() {
|
||||
if (!document.fullscreenElement) {
|
||||
canvas.requestFullscreen();
|
||||
} else {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
platform.toggle_fullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
const CENTERING_TIMEOUT_MS = 250;
|
||||
const CENTERING_SETTLE_MS = 100;
|
||||
|
||||
// the desktop app (the page has ?singleplayer there, see desktop/main.ts) moves the cursor to the middle of the
|
||||
// window when the mouse is let go to open a gui, like minecraft. chromium would put it back where it was grabbed.
|
||||
// resolves once the cursor was moved, or after CENTERING_TIMEOUT_MS if the app is slow, so grabbing isn't held up
|
||||
function center_desktop_mouse(): Promise<void> {
|
||||
if (!new URL(location.href).searchParams.has("singleplayer")) return Promise.resolve();
|
||||
const moved = fetch("/desktop/center_mouse", { method: "POST" }).then(() => {}, () => {});
|
||||
return Promise.race([moved, new Promise<void>((resolve) => self.setTimeout(resolve, CENTERING_TIMEOUT_MS))]);
|
||||
}
|
||||
|
||||
+14
-249
@@ -1,224 +1,17 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { AssetManager } from "./assets.ts";
|
||||
import { Client } from "./client.ts";
|
||||
import { InputManager } from "./input_manager.ts";
|
||||
import { Connection } from "./network.ts";
|
||||
import { Options } from "./options.ts";
|
||||
import { connect, HandshakeError, is_trusted, join, remember_trust, ServerAddress } from "./handshake.ts";
|
||||
import { build_atlas, engine_textures } from "./atlas.ts";
|
||||
import { confirm_mods } from "./confirm_mods.ts";
|
||||
import { set_texture_animations } from "./texture_animations.ts";
|
||||
import type { TextureJson } from "@/common/texture_animation.ts";
|
||||
import { ModLoadError } from "@/common/mod_loader.ts";
|
||||
import {
|
||||
begin_drawing,
|
||||
canvas,
|
||||
clear_background,
|
||||
device,
|
||||
end_drawing,
|
||||
init_font,
|
||||
init_window,
|
||||
load_texture,
|
||||
render_debug,
|
||||
resize_canvas,
|
||||
} from "./renderer/mod.ts";
|
||||
import { is_stopped, show_fatal_error } from "./fatal.ts";
|
||||
import { download_mods, load_client_mods, set_mods_client } from "./mods.ts";
|
||||
import type { GuiScreen } from "./gui/gui_screen.ts";
|
||||
import { in_desktop_app, type JoinServer, TitleScreen } from "./gui/title_screen.ts";
|
||||
import { MainMenuScreen } from "./gui/main_menu.ts";
|
||||
import { DisconnectedScreen } from "./gui/disconnected_screen.ts";
|
||||
import { profiler } from "./profiler.ts";
|
||||
// the client in a browser page, drawing on index.html's canvas. the desktop app's starts at native/main.ts
|
||||
import { set_platform } from "./platform.ts";
|
||||
import { browser_platform } from "./browser_platform.ts";
|
||||
import { listen_to_page } from "./browser_input.ts";
|
||||
import { init_window, resize_canvas } from "./renderer/mod.ts";
|
||||
import { show_fatal_error } from "./fatal.ts";
|
||||
import { sounds } from "./sounds.ts";
|
||||
import { WebAudioOutput } from "./audio_output.ts";
|
||||
import { start_client } from "./client_loop.ts";
|
||||
|
||||
// runs whatever is showing every frame: a menu screen before joining (and after leaving), or the game
|
||||
export // while playing, the browser asks before leaving the page. sprinting is ctrl and walking is w, and ctrl+w closes the
|
||||
// tab without the page getting a say. in fullscreen the keyboard lock catches it instead (see input_manager.ts)
|
||||
function confirm_leaving(confirm: boolean) {
|
||||
self.onbeforeunload = confirm ? (event) => event.preventDefault() : null;
|
||||
}
|
||||
|
||||
// with render_debug.uncapped, the most frames between two of the display's refreshes. it's the highest fps that shows,
|
||||
// 960 on a 60 hz display, and what the gpu can be behind by
|
||||
const UNCAPPED_FRAMES_PER_REFRESH = 16;
|
||||
|
||||
class ClientLoop {
|
||||
running = false;
|
||||
last_time = 0;
|
||||
client: Client | undefined;
|
||||
screen: GuiScreen | undefined;
|
||||
|
||||
frame_count = 0;
|
||||
last_fps_time = 0;
|
||||
|
||||
start() {
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (!document.hidden) {
|
||||
this.last_time = performance.now();
|
||||
}
|
||||
});
|
||||
|
||||
this.#next_task.port1.onmessage = () => this.loop(performance.now());
|
||||
this.running = true;
|
||||
const now = performance.now();
|
||||
this.last_time = now;
|
||||
this.frame_count = 0;
|
||||
this.last_fps_time = this.last_time;
|
||||
requestAnimationFrame((time) => this.loop(time));
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
show_screen(screen: GuiScreen) {
|
||||
this.screen?.on_close();
|
||||
this.client = undefined;
|
||||
confirm_leaving(false);
|
||||
this.screen = screen;
|
||||
InputManager.set_mouse_grabbed(false);
|
||||
}
|
||||
|
||||
play(connection: Connection) {
|
||||
const client = new Client(connection, (message) => this.show_screen(new DisconnectedScreen(message)));
|
||||
set_mods_client(client);
|
||||
client.chat.add("Connected to the server");
|
||||
this.screen?.on_close();
|
||||
this.screen = undefined;
|
||||
this.client = client;
|
||||
confirm_leaving(true);
|
||||
console.log("Game started");
|
||||
}
|
||||
|
||||
// with render_debug.uncapped: frames since the display last refreshed, and whether the next one waits for it
|
||||
#frames_this_refresh = 0;
|
||||
#waiting_for_refresh = false;
|
||||
#refresh_requested = false;
|
||||
#next_task = new MessageChannel();
|
||||
|
||||
// with the display's refresh, or with render_debug.uncapped right away, so frames aren't held to vsync and show what
|
||||
// they cost. up to UNCAPPED_FRAMES_PER_REFRESH, then it waits for the next refresh, which the browser holds back
|
||||
// while the gpu is behind, so frames the gpu can't keep up with don't pile up. the browser saying a frame is done
|
||||
// can't be waited on instead, firefox only says so every 100 ms when nothing else is sent to the gpu
|
||||
#next_frame() {
|
||||
if (!render_debug.uncapped) {
|
||||
requestAnimationFrame((time) => this.loop(time));
|
||||
return;
|
||||
}
|
||||
if (!this.#refresh_requested) {
|
||||
this.#refresh_requested = true;
|
||||
requestAnimationFrame(() => {
|
||||
this.#refresh_requested = false;
|
||||
this.#frames_this_refresh = 0;
|
||||
if (this.#waiting_for_refresh) {
|
||||
this.#waiting_for_refresh = false;
|
||||
this.loop(performance.now());
|
||||
}
|
||||
});
|
||||
}
|
||||
this.#frames_this_refresh += 1;
|
||||
if (this.#frames_this_refresh < UNCAPPED_FRAMES_PER_REFRESH) {
|
||||
// a task of its own, so input and the workers' messages get handled in between
|
||||
this.#next_task.port2.postMessage(null);
|
||||
} else {
|
||||
this.#waiting_for_refresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
loop(time: number) {
|
||||
if (!this.running || is_stopped()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const delta = (time - this.last_time) / 1000;
|
||||
|
||||
profiler.begin_frame();
|
||||
profiler.section("begin frame", begin_drawing);
|
||||
clear_background(0.69, 0.8, 1, 1.0);
|
||||
if (this.client) {
|
||||
this.client.run_frame(delta);
|
||||
} else if (this.screen) {
|
||||
this.screen.on_tick(delta);
|
||||
this.screen.on_render();
|
||||
}
|
||||
profiler.section("submit", end_drawing);
|
||||
profiler.end_frame();
|
||||
|
||||
this.frame_count += 1;
|
||||
const now = performance.now();
|
||||
if (now - this.last_fps_time >= 1000) {
|
||||
const fps = (this.frame_count * 1000) / (now - this.last_fps_time);
|
||||
console.log(`FPS: ${fps.toFixed(2)}`);
|
||||
this.frame_count = 0;
|
||||
this.last_fps_time = now;
|
||||
}
|
||||
|
||||
InputManager.update();
|
||||
|
||||
this.last_time = time;
|
||||
this.#next_frame();
|
||||
}
|
||||
}
|
||||
|
||||
// a server's blocks, items and scripts can't be taken back out once loaded, so a failure after that point
|
||||
// can't go back to the title screen to try again, the page has to start over
|
||||
class FailedAfterLoadingMods extends Error {}
|
||||
|
||||
// the game only runs against a server, it owns the world and everything in it. see docs/modding/networking/index.md
|
||||
async function join_server(address: ServerAddress, name: string, status: (text: string) => void): Promise<Connection> {
|
||||
const { socket, welcome } = await connect(address, name);
|
||||
console.log(`Connected to ${address.ws_url}`);
|
||||
|
||||
let loaded_mods = false;
|
||||
try {
|
||||
if (address.cross_origin && !is_trusted(address, welcome)) {
|
||||
status("Waiting for you to accept the server's mods...");
|
||||
if (!await confirm_mods(address, welcome)) {
|
||||
throw new HandshakeError(`You didn't join ${address.base.host}`);
|
||||
}
|
||||
remember_trust(address, welcome);
|
||||
}
|
||||
|
||||
// textures, blocks and items all come from the server's mods, so this happens before anything else
|
||||
status("Downloading the server's mods...");
|
||||
const mods = await download_mods(welcome.mods, address.base);
|
||||
const textures = await engine_textures();
|
||||
const texture_json = new Map<string, TextureJson>();
|
||||
for (const mod of mods) {
|
||||
for (const [id, png] of mod.textures) textures.set(id, png);
|
||||
for (const [id, json] of mod.texture_json ?? []) texture_json.set(id, json);
|
||||
}
|
||||
const atlas = await build_atlas(textures, texture_json);
|
||||
loaded_mods = true;
|
||||
const atlas_texture = load_texture(atlas.image);
|
||||
set_texture_animations(atlas_texture.tex, device.queue, atlas.animated);
|
||||
AssetManager.instance.assets["cubi:textures"] = atlas_texture;
|
||||
AssetManager.instance.assets["cubi:textures_info"] = atlas.regions;
|
||||
await load_client_mods(welcome.mods, mods);
|
||||
console.log(`Mods: ${welcome.mods.map((mod) => `${mod.id} ${mod.version}`).join(", ") || "none"}`);
|
||||
|
||||
status("Joining...");
|
||||
const joined = await join(socket, new Options().render_distance);
|
||||
return new Connection(socket, welcome, joined);
|
||||
} catch (e) {
|
||||
socket.close();
|
||||
const message = error_message(e);
|
||||
throw loaded_mods ? new FailedAfterLoadingMods(message) : new HandshakeError(message);
|
||||
}
|
||||
}
|
||||
|
||||
function error_message(e: unknown) {
|
||||
if (e instanceof HandshakeError) {
|
||||
return e.message;
|
||||
}
|
||||
if (e instanceof ModLoadError) {
|
||||
return `Couldn't load the server's mods: ${e.message}`;
|
||||
}
|
||||
return `Something went wrong joining the server: ${e instanceof Error ? e.message : e}`;
|
||||
}
|
||||
set_platform(browser_platform);
|
||||
|
||||
const game_canvas = document.getElementById("game") as HTMLCanvasElement;
|
||||
if (!game_canvas) {
|
||||
@@ -232,40 +25,12 @@ try {
|
||||
throw e;
|
||||
}
|
||||
|
||||
InputManager.initialize(game_canvas);
|
||||
listen_to_page(game_canvas);
|
||||
// waits for the first click or key, which the title screen gets
|
||||
sounds.set_output(new WebAudioOutput());
|
||||
self.addEventListener("resize", resize_canvas);
|
||||
resize_canvas();
|
||||
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
|
||||
const fit_page = () => resize_canvas(self.innerWidth, self.innerHeight);
|
||||
self.addEventListener("resize", fit_page);
|
||||
fit_page();
|
||||
game_canvas.addEventListener("contextmenu", (event) => event.preventDefault());
|
||||
|
||||
AssetManager.instance.load("cubi:assets_text", "/assets/ASSETS.md");
|
||||
|
||||
AssetManager.instance.load("cubi:skin", "/assets/sprites/skin_template.png");
|
||||
AssetManager.instance.load("cubi:gui", "/assets/sprites/gui.png");
|
||||
|
||||
AssetManager.instance.load("cubi:m6x11", "/assets/fonts/m6x11.png");
|
||||
AssetManager.instance.load("cubi:m6x11_fnt", "/assets/fonts/m6x11.fnt");
|
||||
|
||||
await AssetManager.instance.load_all();
|
||||
|
||||
init_font();
|
||||
|
||||
const loop = new ClientLoop();
|
||||
const join_game: JoinServer = async (address, name, status) => {
|
||||
let connection: Connection;
|
||||
try {
|
||||
connection = await join_server(address, name, status);
|
||||
} catch (e) {
|
||||
if (e instanceof FailedAfterLoadingMods) {
|
||||
loop.show_screen(new DisconnectedScreen(e.message));
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
loop.play(connection);
|
||||
};
|
||||
loop.show_screen(
|
||||
in_desktop_app() ? new MainMenuScreen((screen) => loop.show_screen(screen), join_game) : new TitleScreen(join_game),
|
||||
);
|
||||
loop.start();
|
||||
await start_client();
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { canvas, draw_rect, draw_text, measure_text } from "../renderer/mod.ts";
|
||||
import { GuiScreen } from "../gui/gui_screen.ts";
|
||||
import { credit_sections } from "../gui/credits_screen.ts";
|
||||
import { Button, ListBox, TEXT_SCALE, wrap_text } from "../gui/widgets.ts";
|
||||
|
||||
const MAX_WIDTH = 1200;
|
||||
const MARGIN = 32;
|
||||
const TOP = 90;
|
||||
const BUTTON_WIDTH = 200;
|
||||
const BUTTON_HEIGHT = 48;
|
||||
// the list's own padding around its text
|
||||
const TEXT_PADDING = 24;
|
||||
|
||||
// the credits in the desktop app, drawn in the window with the markdown as it's written, since there's no browser to
|
||||
// show it as a page. after them, the credits of the libraries the app comes with (see desktop/libraries.ts)
|
||||
export class TextCreditsScreen extends GuiScreen {
|
||||
#list = new ListBox(0, 0, () => {});
|
||||
#back: Button;
|
||||
#sections: { heading: string; text: string }[];
|
||||
// what the lines were wrapped for
|
||||
#wrapped_width = 0;
|
||||
|
||||
constructor(on_back: () => void, libraries: string | undefined) {
|
||||
super();
|
||||
this.#back = new Button("Back", BUTTON_WIDTH, BUTTON_HEIGHT, on_back);
|
||||
this.#sections = [...credit_sections(), ...(libraries ? [{ heading: "Libraries", text: libraries }] : [])];
|
||||
}
|
||||
|
||||
on_tick(_delta: number): void {
|
||||
const list = this.#list;
|
||||
list.width = Math.min(MAX_WIDTH, canvas.width - MARGIN * 2);
|
||||
list.height = Math.max(BUTTON_HEIGHT, canvas.height - TOP - BUTTON_HEIGHT - MARGIN * 2);
|
||||
list.x = (canvas.width - list.width) / 2;
|
||||
list.y = TOP;
|
||||
if (list.width !== this.#wrapped_width) {
|
||||
this.#wrapped_width = list.width;
|
||||
list.rows = credit_lines(this.#sections, list.width - TEXT_PADDING).map((text) => ({ text }));
|
||||
}
|
||||
this.#back.x = (canvas.width - BUTTON_WIDTH) / 2;
|
||||
this.#back.y = list.y + list.height + MARGIN;
|
||||
list.handle_input();
|
||||
this.#back.handle_input();
|
||||
}
|
||||
|
||||
on_render(): void {
|
||||
draw_rect(0, 0, canvas.width, canvas.height, [0, 0, 0, 0.6]);
|
||||
const scale = TEXT_SCALE * 2;
|
||||
draw_text("Credits", (canvas.width - measure_text("Credits", scale)) / 2, TOP / 2 - 12, scale);
|
||||
this.#list.render();
|
||||
this.#back.render();
|
||||
}
|
||||
|
||||
on_close(): void {}
|
||||
}
|
||||
|
||||
// every section's heading and text, wrapped at spaces to width pixels
|
||||
function credit_lines(sections: { heading: string; text: string }[], width: number): string[] {
|
||||
return sections.flatMap(({ heading, text }) => [heading, "", ...wrap_text(text, width), ""]);
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the desktop app's client: a deno worker drawing into the app's window with webgpu, see desktop/main.ts. the
|
||||
// window sends what the player does (messages.ts), and does what needs the os, like grabbing the mouse. the browser's
|
||||
// client starts at ../main.ts
|
||||
import { type Platform, set_platform } from "../platform.ts";
|
||||
import { InputManager } from "../input_manager.ts";
|
||||
import { init_window, resize_canvas } from "../renderer/mod.ts";
|
||||
import { show_fatal_error } from "../fatal.ts";
|
||||
import { start_client } from "../client_loop.ts";
|
||||
import { TextCreditsScreen } from "./credits_screen.ts";
|
||||
import { install_web_audio, sources_ended } from "./web_audio.ts";
|
||||
import { sounds } from "../sounds.ts";
|
||||
import { WebAudioOutput } from "../audio_output.ts";
|
||||
import type { ClientMessage, WindowMessage } from "./messages.ts";
|
||||
|
||||
const post = (message: ClientMessage) => self.postMessage(message);
|
||||
|
||||
// what the game asked for, the window does it
|
||||
let grabbed = false;
|
||||
let focused = true;
|
||||
// the window let go of the mouse while the game had it, see Platform.take_lost_mouse
|
||||
let lost_mouse = false;
|
||||
|
||||
// frames are each a task of their own, so input, the network and the workers' messages get handled in between.
|
||||
// waiting for the display's refresh happens while drawing, the window's surface holds back frames the display can't
|
||||
// show yet. a timer, not a MessageChannel like the browser's: deno handles a channel's messages before timers,
|
||||
// fetches and the gpu's callbacks, so frames one after another through one would hold those back
|
||||
let shown = true;
|
||||
let next_frame: ((time: number) => void) | undefined;
|
||||
let frame_waiting = false;
|
||||
const shown_listeners = new Set<() => void>();
|
||||
|
||||
function run_frame() {
|
||||
frame_waiting = false;
|
||||
const frame = next_frame;
|
||||
next_frame = undefined;
|
||||
frame?.(performance.now());
|
||||
}
|
||||
|
||||
function request_frame(frame: (time: number) => void) {
|
||||
next_frame = frame;
|
||||
// a hidden window gets no frames, drawing to it could wait until it's shown again
|
||||
if (shown) wait_for_frame();
|
||||
}
|
||||
|
||||
function wait_for_frame() {
|
||||
if (frame_waiting) return;
|
||||
frame_waiting = true;
|
||||
setTimeout(run_frame, 0);
|
||||
}
|
||||
|
||||
function set_shown(now_shown: boolean) {
|
||||
if (shown === now_shown) return;
|
||||
shown = now_shown;
|
||||
if (!shown) return;
|
||||
for (const listener of shown_listeners) listener();
|
||||
if (next_frame) wait_for_frame();
|
||||
}
|
||||
|
||||
// what was asked of the window, by id, waiting for its answer
|
||||
let next_id = 0;
|
||||
const asking = new Map<number, (answer: string) => void>();
|
||||
|
||||
function ask(question: (id: number) => ClientMessage): Promise<string> {
|
||||
const id = next_id++;
|
||||
post(question(id));
|
||||
return new Promise((resolve) => asking.set(id, resolve));
|
||||
}
|
||||
|
||||
function native_platform(page: URL, stored: Record<string, string>, credits: string | undefined): Platform {
|
||||
const storage = new Map(Object.entries(stored));
|
||||
return {
|
||||
page,
|
||||
restart(url) {
|
||||
post({ type: "restart", page: url.href });
|
||||
},
|
||||
request_frame,
|
||||
on_shown(listener) {
|
||||
shown_listeners.add(listener);
|
||||
return () => shown_listeners.delete(listener);
|
||||
},
|
||||
// kept by the window, which saves it with the app's data
|
||||
storage: {
|
||||
getItem: (key) => storage.get(key) ?? null,
|
||||
setItem(key, value) {
|
||||
storage.set(key, value);
|
||||
post({ type: "store", key, value });
|
||||
},
|
||||
},
|
||||
// the window saves the world when it closes
|
||||
confirm_leaving() {},
|
||||
show_fatal_error(message) {
|
||||
post({ type: "fatal", message });
|
||||
},
|
||||
credits_screen: (on_back) => new TextCreditsScreen(on_back, credits),
|
||||
read_clipboard: () => ask((id) => ({ type: "read_clipboard", id })),
|
||||
write_clipboard(text) {
|
||||
post({ type: "write_clipboard", text });
|
||||
return Promise.resolve();
|
||||
},
|
||||
set_mouse_grabbed(grab) {
|
||||
if (grab === grabbed) return;
|
||||
grabbed = grab;
|
||||
// it's no longer where it was, see InputManager.move_cursor
|
||||
if (grab) {
|
||||
InputManager.mouse_x = -1;
|
||||
InputManager.mouse_y = -1;
|
||||
}
|
||||
post({ type: "grab", grab });
|
||||
},
|
||||
is_mouse_grabbed: () => grabbed && focused,
|
||||
take_lost_mouse() {
|
||||
const lost = lost_mouse;
|
||||
lost_mouse = false;
|
||||
return lost;
|
||||
},
|
||||
toggle_fullscreen() {
|
||||
post({ type: "fullscreen" });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function start(message: Extract<WindowMessage, { type: "start" }>) {
|
||||
set_platform(native_platform(new URL(message.page), message.storage, message.credits));
|
||||
const { surface: handles, width, height } = message;
|
||||
const surface = new Deno.UnsafeWindowSurface({
|
||||
system: handles.system,
|
||||
windowHandle: Deno.UnsafePointer.create(handles.window),
|
||||
displayHandle: Deno.UnsafePointer.create(handles.display),
|
||||
width,
|
||||
height,
|
||||
});
|
||||
// pointers to the window were all that needed ffi. mods run in here too, they don't get it
|
||||
await Deno.permissions.revoke({ name: "ffi" });
|
||||
try {
|
||||
await init_window(surface);
|
||||
} catch (e) {
|
||||
show_fatal_error(e instanceof Error ? e.message : String(e));
|
||||
throw e;
|
||||
}
|
||||
resize_canvas(width, height);
|
||||
if (message.audio) {
|
||||
install_web_audio((commands) => post({ type: "audio", commands }));
|
||||
sounds.set_output(new WebAudioOutput(false));
|
||||
}
|
||||
await start_client();
|
||||
}
|
||||
|
||||
self.onmessage = (event: MessageEvent<WindowMessage>) => {
|
||||
const message = event.data;
|
||||
switch (message.type) {
|
||||
case "start":
|
||||
start(message);
|
||||
break;
|
||||
case "resize":
|
||||
resize_canvas(message.width, message.height);
|
||||
break;
|
||||
case "key":
|
||||
if (message.down) InputManager.key_down(message.code, message.key, message.shortcut);
|
||||
else InputManager.key_up(message.code);
|
||||
break;
|
||||
case "text":
|
||||
InputManager.type_text(message.text);
|
||||
break;
|
||||
case "button":
|
||||
if (message.down) InputManager.mouse_down(message.button);
|
||||
else InputManager.mouse_up(message.button);
|
||||
break;
|
||||
case "cursor":
|
||||
InputManager.move_cursor(message.x, message.y);
|
||||
break;
|
||||
case "look":
|
||||
if (grabbed) InputManager.look(message.x, message.y);
|
||||
break;
|
||||
case "scroll":
|
||||
InputManager.scroll(message.amount);
|
||||
break;
|
||||
case "focus":
|
||||
focused = message.focused;
|
||||
if (focused) break;
|
||||
InputManager.release_all();
|
||||
// the window let go of it, the game asks again once it wants it
|
||||
if (grabbed) {
|
||||
lost_mouse = true;
|
||||
grabbed = false;
|
||||
post({ type: "grab", grab: false });
|
||||
}
|
||||
break;
|
||||
case "shown":
|
||||
set_shown(message.shown);
|
||||
break;
|
||||
case "clipboard":
|
||||
asking.get(message.id)?.(message.text);
|
||||
asking.delete(message.id);
|
||||
break;
|
||||
case "audio_ended":
|
||||
sources_ended(message.sources);
|
||||
break;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,86 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// what the desktop app's window (desktop/main.ts, on deno's main thread) and the client running in a worker (see
|
||||
// main.ts here) tell each other. the window has the os's events and the client draws into it
|
||||
|
||||
// the window's surface, for deno's UnsafeWindowSurface. handles are pointers' addresses, pointers can't be posted
|
||||
export interface SurfaceHandles {
|
||||
system: "cocoa" | "win32" | "x11" | "wayland";
|
||||
window: bigint;
|
||||
display: bigint;
|
||||
}
|
||||
|
||||
export type WindowMessage =
|
||||
| {
|
||||
type: "start";
|
||||
page: string;
|
||||
surface: SurfaceHandles;
|
||||
width: number;
|
||||
height: number;
|
||||
// what the client saved, see Platform.storage
|
||||
storage: Record<string, string>;
|
||||
// whether the window can play sound, see desktop/openal.ts
|
||||
audio: boolean;
|
||||
// the credits of the libraries the app comes with, see desktop/libraries.ts. an app older than its client
|
||||
// (updated from the site) doesn't send them
|
||||
credits?: string;
|
||||
}
|
||||
// in pixels, what's drawn to is this big now
|
||||
| { type: "resize"; width: number; height: number }
|
||||
// code like a KeyboardEvent's, key the letter for a shortcut (see InputManager.key_down), "" otherwise
|
||||
| { type: "key"; down: boolean; code: string; key: string; shortcut: boolean }
|
||||
| { type: "text"; text: string }
|
||||
// buttons numbered like the dom's
|
||||
| { type: "button"; down: boolean; button: number }
|
||||
// the cursor, in pixels from the window's top left
|
||||
| { type: "cursor"; x: number; y: number }
|
||||
// the grabbed mouse moved
|
||||
| { type: "look"; x: number; y: number }
|
||||
// down is positive, about 100 for a notch, like the dom's
|
||||
| { type: "scroll"; amount: number }
|
||||
// the window lost or got focus, losing it lets go of the mouse
|
||||
| { type: "focus"; focused: boolean }
|
||||
// whether the window can be seen
|
||||
| { type: "shown"; shown: boolean }
|
||||
// the answer to read_clipboard, by the id it was asked with
|
||||
| { type: "clipboard"; id: number; text: string }
|
||||
// sources that played to their end, see web_audio.ts
|
||||
| { type: "audio_ended"; sources: number[] };
|
||||
|
||||
export type ClientMessage =
|
||||
| { type: "grab"; grab: boolean }
|
||||
| { type: "fullscreen" }
|
||||
// start the client over at page, see Platform.restart
|
||||
| { type: "restart"; page: string }
|
||||
| { type: "fatal"; message: string }
|
||||
| { type: "read_clipboard"; id: number }
|
||||
| { type: "write_clipboard"; text: string }
|
||||
| { type: "store"; key: string; value: string }
|
||||
| { type: "audio"; commands: AudioCommand[] };
|
||||
|
||||
// how a playing source sounds: everything between it and the speakers worked out, see web_audio.ts. gain 0 is silent
|
||||
export interface SourceSettings {
|
||||
gain: number;
|
||||
pitch: number;
|
||||
// where it is, with its distance falloff: full gain within ref_distance, fading linearly to 1 - rolloff at
|
||||
// max_distance. undefined plays it as it is, not from anywhere
|
||||
at: [number, number, number] | undefined;
|
||||
ref_distance: number;
|
||||
max_distance: number;
|
||||
rolloff: number;
|
||||
}
|
||||
|
||||
// what the client's web audio has the window's openal do. ids are the client's own
|
||||
export type AudioCommand =
|
||||
// a decoded file, one array of samples a channel
|
||||
| { op: "buffer"; id: number; channels: Float32Array[]; sample_rate: number }
|
||||
| { op: "play"; id: number; buffer: number; loop: boolean; offset: number; settings: SourceSettings }
|
||||
| { op: "set"; id: number; settings: SourceSettings }
|
||||
| { op: "stop"; id: number }
|
||||
| {
|
||||
op: "listener";
|
||||
position: [number, number, number];
|
||||
forward: [number, number, number];
|
||||
up: [number, number, number];
|
||||
};
|
||||
@@ -0,0 +1,360 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the web audio api for the desktop app's client, which runs in deno with no audio of its own. only what
|
||||
// client/audio_output.ts uses: buffer sources, gains and panners connected in a chain to the destination, the
|
||||
// listener, and decoding the ogg files mods' sounds are (vorbis or opus). the window plays it with openal
|
||||
// (desktop/openal.ts): each playing source is one openal source, its chain worked out into one gain, pitch and place
|
||||
// at the end of every task something changed in. panners are all hrtf with linear distance, like cubi makes them
|
||||
import decode_vorbis from "@audio/decode-vorbis";
|
||||
import decode_opus from "@audio/decode-opus";
|
||||
import type { AudioCommand, SourceSettings } from "./messages.ts";
|
||||
|
||||
type Vector = [number, number, number];
|
||||
|
||||
// sends what changed to the window
|
||||
let send: (commands: AudioCommand[]) => void = () => {};
|
||||
let next_id = 0;
|
||||
// what's been started and hasn't ended, by id
|
||||
const playing = new Map<number, BufferSource>();
|
||||
|
||||
class Param {
|
||||
#value: number;
|
||||
#context: Context;
|
||||
|
||||
constructor(context: Context, value: number) {
|
||||
this.#context = context;
|
||||
this.#value = value;
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this.#value;
|
||||
}
|
||||
|
||||
set value(value: number) {
|
||||
this.#value = value;
|
||||
this.#context.changed();
|
||||
}
|
||||
}
|
||||
|
||||
class Node {
|
||||
readonly context: Context;
|
||||
// where it plays into, cubi connects each node to one other
|
||||
output: Node | undefined;
|
||||
|
||||
constructor(context: Context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
connect<T extends Node>(destination: T): T {
|
||||
this.output = destination;
|
||||
this.context.changed();
|
||||
return destination;
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.output = undefined;
|
||||
this.context.changed();
|
||||
}
|
||||
}
|
||||
|
||||
class Destination extends Node {}
|
||||
|
||||
class Gain extends Node {
|
||||
readonly gain: Param;
|
||||
|
||||
constructor(context: Context, options: { gain?: number } = {}) {
|
||||
super(context);
|
||||
this.gain = new Param(context, options.gain ?? 1);
|
||||
}
|
||||
}
|
||||
|
||||
interface PannerOptions {
|
||||
panningModel?: string;
|
||||
distanceModel?: string;
|
||||
refDistance?: number;
|
||||
maxDistance?: number;
|
||||
rolloffFactor?: number;
|
||||
positionX?: number;
|
||||
positionY?: number;
|
||||
positionZ?: number;
|
||||
}
|
||||
|
||||
class Panner extends Node {
|
||||
readonly positionX: Param;
|
||||
readonly positionY: Param;
|
||||
readonly positionZ: Param;
|
||||
// openal plays every panner like this, whatever it's set to
|
||||
panningModel = "HRTF";
|
||||
distanceModel = "linear";
|
||||
#ref_distance: number;
|
||||
#max_distance: number;
|
||||
#rolloff: number;
|
||||
|
||||
constructor(context: Context, options: PannerOptions = {}) {
|
||||
super(context);
|
||||
this.positionX = new Param(context, options.positionX ?? 0);
|
||||
this.positionY = new Param(context, options.positionY ?? 0);
|
||||
this.positionZ = new Param(context, options.positionZ ?? 0);
|
||||
this.#ref_distance = options.refDistance ?? 1;
|
||||
this.#max_distance = options.maxDistance ?? 10000;
|
||||
this.#rolloff = options.rolloffFactor ?? 1;
|
||||
}
|
||||
|
||||
get refDistance() {
|
||||
return this.#ref_distance;
|
||||
}
|
||||
set refDistance(value: number) {
|
||||
this.#ref_distance = value;
|
||||
this.context.changed();
|
||||
}
|
||||
|
||||
get maxDistance() {
|
||||
return this.#max_distance;
|
||||
}
|
||||
set maxDistance(value: number) {
|
||||
this.#max_distance = value;
|
||||
this.context.changed();
|
||||
}
|
||||
|
||||
get rolloffFactor() {
|
||||
return this.#rolloff;
|
||||
}
|
||||
set rolloffFactor(value: number) {
|
||||
this.#rolloff = value;
|
||||
this.context.changed();
|
||||
}
|
||||
}
|
||||
|
||||
class Buffer {
|
||||
readonly sampleRate: number;
|
||||
readonly length: number;
|
||||
readonly numberOfChannels: number;
|
||||
#channels: Float32Array[];
|
||||
// once the window has it, see BufferSource.start
|
||||
id: number | undefined;
|
||||
|
||||
constructor(channels: Float32Array[], sample_rate: number) {
|
||||
this.#channels = channels;
|
||||
this.sampleRate = sample_rate;
|
||||
this.length = channels[0]?.length ?? 0;
|
||||
this.numberOfChannels = channels.length;
|
||||
}
|
||||
|
||||
get duration() {
|
||||
return this.length / this.sampleRate;
|
||||
}
|
||||
|
||||
getChannelData(channel: number) {
|
||||
return this.#channels[channel];
|
||||
}
|
||||
}
|
||||
|
||||
class BufferSource extends Node {
|
||||
readonly id = next_id++;
|
||||
buffer: Buffer | null;
|
||||
loop: boolean;
|
||||
readonly playbackRate: Param;
|
||||
onended: (() => void) | null = null;
|
||||
// seconds into the buffer it starts at
|
||||
offset = 0;
|
||||
// what the window was last told, undefined before it was told to play it
|
||||
sent: SourceSettings | undefined;
|
||||
#started = false;
|
||||
|
||||
constructor(context: Context, options: { buffer?: Buffer; loop?: boolean; playbackRate?: number } = {}) {
|
||||
super(context);
|
||||
this.buffer = options.buffer ?? null;
|
||||
this.loop = options.loop ?? false;
|
||||
this.playbackRate = new Param(context, options.playbackRate ?? 1);
|
||||
}
|
||||
|
||||
// it's always now, cubi starts sources as it makes them
|
||||
start(_when = 0, offset = 0) {
|
||||
if (this.#started) throw new Error("A source can only be started once");
|
||||
this.#started = true;
|
||||
this.offset = offset;
|
||||
playing.set(this.id, this);
|
||||
this.context.changed();
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (!playing.has(this.id)) return;
|
||||
if (this.sent) this.context.queue({ op: "stop", id: this.id });
|
||||
this.end();
|
||||
}
|
||||
|
||||
end() {
|
||||
playing.delete(this.id);
|
||||
queueMicrotask(() => this.onended?.());
|
||||
}
|
||||
}
|
||||
|
||||
class Listener {
|
||||
readonly positionX: Param;
|
||||
readonly positionY: Param;
|
||||
readonly positionZ: Param;
|
||||
readonly forwardX: Param;
|
||||
readonly forwardY: Param;
|
||||
readonly forwardZ: Param;
|
||||
readonly upX: Param;
|
||||
readonly upY: Param;
|
||||
readonly upZ: Param;
|
||||
|
||||
constructor(context: Context) {
|
||||
const param = (value: number) => new Param(context, value);
|
||||
[this.positionX, this.positionY, this.positionZ] = [param(0), param(0), param(0)];
|
||||
[this.forwardX, this.forwardY, this.forwardZ] = [param(0), param(0), param(-1)];
|
||||
[this.upX, this.upY, this.upZ] = [param(0), param(1), param(0)];
|
||||
}
|
||||
|
||||
setPosition(x: number, y: number, z: number) {
|
||||
[this.positionX.value, this.positionY.value, this.positionZ.value] = [x, y, z];
|
||||
}
|
||||
|
||||
setOrientation(x: number, y: number, z: number, up_x: number, up_y: number, up_z: number) {
|
||||
[this.forwardX.value, this.forwardY.value, this.forwardZ.value] = [x, y, z];
|
||||
[this.upX.value, this.upY.value, this.upZ.value] = [up_x, up_y, up_z];
|
||||
}
|
||||
|
||||
command(): AudioCommand {
|
||||
const values = (params: Param[]) => params.map((param) => param.value) as Vector;
|
||||
return {
|
||||
op: "listener",
|
||||
position: values([this.positionX, this.positionY, this.positionZ]),
|
||||
forward: values([this.forwardX, this.forwardY, this.forwardZ]),
|
||||
up: values([this.upX, this.upY, this.upZ]),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Context {
|
||||
// there's no rule against playing before the player clicks, it plays right away
|
||||
readonly state = "running";
|
||||
readonly destination: Destination = new Destination(this);
|
||||
readonly listener: Listener = new Listener(this);
|
||||
#queued: AudioCommand[] = [];
|
||||
#flushing = false;
|
||||
#last_listener = "";
|
||||
|
||||
createGain() {
|
||||
return new Gain(this);
|
||||
}
|
||||
|
||||
resume() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
close() {
|
||||
for (const source of playing.values()) source.stop();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// ogg vorbis or ogg opus, by the first packet: after the first page's 27 byte header and its segment table
|
||||
async decodeAudioData(data: ArrayBuffer): Promise<Buffer> {
|
||||
const bytes = new Uint8Array(data);
|
||||
const packet = 27 + (bytes[26] ?? 0);
|
||||
const head = new TextDecoder().decode(bytes.subarray(packet, packet + 8));
|
||||
const decode = head.startsWith("OpusHead") ? decode_opus : head.includes("vorbis") ? decode_vorbis : undefined;
|
||||
if (!decode) throw new Error("Only ogg vorbis and ogg opus can be decoded");
|
||||
const { channelData, sampleRate } = await decode(bytes);
|
||||
if (!channelData.length || !channelData[0].length) throw new Error("There's no audio in it");
|
||||
return new Buffer(channelData, sampleRate);
|
||||
}
|
||||
|
||||
queue(command: AudioCommand) {
|
||||
this.#queued.push(command);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// something about what plays changed, the window hears about it once this task is done
|
||||
changed() {
|
||||
if (this.#flushing) return;
|
||||
this.#flushing = true;
|
||||
queueMicrotask(() => this.#flush());
|
||||
}
|
||||
|
||||
#flush() {
|
||||
this.#flushing = false;
|
||||
const commands = this.#queued;
|
||||
this.#queued = [];
|
||||
const listener = this.listener.command();
|
||||
const listener_key = JSON.stringify(listener);
|
||||
if (listener_key !== this.#last_listener) {
|
||||
this.#last_listener = listener_key;
|
||||
commands.push(listener);
|
||||
}
|
||||
for (const source of playing.values()) {
|
||||
if (source.context !== this) continue;
|
||||
const settings = source_settings(source);
|
||||
if (!source.sent) {
|
||||
const buffer = source.buffer;
|
||||
if (!buffer) continue;
|
||||
if (buffer.id === undefined) {
|
||||
buffer.id = next_id++;
|
||||
const channels = Array.from(
|
||||
{ length: buffer.numberOfChannels },
|
||||
(_, i) => buffer.getChannelData(i),
|
||||
);
|
||||
commands.push({ op: "buffer", id: buffer.id, channels, sample_rate: buffer.sampleRate });
|
||||
}
|
||||
commands.push({
|
||||
op: "play",
|
||||
id: source.id,
|
||||
buffer: buffer.id,
|
||||
loop: source.loop,
|
||||
offset: source.offset,
|
||||
settings,
|
||||
});
|
||||
} else if (!same_settings(source.sent, settings)) {
|
||||
commands.push({ op: "set", id: source.id, settings });
|
||||
}
|
||||
source.sent = settings;
|
||||
}
|
||||
if (commands.length) send(commands);
|
||||
}
|
||||
}
|
||||
|
||||
// the gains between source and destination multiplied, and the panner in between if there's one. silent when it
|
||||
// isn't connected all the way
|
||||
function source_settings(source: BufferSource): SourceSettings {
|
||||
let gain = 1;
|
||||
let panner: Panner | undefined;
|
||||
let node = source.output;
|
||||
while (node && !(node instanceof Destination)) {
|
||||
if (node instanceof Gain) gain *= node.gain.value;
|
||||
else if (node instanceof Panner) panner ??= node;
|
||||
node = node.output;
|
||||
}
|
||||
return {
|
||||
gain: node ? gain : 0,
|
||||
pitch: source.playbackRate.value,
|
||||
at: panner && [panner.positionX.value, panner.positionY.value, panner.positionZ.value],
|
||||
ref_distance: panner?.refDistance ?? 1,
|
||||
max_distance: panner?.maxDistance ?? 1,
|
||||
rolloff: panner?.rolloffFactor ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
function same_settings(a: SourceSettings, b: SourceSettings) {
|
||||
return a.gain === b.gain && a.pitch === b.pitch && a.at?.join() === b.at?.join() &&
|
||||
a.ref_distance === b.ref_distance && a.max_distance === b.max_distance && a.rolloff === b.rolloff;
|
||||
}
|
||||
|
||||
// makes AudioContext and its nodes globals, with to_window sending the window what to play
|
||||
export function install_web_audio(to_window: (commands: AudioCommand[]) => void) {
|
||||
send = to_window;
|
||||
Object.assign(globalThis, {
|
||||
AudioContext: Context,
|
||||
GainNode: Gain,
|
||||
PannerNode: Panner,
|
||||
AudioBufferSourceNode: BufferSource,
|
||||
AudioBuffer: Buffer,
|
||||
AudioParam: Param,
|
||||
});
|
||||
}
|
||||
|
||||
// the window says these played to their end
|
||||
export function sources_ended(ids: number[]) {
|
||||
for (const id of ids) playing.get(id)?.end();
|
||||
}
|
||||
+2
-1
@@ -5,6 +5,7 @@ import { ClientMessage, EntityInfo, MenuSlotInfo, PlayerInfo, ServerMessage } fr
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import { WorldShape } from "@/common/world_shape.ts";
|
||||
import type { Join, ServerSocket, Welcome } from "./handshake.ts";
|
||||
import { platform } from "./platform.ts";
|
||||
|
||||
export class Connection {
|
||||
#server: ServerSocket;
|
||||
@@ -59,5 +60,5 @@ export class Connection {
|
||||
|
||||
// what the name field starts as, from ?name=
|
||||
export function default_player_name(): string {
|
||||
return new URLSearchParams(location.search).get("name") ?? "";
|
||||
return platform.page.searchParams.get("name") ?? "";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// what the client needs from where it runs: a browser page (browser_platform.ts), or the desktop app's window, where
|
||||
// it runs in deno with no browser (native/). the entry point sets it before anything else runs
|
||||
import type { GuiScreen } from "./gui/gui_screen.ts";
|
||||
|
||||
export interface Platform {
|
||||
// the page's address. its query has the options (?server=, ?name=, ?singleplayer), and the client's own files
|
||||
// (/assets/) and the desktop app's requests (/desktop/) are relative to it
|
||||
page: URL;
|
||||
// starts the client over at url, like loading the page again. a server's mods can't be taken back out once
|
||||
// they're loaded, so leaving a server does this
|
||||
restart(url: URL): void;
|
||||
// calls frame once it's time for the next frame, with the time like performance.now()
|
||||
request_frame(frame: (time: number) => void): void;
|
||||
// calls shown when the game can be seen again after being hidden, there are no frames meanwhile. returns what
|
||||
// stops calling it
|
||||
on_shown(shown: () => void): () => void;
|
||||
// what's remembered from one time to the next, like the servers whose mods the player trusts. it can throw, like a
|
||||
// browser's in a private window
|
||||
storage: Pick<Storage, "getItem" | "setItem">;
|
||||
// while playing, leaving asks first
|
||||
confirm_leaving(confirm: boolean): void;
|
||||
// replaces the game with a message, for when it can't go on
|
||||
show_fatal_error(message: string): void;
|
||||
// who made what: the engine's assets/ASSETS.md, then each loaded mod's credits file
|
||||
credits_screen(on_back: () => void): GuiScreen;
|
||||
read_clipboard(): Promise<string>;
|
||||
write_clipboard(text: string): Promise<void>;
|
||||
// while the mouse is grabbed it turns the camera and there's no cursor
|
||||
set_mouse_grabbed(grab: boolean): void;
|
||||
is_mouse_grabbed(): boolean;
|
||||
// whether the mouse was let go by something other than the game since the last call, like switching windows
|
||||
take_lost_mouse(): boolean;
|
||||
toggle_fullscreen(): void;
|
||||
}
|
||||
|
||||
export let platform: Platform;
|
||||
|
||||
export function set_platform(chosen: Platform) {
|
||||
platform = chosen;
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// png decoding, for textures, skins and the gui. the desktop app's client runs without a browser, so it has no image
|
||||
// decoding of its own, and both clients decoding the same way keeps them alike. pixels come out as stored: no color
|
||||
// profile or gamma is applied, like an editor that ignores them
|
||||
import { unzlibSync } from "fflate";
|
||||
|
||||
// rgba, 8 bits a channel, not premultiplied, row by row from the top
|
||||
export interface Pixels {
|
||||
width: number;
|
||||
height: number;
|
||||
data: Uint8ClampedArray<ArrayBuffer>;
|
||||
}
|
||||
|
||||
const SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
|
||||
|
||||
// by color type: gray, rgb, palette, gray and alpha, rgba
|
||||
const CHANNELS: Record<number, number> = { 0: 1, 2: 3, 3: 1, 4: 2, 6: 4 };
|
||||
|
||||
// the 7 passes of an interlaced image: the first pixel's x and y, and the steps between pixels
|
||||
const ADAM7 = [
|
||||
[0, 0, 8, 8],
|
||||
[4, 0, 8, 8],
|
||||
[0, 4, 4, 8],
|
||||
[2, 0, 4, 4],
|
||||
[0, 2, 2, 4],
|
||||
[1, 0, 2, 2],
|
||||
[0, 1, 1, 2],
|
||||
];
|
||||
|
||||
// throws for anything that isn't a png
|
||||
export function decode_png(bytes: Uint8Array): Pixels {
|
||||
if (bytes.length < 8 || SIGNATURE.some((byte, i) => bytes[i] !== byte)) throw new Error("Not a png");
|
||||
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||
|
||||
let width = 0;
|
||||
let height = 0;
|
||||
let depth = 0;
|
||||
let color_type = -1;
|
||||
let interlaced = false;
|
||||
let palette: Uint8Array | undefined;
|
||||
// the alpha of each palette entry, or the one gray or rgb value that's see-through
|
||||
let transparency: Uint8Array | undefined;
|
||||
const compressed: Uint8Array[] = [];
|
||||
|
||||
let pos = 8;
|
||||
while (pos + 8 <= bytes.length) {
|
||||
const length = view.getUint32(pos);
|
||||
const type = String.fromCharCode(...bytes.subarray(pos + 4, pos + 8));
|
||||
const start = pos + 8;
|
||||
const data = bytes.subarray(start, start + length);
|
||||
pos = start + length + 4;
|
||||
if (type === "IHDR") {
|
||||
width = view.getUint32(start);
|
||||
height = view.getUint32(start + 4);
|
||||
depth = data[8];
|
||||
color_type = data[9];
|
||||
interlaced = data[12] === 1;
|
||||
} else if (type === "PLTE") {
|
||||
palette = data;
|
||||
} else if (type === "tRNS") {
|
||||
transparency = data;
|
||||
} else if (type === "IDAT") {
|
||||
compressed.push(data);
|
||||
} else if (type === "IEND") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
const channels = CHANNELS[color_type];
|
||||
if (!channels || !width || !height || ![1, 2, 4, 8, 16].includes(depth)) throw new Error("Not a png");
|
||||
if (color_type === 3 && !palette) throw new Error("A palette png without a palette");
|
||||
|
||||
const raw = unzlibSync(concat(compressed));
|
||||
const pixels = new Uint8ClampedArray(width * height * 4);
|
||||
const bits_per_pixel = channels * depth;
|
||||
// filters work on whole bytes, a pixel's or 1 for pixels smaller than a byte
|
||||
const filter_step = Math.max(1, bits_per_pixel >> 3);
|
||||
// a sample at depth, scaled to 0-255
|
||||
const max = (1 << depth) - 1;
|
||||
const sample = (line: Uint8Array, index: number) => {
|
||||
if (depth === 8) return line[index];
|
||||
if (depth === 16) return (line[index * 2] << 8) | line[index * 2 + 1];
|
||||
const bit = index * depth;
|
||||
return (line[bit >> 3] >> (8 - depth - (bit & 7))) & max;
|
||||
};
|
||||
const to_byte = (value: number) => depth === 16 ? value >> 8 : depth === 8 ? value : Math.round(value * 255 / max);
|
||||
const see_through = (value: number, channel: number) =>
|
||||
(transparency![channel * 2] << 8 | transparency![channel * 2 + 1]) === value;
|
||||
|
||||
let offset = 0;
|
||||
for (const [first_x, first_y, step_x, step_y] of interlaced ? ADAM7 : [[0, 0, 1, 1]]) {
|
||||
const pass_width = Math.ceil((width - first_x) / step_x);
|
||||
const pass_height = Math.ceil((height - first_y) / step_y);
|
||||
if (pass_width <= 0 || pass_height <= 0) continue;
|
||||
const stride = Math.ceil(pass_width * bits_per_pixel / 8);
|
||||
let previous = new Uint8Array(stride);
|
||||
for (let y = 0; y < pass_height; y++) {
|
||||
if (offset + 1 + stride > raw.length) throw new Error("A png with too little image data");
|
||||
const line = raw.slice(offset + 1, offset + 1 + stride);
|
||||
unfilter(raw[offset], line, previous, filter_step);
|
||||
offset += 1 + stride;
|
||||
previous = line;
|
||||
|
||||
for (let x = 0; x < pass_width; x++) {
|
||||
const out = ((first_y + y * step_y) * width + first_x + x * step_x) * 4;
|
||||
const s = x * channels;
|
||||
if (color_type === 3) {
|
||||
const entry = sample(line, x);
|
||||
pixels[out] = palette![entry * 3];
|
||||
pixels[out + 1] = palette![entry * 3 + 1];
|
||||
pixels[out + 2] = palette![entry * 3 + 2];
|
||||
pixels[out + 3] = transparency && entry < transparency.length ? transparency[entry] : 255;
|
||||
} else if (color_type === 0 || color_type === 4) {
|
||||
const gray = sample(line, s);
|
||||
pixels[out] = pixels[out + 1] = pixels[out + 2] = to_byte(gray);
|
||||
pixels[out + 3] = color_type === 4
|
||||
? to_byte(sample(line, s + 1))
|
||||
: transparency && see_through(gray, 0)
|
||||
? 0
|
||||
: 255;
|
||||
} else {
|
||||
const [r, g, b] = [sample(line, s), sample(line, s + 1), sample(line, s + 2)];
|
||||
pixels[out] = to_byte(r);
|
||||
pixels[out + 1] = to_byte(g);
|
||||
pixels[out + 2] = to_byte(b);
|
||||
pixels[out + 3] = color_type === 6
|
||||
? to_byte(sample(line, s + 3))
|
||||
: transparency && see_through(r, 0) && see_through(g, 1) && see_through(b, 2)
|
||||
? 0
|
||||
: 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return { width, height, data: pixels };
|
||||
}
|
||||
|
||||
// undoes a line's filter in place, previous is the line above it, already undone
|
||||
function unfilter(filter: number, line: Uint8Array, previous: Uint8Array, step: number) {
|
||||
switch (filter) {
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
for (let i = step; i < line.length; i++) line[i] += line[i - step];
|
||||
return;
|
||||
case 2:
|
||||
for (let i = 0; i < line.length; i++) line[i] += previous[i];
|
||||
return;
|
||||
case 3:
|
||||
for (let i = 0; i < line.length; i++) line[i] += ((i >= step ? line[i - step] : 0) + previous[i]) >> 1;
|
||||
return;
|
||||
case 4:
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const left = i >= step ? line[i - step] : 0;
|
||||
const up = previous[i];
|
||||
const up_left = i >= step ? previous[i - step] : 0;
|
||||
const p = left + up - up_left;
|
||||
const [pa, pb, pc] = [Math.abs(p - left), Math.abs(p - up), Math.abs(p - up_left)];
|
||||
line[i] += pa <= pb && pa <= pc ? left : pb <= pc ? up : up_left;
|
||||
}
|
||||
return;
|
||||
default:
|
||||
throw new Error("A png with an unknown filter");
|
||||
}
|
||||
}
|
||||
|
||||
function concat(parts: Uint8Array[]) {
|
||||
const all = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
|
||||
let at = 0;
|
||||
for (const part of parts) {
|
||||
all.set(part, at);
|
||||
at += part.length;
|
||||
}
|
||||
return all;
|
||||
}
|
||||
+30
-11
@@ -7,8 +7,20 @@ import type { RenderLayer } from "@/common/everything_registry.ts";
|
||||
import { TERRAIN_VERTEX_BYTES } from "../workers/chunk_messages.ts";
|
||||
import { GpuTimer } from "./gpu_timing.ts";
|
||||
|
||||
// what frames are drawn on: the page's canvas, or the desktop app's window (deno's UnsafeWindowSurface). setting
|
||||
// width and height resizes it, like a canvas
|
||||
export interface DrawSurface {
|
||||
width: number;
|
||||
height: number;
|
||||
getContext(id: "webgpu"): unknown;
|
||||
// shows what was drawn, the window's needs it after every frame, a canvas does it by itself
|
||||
present?(): void;
|
||||
// a canvas is shown scaled when its size is fixed, see set_canvas_size
|
||||
style?: { width: string; height: string };
|
||||
}
|
||||
|
||||
export let device: GPUDevice;
|
||||
export let canvas: HTMLCanvasElement;
|
||||
export let canvas: DrawSurface;
|
||||
|
||||
const MAX_SPRITES = 100000;
|
||||
const VERTS_PER_SPRITE = 6;
|
||||
@@ -120,6 +132,8 @@ export let gpu_timer: GpuTimer | undefined;
|
||||
export let adapter_info: GPUAdapterInfo | undefined;
|
||||
// see set_canvas_size
|
||||
let fixed_canvas_size: { width: number; height: number } | undefined;
|
||||
// the space frames are shown in, the page's or the window's, see resize_canvas
|
||||
let view_size = { width: 1800, height: 900 };
|
||||
let resize_pending = false;
|
||||
// what the passes starting now are timed as
|
||||
let gpu_label = "other";
|
||||
@@ -287,10 +301,10 @@ fn fs_translucent(in: VertexOut) -> @location(0) vec4<f32> {
|
||||
}
|
||||
`;
|
||||
|
||||
export async function init_window(canvas_element: HTMLCanvasElement) {
|
||||
canvas = canvas_element;
|
||||
canvas.width = 1800;
|
||||
canvas.height = 900;
|
||||
export async function init_window(surface: DrawSurface) {
|
||||
canvas = surface;
|
||||
canvas.width = view_size.width;
|
||||
canvas.height = view_size.height;
|
||||
|
||||
if (!navigator.gpu) {
|
||||
throw new Error("WebGPU not supported");
|
||||
@@ -413,6 +427,7 @@ export function end_drawing() {
|
||||
gpu_timer?.resolve(encoder!);
|
||||
device.queue.submit([encoder!.finish()]);
|
||||
encoder = undefined;
|
||||
canvas.present?.();
|
||||
gpu_timer?.read();
|
||||
|
||||
for (const buffer of pending_destroy) {
|
||||
@@ -695,19 +710,23 @@ export function destroy_buffer(buffer: GPUBuffer) {
|
||||
}
|
||||
}
|
||||
|
||||
export function resize_canvas() {
|
||||
const width = fixed_canvas_size?.width ?? self.innerWidth;
|
||||
const height = fixed_canvas_size?.height ?? self.innerHeight;
|
||||
// the space frames are shown in changed to view_width × view_height, or the fixed size did
|
||||
export function resize_canvas(view_width = view_size.width, view_height = view_size.height) {
|
||||
view_size = { width: view_width, height: view_height };
|
||||
const width = fixed_canvas_size?.width ?? view_width;
|
||||
const height = fixed_canvas_size?.height ?? view_height;
|
||||
// a fixed size is shown as big as it fits in the window
|
||||
const scale = Math.min(self.innerWidth / width, self.innerHeight / height);
|
||||
const scale = Math.min(view_width / width, view_height / height);
|
||||
|
||||
if (canvas.width !== width || canvas.height !== height) {
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
// render targets get recreated at the start of the next frame
|
||||
}
|
||||
canvas.style.width = width * scale + "px";
|
||||
canvas.style.height = height * scale + "px";
|
||||
if (canvas.style) {
|
||||
canvas.style.width = width * scale + "px";
|
||||
canvas.style.height = height * scale + "px";
|
||||
}
|
||||
}
|
||||
|
||||
// frames are drawn at this size whatever the window's, like the benchmark's, or at the window's again when it's
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
|
||||
import { create_texture, device, push_quad, push_quad_vertices, use_texture } from "./core.ts";
|
||||
import { Texture } from "./types.ts";
|
||||
import type { Pixels } from "../png.ts";
|
||||
|
||||
export function load_texture(image: HTMLImageElement | ImageBitmap): Texture {
|
||||
export function load_texture(image: Pixels): Texture {
|
||||
const texture = create_texture(image.width, image.height);
|
||||
device.queue.copyExternalImageToTexture({ source: image }, { texture }, [image.width, image.height]);
|
||||
device.queue.writeTexture({ texture }, image.data, { bytesPerRow: image.width * 4 }, [image.width, image.height]);
|
||||
|
||||
return {
|
||||
tex: texture,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// turns to the entity's yaw, and its bones are posed by its type's animator from a mod (see entity_animators.ts). without
|
||||
// one, a bone named "head" turns to where it looks, and bones named like minecraft's humanoid ones (right_arm, left_arm,
|
||||
// right_leg, left_leg) swing as it walks, the right arm when it attacks too. entities without a model are their texture
|
||||
// facing the camera, like minecraft's fishing hook
|
||||
// facing the camera, like minecraft's fishing hook, and objects without one are the item they hold
|
||||
import { AssetManager } from "@/client/assets.ts";
|
||||
import type { Camera } from "@/client/camera.ts";
|
||||
import type { RemoteEntity } from "@/client/entity/remote_entity.ts";
|
||||
@@ -18,6 +18,8 @@ import { HURT_TINT } from "./player_renderer.ts";
|
||||
import { bone_matrices, IDENTITY, model_pivot, multiply, rotation_around, type Vec3 } from "./model_math.ts";
|
||||
import { push_model } from "./model_renderer.ts";
|
||||
import { entity_tint } from "./entity_light.ts";
|
||||
import { push_item, synced_stack } from "./item_renderer.ts";
|
||||
import type { ItemData } from "@/common/inventory.ts";
|
||||
|
||||
// models are in texture pixels, 16 to a block
|
||||
const PIXEL = 1 / 16;
|
||||
@@ -27,29 +29,42 @@ export function render_mod_entity(entity: RemoteEntity, camera: Camera, partial_
|
||||
const json = EverythingRegistry.get<EntityJson>("entities", entity.type);
|
||||
if (!json) return;
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
const region = get_sprite_region(json.texture);
|
||||
const hurt = entity.hurt_time > 0 || entity.dead ? HURT_TINT : undefined;
|
||||
const tint = entity_tint(entity, partial_tick, hurt, entity.data.on_fire === true);
|
||||
const scale = json.scale ?? 1;
|
||||
if (json.model === undefined) {
|
||||
render_sprite(entity, camera, atlas, region, partial_tick, tint);
|
||||
// an object is the item it holds, the size the item's model is made
|
||||
const item = entity.data.item as ItemData | undefined;
|
||||
if (json.behavior === "object") {
|
||||
if (item) push_item(atlas, synced_stack(item), turned_with(entity, partial_tick, scale), tint);
|
||||
} else if (json.texture !== undefined) {
|
||||
render_sprite(entity, camera, atlas, get_sprite_region(json.texture), scale, partial_tick, tint);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const model = EverythingRegistry.get<EntityModelJson>("entity_models", json.model);
|
||||
if (!model) return;
|
||||
|
||||
const { x, y, z } = entity.render_position(partial_tick);
|
||||
const yaw_sin = Math.sin(entity.yaw);
|
||||
const yaw_cos = Math.cos(entity.yaw);
|
||||
const to_world = (px: number, py: number, pz: number): Vec3 => {
|
||||
const [mx, my, mz] = [px * PIXEL, py * PIXEL, pz * PIXEL];
|
||||
return [x + mx * yaw_cos + mz * yaw_sin, y + my, z - mx * yaw_sin + mz * yaw_cos];
|
||||
};
|
||||
if (!model || json.texture === undefined) return;
|
||||
|
||||
const placed = turned_with(entity, partial_tick, scale);
|
||||
const to_world = (px: number, py: number, pz: number) => placed(px * PIXEL, py * PIXEL, pz * PIXEL);
|
||||
const offsets = entity.animation?.pose(entity.age + partial_tick);
|
||||
const pose = offsets ? () => IDENTITY : default_pose(entity, partial_tick);
|
||||
const region = get_sprite_region(json.texture);
|
||||
push_model(model, bone_matrices(model, pose, offsets), atlas, region, to_world, tint);
|
||||
}
|
||||
|
||||
// from blocks around the entity's feet, its own way round, to the world: sized by scale and turned to its yaw
|
||||
function turned_with(entity: RemoteEntity, partial_tick: number, scale: number) {
|
||||
const { x, y, z } = entity.render_position(partial_tick);
|
||||
const yaw_sin = Math.sin(entity.yaw) * scale;
|
||||
const yaw_cos = Math.cos(entity.yaw) * scale;
|
||||
return (bx: number, by: number, bz: number): Vec3 => [
|
||||
x + bx * yaw_cos + bz * yaw_sin,
|
||||
y + by * scale,
|
||||
z - bx * yaw_sin + bz * yaw_cos,
|
||||
];
|
||||
}
|
||||
|
||||
// the head looking and the humanoid swing, for an entity without an animator
|
||||
function default_pose(entity: RemoteEntity, partial_tick: number) {
|
||||
const limbs = limb_angles(entity, partial_tick);
|
||||
@@ -86,14 +101,15 @@ function render_sprite(
|
||||
camera: Camera,
|
||||
atlas: Texture,
|
||||
region: SpriteRegion,
|
||||
scale: number,
|
||||
partial_tick: number,
|
||||
[r, g, b]: Vec3,
|
||||
) {
|
||||
const { x, y, z } = entity.render_position(partial_tick);
|
||||
const cy = y + entity.height / 2;
|
||||
// the camera's right and up, halved to the sprite's size
|
||||
const half_width = region.width * PIXEL / 2;
|
||||
const half_height = region.height * PIXEL / 2;
|
||||
const half_width = region.width * PIXEL * scale / 2;
|
||||
const half_height = region.height * PIXEL * scale / 2;
|
||||
const [yaw_sin, yaw_cos] = [Math.sin(camera.yaw), Math.cos(camera.yaw)];
|
||||
const [pitch_sin, pitch_cos] = [Math.sin(camera.pitch), Math.cos(camera.pitch)];
|
||||
const right: Vec3 = [yaw_cos * half_width, 0, -yaw_sin * half_width];
|
||||
|
||||
@@ -9,13 +9,14 @@ import { get_sprite_region } from "@/client/sprites.ts";
|
||||
import type { ItemEntity } from "@/client/entity/item_entity.ts";
|
||||
import { contained_fluid, type ItemData, ItemStack } from "@/common/inventory.ts";
|
||||
import type { FluidVariant } from "@/common/mod_api/shared.ts";
|
||||
import type { FluidJson } from "@/common/mod_data.ts";
|
||||
import type { EntityModelJson, FluidJson } from "@/common/mod_data.ts";
|
||||
import { light_color, push_vertex, Texture } from "@/client/renderer/mod.ts";
|
||||
import {
|
||||
bake_model,
|
||||
type BakedQuad,
|
||||
block_item_texture,
|
||||
block_variant,
|
||||
classify_quad,
|
||||
cube_face_texture,
|
||||
cube_face_tint,
|
||||
type DisplayTransform,
|
||||
@@ -30,6 +31,8 @@ import { get_state_value, item_texture } from "@/common/utils.ts";
|
||||
import { ID_MASK, TEXTURE_SIZE } from "@/common/constants.ts";
|
||||
import type { ClientLevel } from "@/client/level/client_level.ts";
|
||||
import { entity_tint } from "./entity_light.ts";
|
||||
import { bone_matrices, IDENTITY } from "./model_math.ts";
|
||||
import { push_model } from "./model_renderer.ts";
|
||||
import type { Vec3 } from "./player_renderer.ts";
|
||||
import { fluid_rules } from "@/client/fluid_rules.ts";
|
||||
import { color_rgb, tint_without_biome, type TintColor } from "@/common/worldgen/biome_colors.ts";
|
||||
@@ -124,8 +127,17 @@ export function render_item_entity(entity: ItemEntity, partial_tick: number) {
|
||||
}
|
||||
}
|
||||
|
||||
// the stacks shown items are drawn as, by their "item" client data, which is replaced whenever it changes
|
||||
const shown_stacks = new WeakMap<ItemData, ItemStack>();
|
||||
// the stack an item synced to clients is drawn as, like a shown item's "item" client data or an object's. made once
|
||||
// for each, since the data is replaced whenever it changes
|
||||
export function synced_stack(data: ItemData): ItemStack {
|
||||
let stack = synced_stacks.get(data);
|
||||
if (!stack) {
|
||||
stack = ItemStack.from_data(data);
|
||||
synced_stacks.set(data, stack);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
const synced_stacks = new WeakMap<ItemData, ItemStack>();
|
||||
|
||||
// every item blocks with item_display show on top of them, their "item" client data, see BlockRegistry.item_display.
|
||||
// the atlas has to be the current texture
|
||||
@@ -140,11 +152,7 @@ export function render_block_items(level: ClientLevel) {
|
||||
const value = level.get_block_value(x, y, z);
|
||||
const block = blocks[value & ID_MASK];
|
||||
if (!block?.item_display) continue;
|
||||
let item = shown_stacks.get(shown);
|
||||
if (!item) {
|
||||
item = ItemStack.from_data(shown);
|
||||
shown_stacks.set(shown, item);
|
||||
}
|
||||
const item = synced_stack(shown);
|
||||
// the block's own light, or the one above for blocks light doesn't get into, since the items sit on top
|
||||
const here = level.get_light(x, y, z);
|
||||
const above = level.get_light(x, y + 1, z);
|
||||
@@ -249,11 +257,15 @@ export interface ItemModel {
|
||||
block?: BlockRegistry;
|
||||
}
|
||||
|
||||
// an item's own model, or its block's item_model with the block's textures, baked the first time it's drawn. undefined
|
||||
// for items drawn as a cube or as their sprite
|
||||
// an item's own model, or its block's item_model with the block's textures, baked the first time it's drawn. an item's
|
||||
// own can be an entity model, drawn in the item's texture. undefined for items drawn as a cube or as their sprite
|
||||
export function item_model_of(item: ItemStack): ItemModel | undefined {
|
||||
const info = EverythingRegistry.get<ItemRegistry>("items", item.type_id);
|
||||
if (info?.model !== undefined) return baked_item_model(info, info.model);
|
||||
if (info?.model !== undefined) {
|
||||
const entity_model = EverythingRegistry.get<EntityModelJson>("entity_models", info.model);
|
||||
if (entity_model) return baked_entity_item_model(entity_model, item_texture(item, info));
|
||||
return baked_item_model(info, info.model);
|
||||
}
|
||||
const block = placed_block(item);
|
||||
if (block?.item_model !== undefined) return baked_item_model(block, block.item_model, block);
|
||||
return undefined;
|
||||
@@ -270,6 +282,54 @@ function baked_item_model(key: ItemRegistry | BlockRegistry, id: string, block?:
|
||||
}
|
||||
const baked_items = new WeakMap<ItemRegistry | BlockRegistry, ItemModel>();
|
||||
|
||||
// by texture, since an item's texture can change with its data
|
||||
function baked_entity_item_model(model: EntityModelJson, texture: string): ItemModel {
|
||||
let by_texture = baked_entity_items.get(model);
|
||||
if (!by_texture) {
|
||||
by_texture = new Map();
|
||||
baked_entity_items.set(model, by_texture);
|
||||
}
|
||||
let baked = by_texture.get(texture);
|
||||
if (!baked) {
|
||||
baked = { quads: entity_model_quads(model, texture), display: model.display ?? {} };
|
||||
by_texture.set(texture, baked);
|
||||
}
|
||||
return baked;
|
||||
}
|
||||
const baked_entity_items = new WeakMap<EntityModelJson, Map<string, ItemModel>>();
|
||||
|
||||
// an entity model as a block model's quads, standing on the block's bottom in its middle like it stands on the ground,
|
||||
// 16 of its pixels across the block. its uvs are pixels of the texture, 0 to 16 like a block model's
|
||||
export function entity_model_quads(model: EntityModelJson, texture: string): BakedQuad[] {
|
||||
const vertices: number[][] = [];
|
||||
const pixels = { width: 1, height: 1 } as Texture;
|
||||
const whole_texture = { x: 0, y: 0, width: TEXTURE_SIZE, height: TEXTURE_SIZE };
|
||||
const to_block = (x: number, y: number, z: number): Vec3 => [x / 16 + 0.5, y / 16, z / 16 + 0.5];
|
||||
push_model(model, bone_matrices(model, () => IDENTITY), pixels, whole_texture, to_block, undefined, undefined, (
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
u,
|
||||
v,
|
||||
) => vertices.push([x, y, z, u, v]));
|
||||
const quads: BakedQuad[] = [];
|
||||
// two triangles a box face, its corners 0 1 2 and 0 2 3
|
||||
for (let i = 0; i < vertices.length; i += 6) {
|
||||
const corners = [vertices[i], vertices[i + 1], vertices[i + 2], vertices[i + 5]];
|
||||
const positions = corners.flatMap(([x, y, z]) => [x, y, z]);
|
||||
quads.push({
|
||||
positions,
|
||||
uvs: corners.flatMap(([, , , u, v]) => [u, v]),
|
||||
texture,
|
||||
variables: [],
|
||||
...classify_quad(positions),
|
||||
cull: -1,
|
||||
shade: true,
|
||||
});
|
||||
}
|
||||
return quads;
|
||||
}
|
||||
|
||||
// whether an item is drawn as a block or a model rather than its sprite, which decides how big it's drawn and how it's
|
||||
// held when its model has no display transform for that
|
||||
export function drawn_as_model(item: ItemStack) {
|
||||
|
||||
+6
-11
@@ -2,19 +2,14 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { load_texture, type Texture } from "./renderer/mod.ts";
|
||||
import { decode_png } from "./png.ts";
|
||||
|
||||
// a player's skin as the server sends it (a base64 64x64 png), undefined when it can't be decoded
|
||||
export async function decode_skin(skin: string): Promise<Texture | undefined> {
|
||||
// a player's skin as the server sends it (a base64 64x64 png), undefined when it can't be decoded. pixels are as
|
||||
// stored, so pngs with a color profile look the same as in an editor that ignores it
|
||||
export function decode_skin(skin: string): Texture | undefined {
|
||||
try {
|
||||
const bytes = Uint8Array.from(atob(skin), (char) => char.charCodeAt(0));
|
||||
// as stored, so pngs with a color profile look the same as in an editor that ignores it, like minecraft
|
||||
const image = await createImageBitmap(new Blob([bytes], { type: "image/png" }), {
|
||||
colorSpaceConversion: "none",
|
||||
premultiplyAlpha: "none",
|
||||
});
|
||||
const texture = image.width === 64 && image.height === 64 ? load_texture(image) : undefined;
|
||||
image.close();
|
||||
return texture;
|
||||
const image = decode_png(Uint8Array.from(atob(skin), (char) => char.charCodeAt(0)));
|
||||
return image.width === 64 && image.height === 64 ? load_texture(image) : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ export function bake_model(
|
||||
let cull = face_json.cullface ? FACE_INDEX[face_json.cullface] : -1;
|
||||
for (let t = 0; t < x_turns && cull >= 0; t++) cull = TURN_X[cull];
|
||||
for (let t = 0; t < turns && cull >= 0; t++) cull = TURN_Y[cull];
|
||||
const { face: facing, flush, aligned } = classify(positions);
|
||||
const { face: facing, flush, aligned } = classify_quad(positions);
|
||||
quads.push({
|
||||
positions,
|
||||
uvs,
|
||||
@@ -560,7 +560,7 @@ export function element_rotation(element: ModelElementJson): (point: number[]) =
|
||||
}
|
||||
|
||||
// which way a quad faces most, whether it's flat against the block's edge, and whether it faces straight along an axis
|
||||
function classify(p: number[]): { face: number; flush: boolean; aligned: boolean } {
|
||||
export function classify_quad(p: number[]): { face: number; flush: boolean; aligned: boolean } {
|
||||
const e1 = [p[3] - p[0], p[4] - p[1], p[5] - p[2]];
|
||||
const e2 = [p[9] - p[0], p[10] - p[1], p[11] - p[2]];
|
||||
const normal = [e1[1] * e2[2] - e1[2] * e2[1], e1[2] * e2[0] - e1[0] * e2[2], e1[0] * e2[1] - e1[1] * e2[0]];
|
||||
|
||||
@@ -284,8 +284,12 @@ export interface ItemRegistry<T = unknown | undefined> {
|
||||
texture_id: string | ((item: ItemStack<T>) => string);
|
||||
// shown in place of texture_id while the stack's data has that key set, like a cast fishing rod. the first wins
|
||||
data_textures?: Record<string, string>;
|
||||
// a model it's drawn with instead of its texture, with the model's own textures, like a 3d wrench
|
||||
// a model it's drawn with instead of its texture, with the model's own textures, like a 3d wrench. or an entity
|
||||
// model (see EntityModelJson), drawn in its texture
|
||||
model?: string;
|
||||
// the entity it lies in the world as instead of a cubi:item, holding the stack, like neoforge's hasCustomEntity.
|
||||
// an "object" (see EntityJson.behavior)
|
||||
entity?: string;
|
||||
// what players see, like "Iron Ingot". made from the id when not set, see display_name in common/utils.ts
|
||||
name?: string;
|
||||
block_id?: string;
|
||||
|
||||
@@ -381,6 +381,13 @@ export interface BlockInteractEvent {
|
||||
readonly item: ItemStack | undefined;
|
||||
}
|
||||
|
||||
// a right click on an entity, like neoforge's PlayerInteractEvent.EntityInteract
|
||||
export interface EntityInteractEvent {
|
||||
readonly player: Player;
|
||||
readonly entity: EntityRef;
|
||||
readonly item: ItemStack | undefined;
|
||||
}
|
||||
|
||||
// a player or a mob being hurt, like neoforge's LivingIncomingDamageEvent
|
||||
export interface EntityDamageEvent {
|
||||
readonly entity: LivingRef;
|
||||
@@ -408,6 +415,8 @@ export interface ServerBeforeEvents {
|
||||
block_break: EventSignal<BlockBreakEvent & Cancelable>;
|
||||
block_place: EventSignal<BlockPlaceEvent & Cancelable>;
|
||||
block_interact: EventSignal<BlockInteractEvent & Cancelable>;
|
||||
// handlers do what the click does, and cancel it so the held item isn't used too
|
||||
entity_interact: EventSignal<EntityInteractEvent & Cancelable>;
|
||||
chat_send: EventSignal<ChatSendEvent & Cancelable>;
|
||||
entity_damage: EventSignal<EntityDamageEvent & Cancelable>;
|
||||
}
|
||||
@@ -584,10 +593,10 @@ export interface EntityRef {
|
||||
// like neoforge's Entity.kill: a player or a mob dies, even when invulnerable, and anything else is removed. cause
|
||||
// is for events and the death message, like LivingRef.damage's. mods' entity_damage can still cancel it
|
||||
kill(cause?: string): void;
|
||||
// what an item lying around is, a copy. undefined for every other kind of entity
|
||||
// what an item lying around is, or what an object holds, a copy. undefined for every other kind of entity
|
||||
get_item(): ItemStack | undefined;
|
||||
// changes what an item lying around is, like ItemEntity.setItem. undefined or a count of 0 removes it. throws for
|
||||
// every other kind of entity
|
||||
// changes what an item lying around is, like ItemEntity.setItem, undefined or a count of 0 removing it. or what an
|
||||
// object holds, undefined or a count of 0 leaving it holding nothing. throws for every other kind of entity
|
||||
set_item(item: ItemStack | undefined): void;
|
||||
// a sound following it, once, for every player who sees it and is within its range
|
||||
play_sound(sound: Id, options?: PlayOptions): void;
|
||||
@@ -728,6 +737,8 @@ export interface SchematicApi {
|
||||
// StructureTemplateManager.get. undefined for an id nothing registered. for reading what's in it before placing it,
|
||||
// like where a room's doorways are
|
||||
get(id: Id): Schematic | undefined;
|
||||
// every registered schematic's id, the files' and the ones scripts registered, in the order they were registered
|
||||
ids(): Id[];
|
||||
// puts a registered schematic in the world, all of it at once, replacing what was there, air too. replaced blocks
|
||||
// get their on_break. blocks it has data for get that data as it is, the rest their on_create, then everything
|
||||
// placed tells the blocks beside it. its entities come with new uuids. throws for an id nothing registered, or a
|
||||
|
||||
+11
-2
@@ -361,7 +361,16 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
errors.push(`${file}: item ${json.id} has no texture, and no block of this mod gives it an item`);
|
||||
}
|
||||
for (const texture of Object.values(json.data_textures ?? {})) uses(file, texture, "texture");
|
||||
if (json.model) uses(file, json.model, "model");
|
||||
// an entity model is drawn in the item's texture
|
||||
if (json.model && !entity_model_owners.has(json.model)) uses(file, json.model, "model");
|
||||
if (json.entity) {
|
||||
check_namespace(file, json.entity);
|
||||
const behavior = entity_jsons.get(json.entity)?.behavior;
|
||||
if (!entity_owners.has(json.entity)) errors.push(`${file}: entity ${json.entity} doesn't exist`);
|
||||
else if (behavior !== "object") {
|
||||
errors.push(`${file}: entity ${json.entity} has to be an "object" to lie around holding the item`);
|
||||
}
|
||||
}
|
||||
if (json.places) uses(file, json.places, "block");
|
||||
if (json.food?.returns) uses(file, json.food.returns, "item");
|
||||
for (const layer of json.layers ?? []) uses(file, layer.texture, "texture");
|
||||
@@ -404,7 +413,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
errors.push(`${file}: entity ${json.id} is also defined by ${entity_owners.get(json.id)!.join(", ")}`);
|
||||
}
|
||||
if (json.model !== undefined) uses(file, json.model, "entity model");
|
||||
uses(file, json.texture, "texture");
|
||||
if (json.texture !== undefined) uses(file, json.texture, "texture");
|
||||
if (json.loot_table) uses(file, json.loot_table, "loot table");
|
||||
if (json.sounds) uses_sounds(file, json.sounds, ENTITY_SOUNDS);
|
||||
// scripts register behaviors, the server checks them when it starts
|
||||
|
||||
+44
-7
@@ -23,7 +23,7 @@ import {
|
||||
WATERLOGGED,
|
||||
type WornProperties,
|
||||
} from "./everything_registry.ts";
|
||||
import type { BlockPart, BlockVariant, ModelFileJson } from "./block_models.ts";
|
||||
import type { BlockPart, BlockVariant, ModelDisplay, ModelFileJson } from "./block_models.ts";
|
||||
import { expand_items, list_matches } from "./tags.ts";
|
||||
import { GAME_VERSION } from "./constants.ts";
|
||||
import type { PlayOptions } from "./mod_api/shared.ts";
|
||||
@@ -368,6 +368,8 @@ export interface ItemJson {
|
||||
data_textures?: Record<string, string>;
|
||||
// see ItemRegistry.model
|
||||
model?: string;
|
||||
// see ItemRegistry.entity
|
||||
entity?: string;
|
||||
// tier and speed default to 0 and 2
|
||||
tool?: Omit<ToolProperties, "tier" | "speed"> & Partial<ToolProperties>;
|
||||
places?: string;
|
||||
@@ -390,6 +392,7 @@ const item_schema: z.ZodType<ItemJson> = z.object({
|
||||
texture: id.optional(),
|
||||
data_textures: z.record(z.string(), id).optional(),
|
||||
model: id.optional(),
|
||||
entity: id.optional(),
|
||||
tool: z.object({
|
||||
type: z.string(),
|
||||
durability: z.int().min(1),
|
||||
@@ -429,19 +432,24 @@ const item_schema: z.ZodType<ItemJson> = z.object({
|
||||
components: json_object.optional(),
|
||||
});
|
||||
|
||||
// a kind of entity, drawn with an entity model and one texture, or without a model as its texture facing the camera
|
||||
const ENTITY_BEHAVIORS = ["animal", "monster", "scripted", "object"];
|
||||
|
||||
// a kind of entity, drawn with an entity model and one texture, or without a model as its texture facing the camera.
|
||||
// an object without a model is drawn as the item it holds
|
||||
const entity_schema = z.object({
|
||||
id,
|
||||
// an entity model, see EntityModelJson
|
||||
model: id.optional(),
|
||||
texture: id,
|
||||
// only an object can go without one
|
||||
texture: id.optional(),
|
||||
// "animal" (the default) wanders around, panics when hurt and looks at players. "monster" goes after players it
|
||||
// sees and whoever hurts it, and despawns far from players, like minecraft's zombies. "scripted" stays where
|
||||
// scripts put it: no gravity, ai or health, and it isn't saved with the world, like the fishing hook. any other id
|
||||
// is a behavior a mod's script registers
|
||||
// scripts put it: no gravity, ai or health, and it isn't saved with the world, like the fishing hook. "object" lies
|
||||
// around like a dropped item, holding one, without ai or health (see ItemRegistry.entity). any other id is a
|
||||
// behavior a mod's script registers
|
||||
behavior: z.custom<string>(
|
||||
(value) => ["animal", "monster", "scripted"].includes(value as string) || id.safeParse(value).success,
|
||||
'must be "animal", "monster", "scripted" or a behavior id like "my_mod:thing"',
|
||||
(value) => ENTITY_BEHAVIORS.includes(value as string) || id.safeParse(value).success,
|
||||
'must be "animal", "monster", "scripted", "object" or a behavior id like "my_mod:thing"',
|
||||
).optional(),
|
||||
// what natural spawning counts it as, see entity_category
|
||||
category: z.enum(["monster", "creature"]).optional(),
|
||||
@@ -465,6 +473,11 @@ const entity_schema = z.object({
|
||||
loot_table: loot_table_id.optional(),
|
||||
// what it sounds like: <sounds>/hurt, /death, /step and /ambient, see ENTITY_SOUNDS
|
||||
sounds: sound_prefix.optional(),
|
||||
// how much bigger it's drawn than its model (or its texture, or its item), 1 when not set. its box stays the same
|
||||
scale: z.number().positive().optional(),
|
||||
}).refine((entity) => entity.texture !== undefined || entity.behavior === "object", {
|
||||
path: ["texture"],
|
||||
message: "is needed unless it's an object",
|
||||
});
|
||||
|
||||
export type EntityJson = z.infer<typeof entity_schema>;
|
||||
@@ -567,6 +580,8 @@ const entity_model_schema = z.object({
|
||||
// the size its uvs are laid out for, the texture is stretched to it
|
||||
texture_width: z.int().min(1),
|
||||
texture_height: z.int().min(1),
|
||||
// how it's placed where it's shown as an item, from the geometry's item_display_transforms
|
||||
display: z.partialRecord(z.enum(DISPLAY_CONTEXTS), display_transform).optional(),
|
||||
// parents come before their children
|
||||
bones: z.array(entity_bone).superRefine((bones, ctx) => {
|
||||
const names = new Set<string>();
|
||||
@@ -897,6 +912,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
|
||||
const json: ItemJson = { id, texture: item.texture_id };
|
||||
if (item.data_textures !== undefined) json.data_textures = item.data_textures;
|
||||
if (item.model !== undefined) json.model = item.model;
|
||||
if (item.entity !== undefined) json.entity = item.entity;
|
||||
if (item.tool !== undefined) json.tool = item.tool;
|
||||
if (item.block_id !== undefined) json.places = item.block_id;
|
||||
if (item.max_stack !== undefined) json.max_stack = item.max_stack;
|
||||
@@ -927,6 +943,7 @@ function item_fields(json: ItemJson): Partial<ItemRegistry> {
|
||||
const item: Partial<ItemRegistry> = {};
|
||||
if (json.data_textures !== undefined) item.data_textures = json.data_textures;
|
||||
if (json.model !== undefined) item.model = json.model;
|
||||
if (json.entity !== undefined) item.entity = json.entity;
|
||||
if (json.tool !== undefined) item.tool = { tier: 0, speed: 2, ...json.tool };
|
||||
if (json.places !== undefined) item.block_id = json.places;
|
||||
if (json.max_stack !== undefined) item.max_stack = json.max_stack;
|
||||
@@ -1063,10 +1080,12 @@ export function entity_model_from_geo(json: unknown, id: string): { model?: Enti
|
||||
};
|
||||
}
|
||||
const bones = Array.isArray(geometry.bones) ? geometry.bones : [];
|
||||
const display = geo_display(geometry.item_display_transforms);
|
||||
const model = {
|
||||
id,
|
||||
texture_width: geometry.description.texture_width,
|
||||
texture_height: geometry.description.texture_height,
|
||||
...(display === undefined ? {} : { display }),
|
||||
bones: bones.map((bone) => {
|
||||
if (!is_object(bone)) return bone;
|
||||
const { name, parent, pivot, rotation } = bone;
|
||||
@@ -1094,6 +1113,24 @@ export function entity_model_from_geo(json: unknown, id: string): { model?: Enti
|
||||
return problems.length === 0 ? { model: model as EntityModelJson, problems } : { problems };
|
||||
}
|
||||
|
||||
// the places a geometry's item_display_transforms has that items are shown in, with what of each the engine uses. their
|
||||
// rotation_pivot, scale_pivot and fit_to_frame are left out
|
||||
function geo_display(transforms: unknown): ModelDisplay | undefined {
|
||||
if (!is_object(transforms)) return undefined;
|
||||
const display: Record<string, unknown> = {};
|
||||
for (const context of DISPLAY_CONTEXTS) {
|
||||
const transform = transforms[context];
|
||||
if (!is_object(transform)) continue;
|
||||
const { rotation, translation, scale } = transform;
|
||||
display[context] = {
|
||||
...(rotation === undefined ? {} : { rotation }),
|
||||
...(translation === undefined ? {} : { translation }),
|
||||
...(scale === undefined ? {} : { scale }),
|
||||
};
|
||||
}
|
||||
return Object.keys(display).length > 0 ? display as ModelDisplay : undefined;
|
||||
}
|
||||
|
||||
export function validate_clip(json: unknown): Problems {
|
||||
return find_problems(clip_schema, json);
|
||||
}
|
||||
|
||||
+3
-1
@@ -12,7 +12,7 @@ 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 = 30;
|
||||
export const PROTOCOL_VERSION = 31;
|
||||
|
||||
export interface PlayerInfo {
|
||||
id: string;
|
||||
@@ -132,6 +132,8 @@ export type ClientMessage =
|
||||
| { type: "hit_block"; x: number; y: number; z: number }
|
||||
// left click on an entity, by id
|
||||
| { type: "attack_entity"; id: string }
|
||||
// right click on an entity, by id, for mods' entity_interact. it uses the held item when they don't stop it
|
||||
| { type: "interact_entity"; id: string }
|
||||
// left click at nothing, a swing at the air. it starts the attack cooldown over, like an attack
|
||||
| { type: "swing" }
|
||||
// right click without looking at a block, for items' on_use
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
"pack-mod": "deno run --allow-read --allow-write --allow-run --allow-env tools/pack_mod.ts",
|
||||
"test": "deno test --allow-read --allow-write --allow-run --allow-net tests/",
|
||||
"bench": "deno bench --allow-read --allow-write --allow-run tests/",
|
||||
"desktop": "deno run -A build.ts --once && deno desktop --allow-read --allow-write --allow-net --allow-ffi --allow-env=CUBI_SERVER,CUBI_CLIENT_UPDATES,HOME,USERPROFILE,APPDATA,XDG_DATA_HOME,DEBUG --include build --include server_mods --include server/game/worker.ts --include server/game/worldgen_worker.ts --include server/content_worker.ts --include desktop/config.json desktop/main.ts && deno run --allow-read --allow-write desktop/linux_launcher.ts dist/cubi",
|
||||
"desktop-all": "deno run -A tools/desktop_all.ts"
|
||||
"desktop": "deno run --unstable-webgpu --allow-read --allow-write --allow-net --allow-ffi --allow-env=CUBI_SERVER,CUBI_CLIENT_UPDATES,HOME,USERPROFILE,APPDATA,XDG_DATA_HOME desktop/main.ts",
|
||||
"compile": "deno run -A tools/compile.ts"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"lib": ["dom", "dom.asynciterable", "dom.iterable", "deno.ns", "deno.unstable", "deno.webgpu"]
|
||||
@@ -25,6 +25,8 @@
|
||||
},
|
||||
"imports": {
|
||||
"@/": "./",
|
||||
"@audio/decode-opus": "npm:@audio/decode-opus@^1.3.3",
|
||||
"@audio/decode-vorbis": "npm:@audio/decode-vorbis@^1.3.4",
|
||||
"@std/msgpack": "jsr:@std/msgpack@^1.0.3",
|
||||
"cubi/server": "./common/mod_api/server.ts",
|
||||
"cubi/client": "./common/mod_api/client.ts",
|
||||
@@ -42,10 +44,5 @@
|
||||
"gl-matrix": "npm:gl-matrix@^3.4.4",
|
||||
"marked": "npm:marked@^17.0.3",
|
||||
"zod": "jsr:@zod/zod@^4.6.7"
|
||||
},
|
||||
"desktop": {
|
||||
"app": { "name": "cubi", "identifier": "com.bworld.game" },
|
||||
"backend": "cef",
|
||||
"output": { "macos": "./dist/cubi.app", "windows": "./dist/cubi", "linux": "./dist/cubi" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
"jsr:@std/path@^1.1.4": "1.1.6",
|
||||
"jsr:@std/streams@^1.0.17": "1.1.2",
|
||||
"jsr:@zod/zod@^4.6.7": "4.6.7",
|
||||
"npm:@audio/decode-opus@^1.3.3": "1.3.3",
|
||||
"npm:@audio/decode-vorbis@^1.3.4": "1.3.4",
|
||||
"npm:fflate@~0.8.2": "0.8.3",
|
||||
"npm:gl-matrix@^3.4.4": "3.4.4",
|
||||
"npm:marked@^17.0.3": "17.0.3"
|
||||
@@ -129,6 +131,39 @@
|
||||
}
|
||||
},
|
||||
"npm": {
|
||||
"@audio/decode-opus@1.3.3": {
|
||||
"integrity": "sha512-/iykUcA9cgdqqj9pLwPjBkJ4z+WlpLIyWA4xGzvTBkHb1uWpMxYX5yoG+slw8HhmBmrBP2LxKqw6i779g4acVA==",
|
||||
"dependencies": [
|
||||
"codec-parser"
|
||||
]
|
||||
},
|
||||
"@audio/decode-vorbis@1.3.4": {
|
||||
"integrity": "sha512-0bgH1zgLlpgjdHj9NWdiYkMeLyCz5w1UEuvg2qiwJFXbwYSvRhOcmeT82CQUlb8RZSblS3AWpDJzLnAmQJ2cgg==",
|
||||
"dependencies": [
|
||||
"@wasm-audio-decoders/ogg-vorbis",
|
||||
"codec-parser"
|
||||
]
|
||||
},
|
||||
"@eshaz/web-worker@1.2.2": {
|
||||
"integrity": "sha512-WxXiHFmD9u/owrzempiDlBB1ZYqiLnm9s6aPc8AlFQalq2tKmqdmMr9GXOupDgzXtqnBipj8Un0gkIm7Sjf8mw=="
|
||||
},
|
||||
"@wasm-audio-decoders/common@9.0.7": {
|
||||
"integrity": "sha512-WRaUuWSKV7pkttBygml/a6dIEpatq2nnZGFIoPTc5yPLkxL6Wk4YaslPM98OPQvWacvNZ+Py9xROGDtrFBDzag==",
|
||||
"dependencies": [
|
||||
"@eshaz/web-worker",
|
||||
"simple-yenc"
|
||||
]
|
||||
},
|
||||
"@wasm-audio-decoders/ogg-vorbis@0.1.20": {
|
||||
"integrity": "sha512-zaQPasU5usRjUDXtXOHYED5tfkR4QMXd+EH3Nrz1+4+M5pCsdD+s9YxJqb0oqnTyRu/KUujOmu5Z/m/NT47vwg==",
|
||||
"dependencies": [
|
||||
"@wasm-audio-decoders/common",
|
||||
"codec-parser"
|
||||
]
|
||||
},
|
||||
"codec-parser@2.5.0": {
|
||||
"integrity": "sha512-Ru9t80fV8B0ZiixQl8xhMTLru+dzuis/KQld32/x5T/+3LwZb0/YvQdSKytX9JqCnRdiupvAvyYJINKrXieziQ=="
|
||||
},
|
||||
"fflate@0.8.3": {
|
||||
"integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA=="
|
||||
},
|
||||
@@ -138,6 +173,9 @@
|
||||
"marked@17.0.3": {
|
||||
"integrity": "sha512-jt1v2ObpyOKR8p4XaUJVk3YWRJ5n+i4+rjQopxvV32rSndTJXvIzuUdWWIy/1pFQMkQmvTXawzDNqOH/CUmx6A==",
|
||||
"bin": true
|
||||
},
|
||||
"simple-yenc@1.0.4": {
|
||||
"integrity": "sha512-5gvxpSd79e9a3V4QDYUqnqxeD4HGlhCakVpb6gMnDD7lexJggSBJRBO5h52y/iJrdXRilX9UCuDaIJhSWm5OWw=="
|
||||
}
|
||||
},
|
||||
"remote": {
|
||||
@@ -154,6 +192,8 @@
|
||||
"jsr:@std/msgpack@^1.0.3",
|
||||
"jsr:@std/path@1",
|
||||
"jsr:@zod/zod@^4.6.7",
|
||||
"npm:@audio/decode-opus@^1.3.3",
|
||||
"npm:@audio/decode-vorbis@^1.3.4",
|
||||
"npm:fflate@~0.8.2",
|
||||
"npm:gl-matrix@^3.4.4",
|
||||
"npm:marked@^17.0.3"
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// what the desktop app serves its client from: the client's files (updated from the site, see client_updates.ts),
|
||||
// and singleplayer, whose worlds are played on a game server of the app's own with the mods each world picked from
|
||||
// its data folder (see saves.ts). main.ts shows the client in the app's window
|
||||
import { fromFileUrl, join } from "@std/path";
|
||||
import { serve_static } from "../server/host.ts";
|
||||
import { PROTOCOL_VERSION } from "../common/protocol.ts";
|
||||
import { current_client, update_client } from "./client_updates.ts";
|
||||
import { data_dir, install_mods } from "./saves.ts";
|
||||
import { singleplayer_server } from "./singleplayer.ts";
|
||||
|
||||
// where the project was built from, with what deno task build made in build/ and server_mods/ (the .cubi files)
|
||||
const ROOT = fromFileUrl(new URL("../", import.meta.url));
|
||||
const BUILD_DIR = join(ROOT, "build");
|
||||
|
||||
// how long the first page waits for an update, a slower one is played next time
|
||||
const UPDATE_WAIT_MS = 3000;
|
||||
|
||||
export function desktop_app(on_fatal: (message: string) => void) {
|
||||
const data = data_dir();
|
||||
install_mods(join(ROOT, "server_mods"), data);
|
||||
|
||||
// the server the address field starts with. "" leaves it empty for the player to fill in
|
||||
const config: { server?: string; client_updates?: string } = JSON.parse(
|
||||
Deno.readTextFileSync(new URL("./config.json", import.meta.url)),
|
||||
);
|
||||
const default_server = Deno.env.get("CUBI_SERVER") ?? config.server ?? "";
|
||||
|
||||
// the site the client updates from, see client_updates.ts. CUBI_CLIENT_UPDATES=off plays the client the app was
|
||||
// built with (to test a local build), or it can point at a local server to test updating
|
||||
const updates_from = (Deno.env.get("CUBI_CLIENT_UPDATES") ?? config.client_updates ?? "off").replace(/\/+$/, "");
|
||||
const client_options = {
|
||||
source: updates_from,
|
||||
bundled_dir: BUILD_DIR,
|
||||
cache_dir: join(data, "client"),
|
||||
protocol: PROTOCOL_VERSION,
|
||||
};
|
||||
const client_dir: Promise<string> = updates_from === "off" || updates_from === ""
|
||||
? Promise.resolve(BUILD_DIR)
|
||||
: Promise.race([
|
||||
update_client(client_options),
|
||||
new Promise<string>((resolve) => setTimeout(() => resolve(current_client(client_options)), UPDATE_WAIT_MS)),
|
||||
]);
|
||||
client_dir.then((dir) => console.log(`Playing the client in ${dir}`));
|
||||
|
||||
const singleplayer = singleplayer_server({ build_dir: BUILD_DIR, data_dir: data, on_fatal });
|
||||
|
||||
return {
|
||||
data_dir: data,
|
||||
client_dir,
|
||||
singleplayer,
|
||||
// the client's page at origin. ?server= fills in the address field, without it the field would start with
|
||||
// this app's own address. ?singleplayer shows the main menu instead of the browser's title screen
|
||||
start_page(origin: string) {
|
||||
const start = new URL("/client/", origin);
|
||||
start.searchParams.set("server", default_server);
|
||||
start.searchParams.set("singleplayer", "");
|
||||
return start;
|
||||
},
|
||||
// singleplayer's requests and the client's files
|
||||
async handle(req: Request, url: URL): Promise<Response> {
|
||||
const response = await singleplayer.handle(req, url);
|
||||
if (response) return response;
|
||||
return serve_static(await client_dir, req, url);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// when the game lets go of the mouse to open a gui, chromium puts the cursor back where it was grabbed. like minecraft
|
||||
// it goes to the middle of the window instead, moved there by the os: libX11 on linux, user32 on windows. the page
|
||||
// asks for it, see desktop/main.ts and client/input_manager.ts. nothing happens without the library or on macs
|
||||
|
||||
const X11 = {
|
||||
XOpenDisplay: { parameters: ["pointer"], result: "pointer" },
|
||||
XSetErrorHandler: { parameters: ["function"], result: "pointer" },
|
||||
XGetInputFocus: { parameters: ["pointer", "buffer", "buffer"], result: "i32" },
|
||||
XGetGeometry: {
|
||||
parameters: ["pointer", "u64", "buffer", "buffer", "buffer", "buffer", "buffer", "buffer", "buffer"],
|
||||
result: "i32",
|
||||
},
|
||||
XWarpPointer: { parameters: ["pointer", "u64", "u64", "i32", "i32", "u32", "u32", "i32", "i32"], result: "i32" },
|
||||
XSync: { parameters: ["pointer", "i32"], result: "i32" },
|
||||
} as const;
|
||||
|
||||
const USER32 = {
|
||||
GetForegroundWindow: { parameters: [], result: "pointer" },
|
||||
GetWindowThreadProcessId: { parameters: ["pointer", "buffer"], result: "u32" },
|
||||
GetClientRect: { parameters: ["pointer", "buffer"], result: "i32" },
|
||||
ClientToScreen: { parameters: ["pointer", "buffer"], result: "i32" },
|
||||
SetCursorPos: { parameters: ["i32", "i32"], result: "i32" },
|
||||
} as const;
|
||||
|
||||
// moves the cursor to the middle of the app's window, if it's the one in front. set up on the first call
|
||||
export function center_mouse() {
|
||||
center ??= setup();
|
||||
center();
|
||||
}
|
||||
|
||||
let center: (() => void) | undefined;
|
||||
|
||||
function setup(): () => void {
|
||||
switch (Deno.build.os) {
|
||||
case "linux":
|
||||
return setup_x11();
|
||||
case "windows":
|
||||
return setup_windows();
|
||||
default:
|
||||
return () => {};
|
||||
}
|
||||
}
|
||||
|
||||
function setup_x11(): () => void {
|
||||
let lib: Deno.DynamicLibrary<typeof X11>;
|
||||
try {
|
||||
lib = Deno.dlopen("libX11.so.6", X11);
|
||||
} catch (e) {
|
||||
console.error(`Not centering the mouse, no libX11: ${(e as Error).message}`);
|
||||
return () => {};
|
||||
}
|
||||
const x = lib.symbols;
|
||||
const display = x.XOpenDisplay(null);
|
||||
if (!display) {
|
||||
console.error("Not centering the mouse, no X display");
|
||||
return () => {};
|
||||
}
|
||||
// xlib's own handler exits the process, like when the window went away
|
||||
const on_error = new Deno.UnsafeCallback({ parameters: ["pointer", "pointer"], result: "i32" }, () => 0);
|
||||
x.XSetErrorHandler(on_error.pointer);
|
||||
|
||||
const focus = new BigUint64Array(1);
|
||||
const revert_to = new Int32Array(1);
|
||||
const root = new BigUint64Array(1);
|
||||
const [left, top] = [new Int32Array(1), new Int32Array(1)];
|
||||
const [width, height, border, depth] = [
|
||||
new Uint32Array(1),
|
||||
new Uint32Array(1),
|
||||
new Uint32Array(1),
|
||||
new Uint32Array(1),
|
||||
];
|
||||
return () => {
|
||||
// the window with focus, chromium's own inside the app's frame, which has it while the game is asking
|
||||
x.XGetInputFocus(display, focus, revert_to);
|
||||
const window = focus[0];
|
||||
// None and PointerRoot
|
||||
if (window <= 1n) return;
|
||||
if (!x.XGetGeometry(display, window, root, left, top, width, height, border, depth)) return;
|
||||
// from no particular window, to the middle of the app's
|
||||
x.XWarpPointer(display, 0n, window, 0, 0, 0, 0, width[0] >> 1, height[0] >> 1);
|
||||
// done before the page hears back, it grabs the mouse again only after that
|
||||
x.XSync(display, 0);
|
||||
};
|
||||
}
|
||||
|
||||
function setup_windows(): () => void {
|
||||
let lib: Deno.DynamicLibrary<typeof USER32>;
|
||||
try {
|
||||
lib = Deno.dlopen("user32.dll", USER32);
|
||||
} catch (e) {
|
||||
console.error(`Not centering the mouse, no user32: ${(e as Error).message}`);
|
||||
return () => {};
|
||||
}
|
||||
const user32 = lib.symbols;
|
||||
|
||||
const owner = new Uint32Array(1);
|
||||
// RECT: left, top, right, bottom
|
||||
const rect = new Int32Array(4);
|
||||
// POINT: x, y
|
||||
const point = new Int32Array(2);
|
||||
return () => {
|
||||
// chromium's windows are this process's own, like in shortcuts_windows.ts
|
||||
const window = user32.GetForegroundWindow();
|
||||
if (!window) return;
|
||||
owner[0] = 0;
|
||||
user32.GetWindowThreadProcessId(window, owner);
|
||||
if (owner[0] !== Deno.pid) return;
|
||||
if (!user32.GetClientRect(window, rect)) return;
|
||||
point[0] = (rect[0] + rect[2]) >> 1;
|
||||
point[1] = (rect[1] + rect[3]) >> 1;
|
||||
if (!user32.ClientToScreen(window, point)) return;
|
||||
user32.SetCursorPos(point[0], point[1]);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the native libraries the desktop app uses through ffi. windows comes with neither sdl3 nor openal, so the app has its
|
||||
// own in desktop/windows/, which its windows build has inside it (see tools/compile.ts), with their credits and
|
||||
// licenses in credits.txt there. elsewhere it uses the system's.
|
||||
// they're the files of the libraries' releases. openal soft's "latest" builds need the visual c++ runtime, which not
|
||||
// every windows has, its releases' bin/Win64/soft_oal.dll only needs windows' own dlls
|
||||
import { existsSync } from "@std/fs";
|
||||
import { dirname, join } from "@std/path";
|
||||
|
||||
// the library's file on each os
|
||||
export type LibraryFiles = Partial<Record<typeof Deno.build.os, string>>;
|
||||
|
||||
// throws when there's no such library. one next to the executable comes first, so players can use their own build of
|
||||
// a library the app comes with, which openal soft's license asks for
|
||||
export function open_library<const S extends Deno.ForeignLibraryInterface>(
|
||||
name: string,
|
||||
files: LibraryFiles,
|
||||
symbols: S,
|
||||
): Deno.DynamicLibrary<S>["symbols"] {
|
||||
const file = files[Deno.build.os];
|
||||
if (!file) throw new Error(`There's no ${name} for ${Deno.build.os}`);
|
||||
const beside = join(dirname(Deno.execPath()), file);
|
||||
const own = new URL(`./${Deno.build.os}/${file}`, import.meta.url);
|
||||
const path = [beside, own].find((path) => existsSync(path)) ?? file;
|
||||
return Deno.dlopen(path, symbols).symbols;
|
||||
}
|
||||
|
||||
// who made the libraries the app comes with and their licenses, for the credits. undefined when it uses the system's
|
||||
export function library_credits(): string | undefined {
|
||||
try {
|
||||
return Deno.readTextFileSync(new URL(`./${Deno.build.os}/credits.txt`, import.meta.url));
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// deno run --allow-read --allow-write desktop/linux_launcher.ts dist/bworld
|
||||
// deno desktop has no setting for chromium's command line, but its linux launcher passes its arguments on to chromium.
|
||||
// so this moves the launcher to bworld-bin and puts a script in its place that starts it with the switches webgpu
|
||||
// needs on some linux setups. run it on the app folder after deno desktop builds it; running it again does nothing
|
||||
|
||||
const SWITCHES = [
|
||||
"--enable-features=UseOzonePlatform,Vulkan,VulkanFromANGLE",
|
||||
// "--enable-unsafe-webgpu",
|
||||
"--use-angle=vulkan",
|
||||
"--ozone-platform=wayland",
|
||||
"--enable-wayland-ime",
|
||||
"--wayland-text-input-version=3",
|
||||
];
|
||||
|
||||
if (import.meta.main) {
|
||||
// on its own it's run after building for the os it's on, which only needs wrapping on linux
|
||||
if (Deno.build.os !== "linux") {
|
||||
Deno.exit(0);
|
||||
}
|
||||
const dir = Deno.args[0];
|
||||
if (!dir) {
|
||||
console.error("usage: linux_launcher.ts <app folder>, like dist/cubi");
|
||||
Deno.exit(1);
|
||||
}
|
||||
wrap_linux_launcher(dir);
|
||||
}
|
||||
|
||||
// wraps the launcher of a linux build in dir. it works from any os, see tools/desktop_all.ts, but the script is only
|
||||
// made executable on unix: zipping it from windows has to set that itself
|
||||
export function wrap_linux_launcher(dir: string) {
|
||||
const name = dir.replace(/[\/\\]+$/, "").split(/[\/\\]/).pop()!;
|
||||
const launcher = `${dir}/${name}`;
|
||||
const binary = `${launcher}-bin`;
|
||||
|
||||
// already wrapped: the launcher is a script now
|
||||
if (!is_elf(launcher)) {
|
||||
console.log(`${launcher} is already wrapped`);
|
||||
return;
|
||||
}
|
||||
|
||||
Deno.renameSync(launcher, binary);
|
||||
Deno.writeTextFileSync(
|
||||
launcher,
|
||||
`#!/bin/sh
|
||||
# starts ${name} with the chromium switches webgpu needs on some linux setups, see desktop/linux_launcher.ts.
|
||||
# CUBI_CHROMIUM_FLAGS replaces them, set it to "" to start without any
|
||||
here="$(dirname "$(readlink -f "$0")")"
|
||||
# the binary finds its runtime by its own name, which is ${name}.so and not ${name}-bin.so
|
||||
export LAUFEY_RUNTIME_PATH="$here/${name}.so"
|
||||
exec "$here/${name}-bin" \${CUBI_CHROMIUM_FLAGS-${SWITCHES.join(" ")}} "$@"
|
||||
`,
|
||||
);
|
||||
if (Deno.build.os !== "windows") {
|
||||
Deno.chmodSync(launcher, 0o755);
|
||||
}
|
||||
console.log(`Wrapped ${launcher}: ${SWITCHES.join(" ")}`);
|
||||
}
|
||||
|
||||
export function is_elf(path: string) {
|
||||
const head = new Uint8Array(4);
|
||||
const file = Deno.openSync(path);
|
||||
file.readSync(head);
|
||||
file.close();
|
||||
return head[0] === 0x7f && head[1] === 0x45 && head[2] === 0x4c && head[3] === 0x46;
|
||||
}
|
||||
+154
-85
@@ -1,94 +1,163 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/// <reference lib="deno.desktop" />
|
||||
// the desktop app: an sdl window (sdl.ts) that the client draws into with deno's own webgpu, so it plays without a
|
||||
// browser. the client runs in a worker (client/native/main.ts) loaded from the client's files like a page, and this
|
||||
// thread passes it the window's events and does what it asks, like grabbing the mouse or playing sounds (openal.ts).
|
||||
// the client's files and singleplayer are served on a local address, see app.ts
|
||||
import { join, toFileUrl } from "@std/path";
|
||||
import { desktop_app } from "./app.ts";
|
||||
import { SdlWindow } from "./sdl.ts";
|
||||
import { OpenAl } from "./openal.ts";
|
||||
import { library_credits } from "./libraries.ts";
|
||||
import type { ClientMessage, WindowMessage } from "../client/native/messages.ts";
|
||||
|
||||
// the desktop app: the web client in a bundled chromium (deno desktop's cef backend), so people whose browser has no
|
||||
// webgpu (firefox) can still play. its title screen is a main menu like luanti's: singleplayer worlds are played on
|
||||
// a game server of its own, with the mods each world picked from its data folder, see saves.ts. build it with deno
|
||||
// task desktop, see the desktop/ docs for how deno desktop works
|
||||
import { fromFileUrl, join } from "@std/path";
|
||||
import { serve_static } from "../server/host.ts";
|
||||
import { PROTOCOL_VERSION } from "../common/protocol.ts";
|
||||
import { current_client, update_client } from "./client_updates.ts";
|
||||
import { guard_shortcuts } from "./shortcuts.ts";
|
||||
import { center_mouse } from "./center_mouse.ts";
|
||||
import { data_dir, install_mods } from "./saves.ts";
|
||||
import { singleplayer_server } from "./singleplayer.ts";
|
||||
// how often the window's events are looked at, in milliseconds
|
||||
const POLL_MS = 2;
|
||||
// how often sounds are checked for having ended, in polls
|
||||
const AUDIO_POLLS = 10;
|
||||
|
||||
// where the project was built from: build/ and server_mods/ (the .cubi files) are bundled into the app with --include
|
||||
const ROOT = fromFileUrl(new URL("../", import.meta.url));
|
||||
const BUILD_DIR = join(ROOT, "build");
|
||||
const DATA_DIR = data_dir();
|
||||
install_mods(join(ROOT, "server_mods"), DATA_DIR);
|
||||
const game_window = new SdlWindow("bworld", 1280, 720);
|
||||
|
||||
// the server the address field starts with. "" leaves it empty for the player to fill in
|
||||
const config: { server?: string; client_updates?: string } = JSON.parse(
|
||||
await Deno.readTextFile(new URL("./config.json", import.meta.url)),
|
||||
);
|
||||
const default_server = Deno.env.get("CUBI_SERVER") ?? config.server ?? "";
|
||||
|
||||
// the site the client updates from, see client_updates.ts. CUBI_CLIENT_UPDATES=off plays the client the app was
|
||||
// built with (to test a local build), or it can point at a local server to test updating
|
||||
const updates_from = (Deno.env.get("CUBI_CLIENT_UPDATES") ?? config.client_updates ?? "off").replace(/\/+$/, "");
|
||||
// how long the first page waits for an update, a slower one is played next time
|
||||
const UPDATE_WAIT_MS = 3000;
|
||||
const client_options = {
|
||||
source: updates_from,
|
||||
bundled_dir: BUILD_DIR,
|
||||
cache_dir: join(DATA_DIR, "client"),
|
||||
protocol: PROTOCOL_VERSION,
|
||||
};
|
||||
const client_dir: Promise<string> = updates_from === "off" || updates_from === ""
|
||||
? Promise.resolve(BUILD_DIR)
|
||||
: Promise.race([
|
||||
update_client(client_options),
|
||||
new Promise<string>((resolve) => setTimeout(() => resolve(current_client(client_options)), UPDATE_WAIT_MS)),
|
||||
]);
|
||||
client_dir.then((dir) => console.log(`Playing the client in ${dir}`));
|
||||
|
||||
const win = new Deno.BrowserWindow({ title: "bworld", width: 1280, height: 720 });
|
||||
guard_shortcuts(win);
|
||||
|
||||
const singleplayer = singleplayer_server({
|
||||
build_dir: BUILD_DIR,
|
||||
data_dir: DATA_DIR,
|
||||
on_fatal(message) {
|
||||
console.error(message);
|
||||
alert(`The singleplayer world stopped: ${message}`);
|
||||
Deno.exit(1);
|
||||
},
|
||||
});
|
||||
|
||||
// the world gets saved before the app closes. it always exits by itself: deno desktop's own shutdown freezes on the
|
||||
// last frame when chromium's ctrl+w closed the window, and Deno.serve keeps the process alive anyway
|
||||
win.addEventListener("close", async (event) => {
|
||||
event.preventDefault();
|
||||
await singleplayer.stop();
|
||||
Deno.exit(0);
|
||||
});
|
||||
|
||||
if (Deno.env.get("DEBUG")) {
|
||||
win.openDevtools();
|
||||
// the game plays without sound when there's no openal
|
||||
let audio: OpenAl | undefined;
|
||||
try {
|
||||
audio = new OpenAl();
|
||||
} catch (e) {
|
||||
console.error(`No sound: ${(e as Error).message}`);
|
||||
}
|
||||
|
||||
// deno desktop binds this to a private local address and opens the window on it, the port given here is ignored
|
||||
Deno.serve(async (req) => {
|
||||
const url = new URL(req.url);
|
||||
if (url.pathname === "/") {
|
||||
// ?server= fills in the address field, without it the field would start with this app's own address.
|
||||
// ?singleplayer shows the main menu instead of the browser's title screen
|
||||
const start = new URL("/client/", url);
|
||||
start.searchParams.set("server", default_server);
|
||||
start.searchParams.set("singleplayer", "");
|
||||
return Response.redirect(start, 302);
|
||||
}
|
||||
// the page let go of the mouse, see center_mouse.ts
|
||||
if (url.pathname === "/desktop/center_mouse" && req.method === "POST") {
|
||||
center_mouse();
|
||||
return new Response(null, { status: 204 });
|
||||
}
|
||||
const response = await singleplayer.handle(req, url);
|
||||
if (response) return response;
|
||||
return serve_static(await client_dir, req, url);
|
||||
// the app can't go on. it says why in a message box, a packaged app has no terminal to read it in
|
||||
function fail(message: string) {
|
||||
console.error(message);
|
||||
game_window.set_grabbed(false);
|
||||
game_window.show_error("bworld", message);
|
||||
audio?.close();
|
||||
game_window.close();
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
// an error nothing caught, even a throw while starting, ends the app through fail. ending deno with it instead unloads
|
||||
// openal while its thread still plays, which crashes before the error is printed
|
||||
addEventListener("error", (event) => {
|
||||
event.preventDefault();
|
||||
fail(String(event.error?.stack ?? event.message));
|
||||
});
|
||||
addEventListener("unhandledrejection", (event) => {
|
||||
event.preventDefault();
|
||||
fail(String(event.reason?.stack ?? event.reason));
|
||||
});
|
||||
|
||||
const app = desktop_app((message) => fail(`The singleplayer world stopped: ${message}`));
|
||||
|
||||
const server = Deno.serve(
|
||||
{ hostname: "127.0.0.1", port: 0, onListen() {} },
|
||||
(req) => app.handle(req, new URL(req.url)),
|
||||
);
|
||||
const start_page = app.start_page(`http://127.0.0.1:${server.addr.port}`);
|
||||
|
||||
// what the client remembers, see Platform.storage
|
||||
const STORAGE_FILE = join(app.data_dir, "client_storage.json");
|
||||
let storage: Record<string, string> = {};
|
||||
try {
|
||||
storage = JSON.parse(Deno.readTextFileSync(STORAGE_FILE));
|
||||
} catch {
|
||||
// nothing saved yet
|
||||
}
|
||||
|
||||
let client: Worker | undefined;
|
||||
let closing = false;
|
||||
|
||||
// a fresh client, like loading the page again. the old one is gone with everything it loaded
|
||||
async function start_client(page: URL) {
|
||||
client?.terminate();
|
||||
game_window.set_grabbed(false);
|
||||
audio?.reset();
|
||||
const client_dir = await app.client_dir;
|
||||
const worker = new Worker(toFileUrl(join(client_dir, "client", "native.js")), {
|
||||
type: "module",
|
||||
deno: {
|
||||
// the servers it plays on, and its own files. ffi is for drawing into the window, it gives it up after
|
||||
permissions: { net: true, read: [client_dir], ffi: true, write: false, run: false, env: false, sys: false },
|
||||
},
|
||||
});
|
||||
worker.onmessage = (event: MessageEvent<ClientMessage>) => handle(event.data);
|
||||
worker.onerror = (event) => {
|
||||
event.preventDefault();
|
||||
fail(`The client stopped: ${event.message}`);
|
||||
};
|
||||
client = worker;
|
||||
send({
|
||||
type: "start",
|
||||
page: page.href,
|
||||
surface: game_window.surface_handles(),
|
||||
...game_window.pixel_size(),
|
||||
storage,
|
||||
audio: audio !== undefined,
|
||||
credits: library_credits(),
|
||||
});
|
||||
}
|
||||
|
||||
function send(message: WindowMessage) {
|
||||
client?.postMessage(message);
|
||||
}
|
||||
|
||||
function handle(message: ClientMessage) {
|
||||
// what it asks while the app closes, like sounds, would come after openal and the window are gone
|
||||
if (closing) return;
|
||||
switch (message.type) {
|
||||
case "grab":
|
||||
game_window.set_grabbed(message.grab);
|
||||
break;
|
||||
case "fullscreen":
|
||||
game_window.toggle_fullscreen();
|
||||
break;
|
||||
case "restart": {
|
||||
const page = new URL(message.page);
|
||||
// only its own pages
|
||||
start_client(page.origin === start_page.origin ? page : start_page);
|
||||
break;
|
||||
}
|
||||
// the client can't run at all, like without webgpu
|
||||
case "fatal":
|
||||
game_window.set_grabbed(false);
|
||||
game_window.show_error("bworld", message.message);
|
||||
close();
|
||||
break;
|
||||
case "read_clipboard":
|
||||
send({ type: "clipboard", id: message.id, text: game_window.read_clipboard() });
|
||||
break;
|
||||
case "write_clipboard":
|
||||
game_window.write_clipboard(message.text);
|
||||
break;
|
||||
case "audio":
|
||||
audio?.run(message.commands);
|
||||
break;
|
||||
case "store":
|
||||
storage[message.key] = message.value;
|
||||
Deno.writeTextFileSync(STORAGE_FILE, JSON.stringify(storage, null, "\t"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// the world gets saved before the app closes. the client isn't terminated first, exiting while a terminated worker is
|
||||
// still letting go of its webgpu surface can crash deno, exiting stops it as well
|
||||
async function close() {
|
||||
if (closing) return;
|
||||
closing = true;
|
||||
clearInterval(polling);
|
||||
await app.singleplayer.stop();
|
||||
audio?.close();
|
||||
game_window.close();
|
||||
Deno.exit(0);
|
||||
}
|
||||
|
||||
let polls = 0;
|
||||
const polling = setInterval(() => {
|
||||
game_window.poll(send, close);
|
||||
if (audio && ++polls % AUDIO_POLLS === 0) {
|
||||
const ended = audio.ended();
|
||||
if (ended.length) send({ type: "audio_ended", sources: ended });
|
||||
}
|
||||
}, POLL_MS);
|
||||
start_client(start_page);
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the desktop app's sound, with openal soft through ffi: plays what the client's web audio asks for (see
|
||||
// client/native/web_audio.ts), each of its sources an openal source. openal mixes on a thread of its own, with hrtf
|
||||
// like browsers' panners, and linear distance falloff the same as a web audio panner's
|
||||
import type { AudioCommand, SourceSettings } from "../client/native/messages.ts";
|
||||
import { type LibraryFiles, open_library } from "./libraries.ts";
|
||||
|
||||
const LIBRARY: LibraryFiles = { linux: "libopenal.so.1", windows: "OpenAL32.dll", darwin: "libopenal.1.dylib" };
|
||||
|
||||
const SYMBOLS = {
|
||||
alcOpenDevice: { parameters: ["pointer"], result: "pointer" },
|
||||
alcCloseDevice: { parameters: ["pointer"], result: "u8" },
|
||||
alcCreateContext: { parameters: ["pointer", "buffer"], result: "pointer" },
|
||||
alcDestroyContext: { parameters: ["pointer"], result: "void" },
|
||||
alcMakeContextCurrent: { parameters: ["pointer"], result: "u8" },
|
||||
alIsExtensionPresent: { parameters: ["buffer"], result: "u8" },
|
||||
alDistanceModel: { parameters: ["i32"], result: "void" },
|
||||
alGenBuffers: { parameters: ["i32", "buffer"], result: "void" },
|
||||
alDeleteBuffers: { parameters: ["i32", "buffer"], result: "void" },
|
||||
alBufferData: { parameters: ["u32", "i32", "buffer", "i32", "i32"], result: "void" },
|
||||
alGenSources: { parameters: ["i32", "buffer"], result: "void" },
|
||||
alDeleteSources: { parameters: ["i32", "buffer"], result: "void" },
|
||||
alSourcei: { parameters: ["u32", "i32", "i32"], result: "void" },
|
||||
alSourcef: { parameters: ["u32", "i32", "f32"], result: "void" },
|
||||
alSource3f: { parameters: ["u32", "i32", "f32", "f32", "f32"], result: "void" },
|
||||
alGetSourcei: { parameters: ["u32", "i32", "buffer"], result: "void" },
|
||||
alSourcePlay: { parameters: ["u32"], result: "void" },
|
||||
alSourceStop: { parameters: ["u32"], result: "void" },
|
||||
alListener3f: { parameters: ["i32", "f32", "f32", "f32"], result: "void" },
|
||||
alListenerfv: { parameters: ["i32", "buffer"], result: "void" },
|
||||
} as const;
|
||||
|
||||
const ALC_TRUE = 1;
|
||||
const ALC_HRTF_SOFT = 0x1992;
|
||||
const AL_SOURCE_RELATIVE = 0x202;
|
||||
const AL_PITCH = 0x1003;
|
||||
const AL_POSITION = 0x1004;
|
||||
const AL_LOOPING = 0x1007;
|
||||
const AL_BUFFER = 0x1009;
|
||||
const AL_GAIN = 0x100a;
|
||||
const AL_ORIENTATION = 0x100f;
|
||||
const AL_SOURCE_STATE = 0x1010;
|
||||
const AL_STOPPED = 0x1014;
|
||||
const AL_REFERENCE_DISTANCE = 0x1020;
|
||||
const AL_ROLLOFF_FACTOR = 0x1021;
|
||||
const AL_MAX_DISTANCE = 0x1023;
|
||||
const AL_SEC_OFFSET = 0x1024;
|
||||
const AL_LINEAR_DISTANCE_CLAMPED = 0xd004;
|
||||
const AL_FORMAT_MONO_FLOAT32 = 0x10010;
|
||||
const AL_FORMAT_STEREO_FLOAT32 = 0x10011;
|
||||
|
||||
// openal can't play at a pitch of 0 or less
|
||||
const MIN_PITCH = 0.001;
|
||||
|
||||
const c_string = (text: string) => new TextEncoder().encode(text + "\0");
|
||||
|
||||
// a decoded file, made into openal buffers as it's needed: mono for sounds placed somewhere, since openal only places
|
||||
// mono ones, and as many channels as it has (up to stereo) for the rest
|
||||
interface Decoded {
|
||||
channels: Float32Array[];
|
||||
sample_rate: number;
|
||||
mono?: number;
|
||||
all?: number;
|
||||
}
|
||||
|
||||
export class OpenAl {
|
||||
#al: Deno.DynamicLibrary<typeof SYMBOLS>["symbols"];
|
||||
#device: Deno.PointerObject;
|
||||
#context: Deno.PointerObject;
|
||||
#buffers = new Map<number, Decoded>();
|
||||
// the client's source ids, and the openal sources playing them
|
||||
#sources = new Map<number, { name: number; loop: boolean }>();
|
||||
#name = new Uint32Array(1);
|
||||
#state = new Int32Array(1);
|
||||
|
||||
// throws when there's no openal or no sound device
|
||||
constructor() {
|
||||
this.#al = open_library("openal", LIBRARY, SYMBOLS);
|
||||
const al = this.#al;
|
||||
const device = al.alcOpenDevice(null);
|
||||
if (!device) throw new Error("There's no sound device");
|
||||
// hrtf on speakers too, like a browser's panners
|
||||
const context = al.alcCreateContext(device, new Int32Array([ALC_HRTF_SOFT, ALC_TRUE, 0]));
|
||||
if (!context || !al.alcMakeContextCurrent(context)) {
|
||||
al.alcCloseDevice(device);
|
||||
throw new Error("Couldn't start openal");
|
||||
}
|
||||
if (!al.alIsExtensionPresent(c_string("AL_EXT_FLOAT32"))) {
|
||||
throw new Error("This openal can't play float samples");
|
||||
}
|
||||
this.#device = device;
|
||||
this.#context = context;
|
||||
al.alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
|
||||
}
|
||||
|
||||
run(commands: AudioCommand[]) {
|
||||
const al = this.#al;
|
||||
for (const command of commands) {
|
||||
switch (command.op) {
|
||||
case "buffer":
|
||||
this.#buffers.set(command.id, { channels: command.channels, sample_rate: command.sample_rate });
|
||||
break;
|
||||
case "play": {
|
||||
const decoded = this.#buffers.get(command.buffer);
|
||||
if (!decoded) break;
|
||||
al.alGenSources(1, this.#name);
|
||||
const name = this.#name[0];
|
||||
al.alSourcei(name, AL_BUFFER, this.#buffer(decoded, command.settings.at !== undefined));
|
||||
al.alSourcei(name, AL_LOOPING, command.loop ? 1 : 0);
|
||||
al.alSourcef(name, AL_SEC_OFFSET, command.offset);
|
||||
this.#set(name, command.settings);
|
||||
al.alSourcePlay(name);
|
||||
this.#sources.set(command.id, { name, loop: command.loop });
|
||||
break;
|
||||
}
|
||||
case "set": {
|
||||
const source = this.#sources.get(command.id);
|
||||
if (source) this.#set(source.name, command.settings);
|
||||
break;
|
||||
}
|
||||
case "stop":
|
||||
this.#delete_source(command.id);
|
||||
break;
|
||||
case "listener":
|
||||
al.alListener3f(AL_POSITION, ...command.position);
|
||||
al.alListenerfv(AL_ORIENTATION, new Float32Array([...command.forward, ...command.up]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#set(name: number, settings: SourceSettings) {
|
||||
const al = this.#al;
|
||||
al.alSourcef(name, AL_GAIN, Math.max(0, settings.gain));
|
||||
al.alSourcef(name, AL_PITCH, Math.max(MIN_PITCH, settings.pitch));
|
||||
// one that isn't anywhere stays on the listener, at full volume
|
||||
al.alSourcei(name, AL_SOURCE_RELATIVE, settings.at ? 0 : 1);
|
||||
al.alSource3f(name, AL_POSITION, ...settings.at ?? [0, 0, 0]);
|
||||
al.alSourcef(name, AL_ROLLOFF_FACTOR, settings.at ? settings.rolloff : 0);
|
||||
al.alSourcef(name, AL_REFERENCE_DISTANCE, settings.ref_distance);
|
||||
al.alSourcef(name, AL_MAX_DISTANCE, settings.max_distance);
|
||||
}
|
||||
|
||||
#buffer(decoded: Decoded, placed: boolean): number {
|
||||
const key = placed || decoded.channels.length === 1 ? "mono" : "all";
|
||||
const made = decoded[key];
|
||||
if (made !== undefined) return made;
|
||||
const { channels, sample_rate } = decoded;
|
||||
const length = channels[0].length;
|
||||
let samples: Float32Array;
|
||||
if (key === "mono") {
|
||||
samples = new Float32Array(length);
|
||||
for (const channel of channels) {
|
||||
for (let i = 0; i < length; i++) samples[i] += channel[i] / channels.length;
|
||||
}
|
||||
} else {
|
||||
// past stereo only the first two, cubi's sounds are mono or stereo
|
||||
samples = new Float32Array(length * 2);
|
||||
for (let i = 0; i < length; i++) {
|
||||
samples[i * 2] = channels[0][i];
|
||||
samples[i * 2 + 1] = channels[1][i];
|
||||
}
|
||||
}
|
||||
const al = this.#al;
|
||||
al.alGenBuffers(1, this.#name);
|
||||
const name = this.#name[0];
|
||||
const format = key === "mono" ? AL_FORMAT_MONO_FLOAT32 : AL_FORMAT_STEREO_FLOAT32;
|
||||
al.alBufferData(name, format, samples, samples.byteLength, sample_rate);
|
||||
decoded[key] = name;
|
||||
return name;
|
||||
}
|
||||
|
||||
#delete_source(id: number) {
|
||||
const source = this.#sources.get(id);
|
||||
if (!source) return;
|
||||
this.#sources.delete(id);
|
||||
this.#al.alSourceStop(source.name);
|
||||
this.#al.alDeleteSources(1, new Uint32Array([source.name]));
|
||||
}
|
||||
|
||||
// the sources that played to their end since the last call, by the client's ids. they're gone after
|
||||
ended(): number[] {
|
||||
const ended: number[] = [];
|
||||
for (const [id, source] of this.#sources) {
|
||||
if (source.loop) continue;
|
||||
this.#al.alGetSourcei(source.name, AL_SOURCE_STATE, this.#state);
|
||||
if (this.#state[0] === AL_STOPPED) ended.push(id);
|
||||
}
|
||||
for (const id of ended) this.#delete_source(id);
|
||||
return ended;
|
||||
}
|
||||
|
||||
// everything the client had, for a client starting over
|
||||
reset() {
|
||||
for (const id of [...this.#sources.keys()]) this.#delete_source(id);
|
||||
for (const decoded of this.#buffers.values()) {
|
||||
for (const name of [decoded.mono, decoded.all]) {
|
||||
if (name !== undefined) this.#al.alDeleteBuffers(1, new Uint32Array([name]));
|
||||
}
|
||||
}
|
||||
this.#buffers.clear();
|
||||
}
|
||||
|
||||
close() {
|
||||
this.reset();
|
||||
this.#al.alcMakeContextCurrent(null);
|
||||
this.#al.alcDestroyContext(this.#context);
|
||||
this.#al.alcCloseDevice(this.#device);
|
||||
}
|
||||
}
|
||||
+314
@@ -0,0 +1,314 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the desktop app's window, with sdl3 through ffi: its native handles for webgpu to draw into, and its events as
|
||||
// the client's messages (see client/native/messages.ts), keys named like the dom's. sdl's relative mouse mode grabs
|
||||
// the mouse, which unlike a browser's pointer lock never gets taken away by escape or held back after letting go
|
||||
import type { SurfaceHandles, WindowMessage } from "../client/native/messages.ts";
|
||||
import { type LibraryFiles, open_library } from "./libraries.ts";
|
||||
|
||||
const LIBRARY: LibraryFiles = { linux: "libSDL3.so.0", windows: "SDL3.dll", darwin: "libSDL3.0.dylib" };
|
||||
|
||||
const SYMBOLS = {
|
||||
SDL_Init: { parameters: ["u32"], result: "bool" },
|
||||
SDL_Quit: { parameters: [], result: "void" },
|
||||
SDL_GetError: { parameters: [], result: "pointer" },
|
||||
SDL_free: { parameters: ["pointer"], result: "void" },
|
||||
SDL_GetCurrentVideoDriver: { parameters: [], result: "pointer" },
|
||||
SDL_CreateWindow: { parameters: ["buffer", "i32", "i32", "u64"], result: "pointer" },
|
||||
SDL_GetWindowProperties: { parameters: ["pointer"], result: "u32" },
|
||||
SDL_GetPointerProperty: { parameters: ["u32", "buffer", "pointer"], result: "pointer" },
|
||||
SDL_GetNumberProperty: { parameters: ["u32", "buffer", "i64"], result: "i64" },
|
||||
SDL_GetWindowSizeInPixels: { parameters: ["pointer", "buffer", "buffer"], result: "bool" },
|
||||
SDL_GetWindowSize: { parameters: ["pointer", "buffer", "buffer"], result: "bool" },
|
||||
SDL_GetWindowFlags: { parameters: ["pointer"], result: "u64" },
|
||||
SDL_SetWindowFullscreen: { parameters: ["pointer", "bool"], result: "bool" },
|
||||
SDL_SetWindowRelativeMouseMode: { parameters: ["pointer", "bool"], result: "bool" },
|
||||
SDL_WarpMouseInWindow: { parameters: ["pointer", "f32", "f32"], result: "void" },
|
||||
SDL_StartTextInput: { parameters: ["pointer"], result: "bool" },
|
||||
SDL_GetModState: { parameters: [], result: "u16" },
|
||||
SDL_PollEvent: { parameters: ["buffer"], result: "bool" },
|
||||
SDL_GetClipboardText: { parameters: [], result: "pointer" },
|
||||
SDL_SetClipboardText: { parameters: ["buffer"], result: "bool" },
|
||||
SDL_ShowSimpleMessageBox: { parameters: ["u32", "buffer", "buffer", "pointer"], result: "bool" },
|
||||
} as const;
|
||||
|
||||
const INIT_VIDEO = 0x20;
|
||||
const WINDOW_FULLSCREEN = 0x1n;
|
||||
const WINDOW_RESIZABLE = 0x20n;
|
||||
const MESSAGEBOX_ERROR = 0x10;
|
||||
|
||||
const EVENT_QUIT = 0x100;
|
||||
const EVENT_WINDOW_SHOWN = 0x202;
|
||||
const EVENT_WINDOW_HIDDEN = 0x203;
|
||||
const EVENT_WINDOW_EXPOSED = 0x204;
|
||||
const EVENT_WINDOW_PIXEL_SIZE_CHANGED = 0x207;
|
||||
const EVENT_WINDOW_MINIMIZED = 0x209;
|
||||
const EVENT_WINDOW_MAXIMIZED = 0x20a;
|
||||
const EVENT_WINDOW_RESTORED = 0x20b;
|
||||
const EVENT_WINDOW_FOCUS_GAINED = 0x20e;
|
||||
const EVENT_WINDOW_FOCUS_LOST = 0x20f;
|
||||
const EVENT_WINDOW_CLOSE_REQUESTED = 0x210;
|
||||
const EVENT_WINDOW_OCCLUDED = 0x216;
|
||||
const EVENT_KEY_DOWN = 0x300;
|
||||
const EVENT_KEY_UP = 0x301;
|
||||
const EVENT_TEXT_INPUT = 0x303;
|
||||
const EVENT_MOUSE_MOTION = 0x400;
|
||||
const EVENT_MOUSE_BUTTON_DOWN = 0x401;
|
||||
const EVENT_MOUSE_BUTTON_UP = 0x402;
|
||||
const EVENT_MOUSE_WHEEL = 0x403;
|
||||
|
||||
const KMOD_CTRL = 0x00c0;
|
||||
const KMOD_ALT = 0x0300;
|
||||
const KMOD_GUI = 0x0c00;
|
||||
|
||||
// a wheel notch, in the dom's pixels
|
||||
const WHEEL_NOTCH = 100;
|
||||
|
||||
// sdl's scancodes (usb's key numbers) as the dom's KeyboardEvent.code
|
||||
const KEY_CODES: Record<number, string> = {
|
||||
40: "Enter",
|
||||
41: "Escape",
|
||||
42: "Backspace",
|
||||
43: "Tab",
|
||||
44: "Space",
|
||||
45: "Minus",
|
||||
46: "Equal",
|
||||
47: "BracketLeft",
|
||||
48: "BracketRight",
|
||||
49: "Backslash",
|
||||
50: "Backslash",
|
||||
51: "Semicolon",
|
||||
52: "Quote",
|
||||
53: "Backquote",
|
||||
54: "Comma",
|
||||
55: "Period",
|
||||
56: "Slash",
|
||||
57: "CapsLock",
|
||||
70: "PrintScreen",
|
||||
71: "ScrollLock",
|
||||
72: "Pause",
|
||||
73: "Insert",
|
||||
74: "Home",
|
||||
75: "PageUp",
|
||||
76: "Delete",
|
||||
77: "End",
|
||||
78: "PageDown",
|
||||
79: "ArrowRight",
|
||||
80: "ArrowLeft",
|
||||
81: "ArrowDown",
|
||||
82: "ArrowUp",
|
||||
83: "NumLock",
|
||||
84: "NumpadDivide",
|
||||
85: "NumpadMultiply",
|
||||
86: "NumpadSubtract",
|
||||
87: "NumpadAdd",
|
||||
88: "NumpadEnter",
|
||||
98: "Numpad0",
|
||||
99: "NumpadDecimal",
|
||||
100: "IntlBackslash",
|
||||
101: "ContextMenu",
|
||||
224: "ControlLeft",
|
||||
225: "ShiftLeft",
|
||||
226: "AltLeft",
|
||||
227: "MetaLeft",
|
||||
228: "ControlRight",
|
||||
229: "ShiftRight",
|
||||
230: "AltRight",
|
||||
231: "MetaRight",
|
||||
};
|
||||
for (let i = 0; i < 26; i++) KEY_CODES[4 + i] = `Key${String.fromCharCode(65 + i)}`;
|
||||
for (let i = 0; i < 9; i++) KEY_CODES[30 + i] = `Digit${i + 1}`;
|
||||
KEY_CODES[39] = "Digit0";
|
||||
for (let i = 0; i < 12; i++) KEY_CODES[58 + i] = `F${i + 1}`;
|
||||
for (let i = 0; i < 9; i++) KEY_CODES[89 + i] = `Numpad${i + 1}`;
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const c_string = (text: string) => encoder.encode(text + "\0");
|
||||
const read_string = (pointer: Deno.PointerValue) => pointer ? Deno.UnsafePointerView.getCString(pointer) : "";
|
||||
|
||||
export class SdlWindow {
|
||||
#sdl: Deno.DynamicLibrary<typeof SYMBOLS>["symbols"];
|
||||
#window: Deno.PointerObject;
|
||||
#event = new Uint8Array(128);
|
||||
#event_view = new DataView(this.#event.buffer);
|
||||
#relative = false;
|
||||
// the grabbed mouse's movement and the cursor's last place since the last message, sent as one
|
||||
#look = { x: 0, y: 0 };
|
||||
#cursor: { x: number; y: number } | undefined;
|
||||
|
||||
// throws when there's no sdl3 or no window can be made
|
||||
constructor(title: string, width: number, height: number) {
|
||||
this.#sdl = open_library("sdl3", LIBRARY, SYMBOLS);
|
||||
if (!this.#sdl.SDL_Init(INIT_VIDEO)) throw new Error(`Couldn't start sdl: ${this.#error()}`);
|
||||
// not high pixel density: frames are drawn at the window's size and the os scales them, like a page's canvas
|
||||
const window = this.#sdl.SDL_CreateWindow(c_string(title), width, height, WINDOW_RESIZABLE);
|
||||
if (!window) throw new Error(`Couldn't open a window: ${this.#error()}`);
|
||||
this.#window = window;
|
||||
this.#sdl.SDL_StartTextInput(window);
|
||||
}
|
||||
|
||||
#error() {
|
||||
return read_string(this.#sdl.SDL_GetError());
|
||||
}
|
||||
|
||||
// what webgpu needs to draw into the window
|
||||
surface_handles(): SurfaceHandles {
|
||||
const sdl = this.#sdl;
|
||||
const properties = sdl.SDL_GetWindowProperties(this.#window);
|
||||
const pointer = (name: string) =>
|
||||
Deno.UnsafePointer.value(sdl.SDL_GetPointerProperty(properties, c_string(name), null));
|
||||
const driver = read_string(sdl.SDL_GetCurrentVideoDriver());
|
||||
switch (driver) {
|
||||
case "wayland":
|
||||
return {
|
||||
system: "wayland",
|
||||
window: pointer("SDL.window.wayland.surface"),
|
||||
display: pointer("SDL.window.wayland.display"),
|
||||
};
|
||||
case "x11":
|
||||
return {
|
||||
system: "x11",
|
||||
window: BigInt(sdl.SDL_GetNumberProperty(properties, c_string("SDL.window.x11.window"), 0n)),
|
||||
display: pointer("SDL.window.x11.display"),
|
||||
};
|
||||
case "windows":
|
||||
return {
|
||||
system: "win32",
|
||||
window: pointer("SDL.window.win32.hwnd"),
|
||||
display: pointer("SDL.window.win32.instance"),
|
||||
};
|
||||
default:
|
||||
throw new Error(`Can't draw into ${driver} windows`);
|
||||
}
|
||||
}
|
||||
|
||||
// in pixels
|
||||
pixel_size() {
|
||||
const [width, height] = [new Int32Array(1), new Int32Array(1)];
|
||||
this.#sdl.SDL_GetWindowSizeInPixels(this.#window, width, height);
|
||||
return { width: width[0], height: height[0] };
|
||||
}
|
||||
|
||||
// the mouse turns the camera instead of moving a cursor. letting go puts the cursor in the middle
|
||||
set_grabbed(grab: boolean) {
|
||||
if (grab === this.#relative) return;
|
||||
this.#relative = grab;
|
||||
if (!grab) {
|
||||
const [width, height] = [new Int32Array(1), new Int32Array(1)];
|
||||
this.#sdl.SDL_GetWindowSize(this.#window, width, height);
|
||||
this.#sdl.SDL_WarpMouseInWindow(this.#window, width[0] / 2, height[0] / 2);
|
||||
this.#cursor = { x: width[0] / 2, y: height[0] / 2 };
|
||||
}
|
||||
this.#sdl.SDL_SetWindowRelativeMouseMode(this.#window, grab);
|
||||
}
|
||||
|
||||
toggle_fullscreen() {
|
||||
const fullscreen = (this.#sdl.SDL_GetWindowFlags(this.#window) & WINDOW_FULLSCREEN) !== 0n;
|
||||
this.#sdl.SDL_SetWindowFullscreen(this.#window, !fullscreen);
|
||||
}
|
||||
|
||||
read_clipboard(): string {
|
||||
const text = this.#sdl.SDL_GetClipboardText();
|
||||
const result = read_string(text);
|
||||
this.#sdl.SDL_free(text);
|
||||
return result;
|
||||
}
|
||||
|
||||
write_clipboard(text: string) {
|
||||
this.#sdl.SDL_SetClipboardText(c_string(text));
|
||||
}
|
||||
|
||||
show_error(title: string, text: string) {
|
||||
this.#sdl.SDL_ShowSimpleMessageBox(MESSAGEBOX_ERROR, c_string(title), c_string(text), this.#window);
|
||||
}
|
||||
|
||||
// everything that happened since the last call, as the client's messages. on_close is for the window being closed
|
||||
poll(send: (message: WindowMessage) => void, on_close: () => void) {
|
||||
const sdl = this.#sdl;
|
||||
const event = this.#event_view;
|
||||
const flush = () => {
|
||||
if (this.#look.x || this.#look.y) send({ type: "look", ...this.#look });
|
||||
if (this.#cursor) send({ type: "cursor", ...this.#cursor });
|
||||
this.#look = { x: 0, y: 0 };
|
||||
this.#cursor = undefined;
|
||||
};
|
||||
while (sdl.SDL_PollEvent(this.#event)) {
|
||||
const type = event.getUint32(0, true);
|
||||
// motion comes in often, so it's added up and sent before anything else
|
||||
if (type === EVENT_MOUSE_MOTION) {
|
||||
if (this.#relative) {
|
||||
this.#look.x += event.getFloat32(36, true);
|
||||
this.#look.y += event.getFloat32(40, true);
|
||||
} else {
|
||||
this.#cursor = { x: event.getFloat32(28, true), y: event.getFloat32(32, true) };
|
||||
}
|
||||
continue;
|
||||
}
|
||||
flush();
|
||||
switch (type) {
|
||||
case EVENT_QUIT:
|
||||
case EVENT_WINDOW_CLOSE_REQUESTED:
|
||||
on_close();
|
||||
break;
|
||||
case EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
send({ type: "resize", width: event.getInt32(20, true), height: event.getInt32(24, true) });
|
||||
break;
|
||||
case EVENT_WINDOW_FOCUS_GAINED:
|
||||
send({ type: "focus", focused: true });
|
||||
send({ type: "shown", shown: true });
|
||||
break;
|
||||
case EVENT_WINDOW_FOCUS_LOST:
|
||||
send({ type: "focus", focused: false });
|
||||
break;
|
||||
case EVENT_WINDOW_SHOWN:
|
||||
case EVENT_WINDOW_EXPOSED:
|
||||
case EVENT_WINDOW_RESTORED:
|
||||
case EVENT_WINDOW_MAXIMIZED:
|
||||
send({ type: "shown", shown: true });
|
||||
break;
|
||||
case EVENT_WINDOW_HIDDEN:
|
||||
case EVENT_WINDOW_MINIMIZED:
|
||||
case EVENT_WINDOW_OCCLUDED:
|
||||
send({ type: "shown", shown: false });
|
||||
break;
|
||||
case EVENT_KEY_DOWN:
|
||||
case EVENT_KEY_UP: {
|
||||
const code = KEY_CODES[event.getUint32(24, true)];
|
||||
if (!code) break;
|
||||
const keycode = event.getUint32(28, true);
|
||||
const shortcut = is_shortcut(event.getUint16(32, true));
|
||||
// a letter with ctrl held is a shortcut, see InputManager.key_down. typing comes as text
|
||||
const key = shortcut && keycode >= 0x20 && keycode < 0x7f ? String.fromCharCode(keycode) : "";
|
||||
send({ type: "key", down: type === EVENT_KEY_DOWN, code, key, shortcut });
|
||||
break;
|
||||
}
|
||||
case EVENT_TEXT_INPUT: {
|
||||
// ctrl+c is a shortcut, not a c
|
||||
if (is_shortcut(sdl.SDL_GetModState())) break;
|
||||
const text = Deno.UnsafePointer.create(event.getBigUint64(24, true));
|
||||
send({ type: "text", text: read_string(text) });
|
||||
break;
|
||||
}
|
||||
case EVENT_MOUSE_BUTTON_DOWN:
|
||||
case EVENT_MOUSE_BUTTON_UP:
|
||||
// sdl counts from 1: left, middle, right, back, forward. the dom from 0
|
||||
send({ type: "button", down: type === EVENT_MOUSE_BUTTON_DOWN, button: event.getUint8(24) - 1 });
|
||||
break;
|
||||
case EVENT_MOUSE_WHEEL:
|
||||
send({ type: "scroll", amount: -event.getFloat32(28, true) * WHEEL_NOTCH });
|
||||
break;
|
||||
}
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
close() {
|
||||
this.#sdl.SDL_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
// ctrl (cmd on macs) held for a shortcut, not altgr, which some systems have as ctrl+alt
|
||||
function is_shortcut(mod: number) {
|
||||
return (mod & KMOD_GUI) !== 0 || ((mod & KMOD_CTRL) !== 0 && (mod & KMOD_ALT) === 0);
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// chromium's reserved shortcuts, like ctrl+w closing the window, happen before the page can stop them. sprinting is
|
||||
// ctrl and walking is w, so the app takes those keys from the os before chromium sees them and hands them to the page.
|
||||
// how depends on the os, see shortcuts_x11.ts and shortcuts_windows.ts. macs close with cmd+w, which isn't a game key
|
||||
import { guard_shortcuts_x11 } from "./shortcuts_x11.ts";
|
||||
import { guard_shortcuts_windows } from "./shortcuts_windows.ts";
|
||||
|
||||
// the keys taken with ctrl and with ctrl+shift: their X11 key symbols, windows virtual keys, and how they reach the page
|
||||
export const KEYS: { keysym: number; vk: number; code: string; key: string; shifted_key: string }[] = [
|
||||
// close the window, ctrl+shift+w too
|
||||
{ keysym: 0x77, vk: 0x57, code: "KeyW", key: "w", shifted_key: "W" },
|
||||
// new tab, reopen a closed one
|
||||
{ keysym: 0x74, vk: 0x54, code: "KeyT", key: "t", shifted_key: "T" },
|
||||
// new window
|
||||
{ keysym: 0x6e, vk: 0x4e, code: "KeyN", key: "n", shifted_key: "N" },
|
||||
// ctrl+shift+q quits on linux
|
||||
{ keysym: 0x71, vk: 0x51, code: "KeyQ", key: "q", shifted_key: "Q" },
|
||||
// switching tabs
|
||||
{ keysym: 0xff09, vk: 0x09, code: "Tab", key: "Tab", shifted_key: "Tab" },
|
||||
{ keysym: 0xff55, vk: 0x21, code: "PageUp", key: "PageUp", shifted_key: "PageUp" },
|
||||
{ keysym: 0xff56, vk: 0x22, code: "PageDown", key: "PageDown", shifted_key: "PageDown" },
|
||||
// ctrl+f4 closes the tab on windows
|
||||
{ keysym: 0xffc1, vk: 0x73, code: "F4", key: "F4", shifted_key: "F4" },
|
||||
];
|
||||
|
||||
export type Key = typeof KEYS[number];
|
||||
|
||||
export function guard_shortcuts(win: Deno.BrowserWindow) {
|
||||
switch (Deno.build.os) {
|
||||
case "linux":
|
||||
guard_shortcuts_x11(win);
|
||||
break;
|
||||
case "windows":
|
||||
guard_shortcuts_windows(win);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// to the page as if chromium had sent it, see client/input_manager.ts
|
||||
export function send_key(win: Deno.BrowserWindow, type: "keydown" | "keyup", key: Key, ctrl: boolean, shift: boolean) {
|
||||
const init = {
|
||||
code: key.code,
|
||||
key: shift ? key.shifted_key : key.key,
|
||||
ctrlKey: ctrl,
|
||||
shiftKey: shift,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
};
|
||||
win.executeJs(`dispatchEvent(new KeyboardEvent(${JSON.stringify(type)}, ${JSON.stringify(init)}))`).catch(() => {});
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// on windows the app takes chromium's reserved shortcuts (see shortcuts.ts) as hotkeys, through user32. a hotkey takes
|
||||
// the key press before any window gets it, its release still reaches chromium. hotkeys are for the whole system, so
|
||||
// they're only registered while the app's window is in front. holding the key repeats the hotkey
|
||||
import { KEYS, send_key } from "./shortcuts.ts";
|
||||
|
||||
const MOD_CONTROL = 0x2;
|
||||
const MOD_SHIFT = 0x4;
|
||||
const WM_HOTKEY = 0x0312;
|
||||
const PM_REMOVE = 0x1;
|
||||
// MSG on 64 bit windows: hwnd, then the message, wParam (the hotkey's id) and lParam (its modifiers and virtual key)
|
||||
const MSG_SIZE = 48;
|
||||
const MSG_MESSAGE = 8;
|
||||
const MSG_LPARAM = 24;
|
||||
// how often it looks for hotkeys and which window is in front, in milliseconds
|
||||
const POLL_MS = 4;
|
||||
|
||||
const USER32 = {
|
||||
RegisterHotKey: { parameters: ["pointer", "i32", "u32", "u32"], result: "i32" },
|
||||
UnregisterHotKey: { parameters: ["pointer", "i32"], result: "i32" },
|
||||
PeekMessageW: { parameters: ["buffer", "pointer", "u32", "u32", "u32"], result: "i32" },
|
||||
GetForegroundWindow: { parameters: [], result: "pointer" },
|
||||
GetWindowThreadProcessId: { parameters: ["pointer", "buffer"], result: "u32" },
|
||||
} as const;
|
||||
|
||||
export function guard_shortcuts_windows(win: Deno.BrowserWindow) {
|
||||
let lib: Deno.DynamicLibrary<typeof USER32>;
|
||||
try {
|
||||
lib = Deno.dlopen("user32.dll", USER32);
|
||||
} catch (e) {
|
||||
console.error(`Not guarding shortcuts, no user32: ${(e as Error).message}`);
|
||||
return;
|
||||
}
|
||||
const user32 = lib.symbols;
|
||||
|
||||
// every key with ctrl and with ctrl+shift, by their ids. without a window, WM_HOTKEY goes to this thread's queue
|
||||
const hotkeys = KEYS.flatMap((key) =>
|
||||
[MOD_CONTROL, MOD_CONTROL | MOD_SHIFT].map((modifiers) => ({ key, modifiers }))
|
||||
);
|
||||
let registered = false;
|
||||
const register = () => {
|
||||
if (registered) return;
|
||||
// one already taken by another app just isn't guarded
|
||||
hotkeys.forEach(({ key, modifiers }, id) => user32.RegisterHotKey(null, id + 1, modifiers, key.vk));
|
||||
registered = true;
|
||||
};
|
||||
const unregister = () => {
|
||||
if (!registered) return;
|
||||
hotkeys.forEach((_, id) => user32.UnregisterHotKey(null, id + 1));
|
||||
registered = false;
|
||||
};
|
||||
win.addEventListener("close", unregister);
|
||||
|
||||
// the cef backend never sends focus or blur on windows, so it checks whether the window in front is the app's.
|
||||
// chromium's windows are this process's own
|
||||
const owner = new Uint32Array(1);
|
||||
const in_front = () => {
|
||||
const window = user32.GetForegroundWindow();
|
||||
if (!window) return false;
|
||||
owner[0] = 0;
|
||||
user32.GetWindowThreadProcessId(window, owner);
|
||||
return owner[0] === Deno.pid;
|
||||
};
|
||||
|
||||
const msg = new Uint8Array(MSG_SIZE);
|
||||
const view = new DataView(msg.buffer);
|
||||
setInterval(() => {
|
||||
if (in_front()) register();
|
||||
else unregister();
|
||||
while (user32.PeekMessageW(msg, null, WM_HOTKEY, WM_HOTKEY, PM_REMOVE)) {
|
||||
if (view.getUint32(MSG_MESSAGE, true) !== WM_HOTKEY) continue;
|
||||
const lparam = view.getUint32(MSG_LPARAM, true);
|
||||
const modifiers = lparam & 0xffff;
|
||||
const vk = lparam >>> 16;
|
||||
const key = KEYS.find((k) => k.vk === vk);
|
||||
if (key) send_key(win, "keydown", key, (modifiers & MOD_CONTROL) !== 0, (modifiers & MOD_SHIFT) !== 0);
|
||||
}
|
||||
}, POLL_MS);
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// on linux the app takes chromium's reserved shortcuts (see shortcuts.ts) from the x server itself, with a passive grab
|
||||
// on its window through libX11. deno desktop's chromium always runs on x11, see linux_launcher.ts. a grabbed key goes
|
||||
// to the grabbing client until it's let go, so the grab is dropped right away and the key's release and everything
|
||||
// after it reaches chromium as usual. holding it repeats the press, which is grabbed again each time
|
||||
import { type Key, KEYS, send_key } from "./shortcuts.ts";
|
||||
|
||||
const SHIFT_MASK = 1 << 0;
|
||||
const LOCK_MASK = 1 << 1;
|
||||
const CONTROL_MASK = 1 << 2;
|
||||
// num lock on most setups. a grab only matches the exact modifiers, so every lock combination gets one
|
||||
const MOD2_MASK = 1 << 4;
|
||||
const KEY_PRESS = 2;
|
||||
const KEY_RELEASE = 3;
|
||||
const GRAB_MODE_ASYNC = 1;
|
||||
const CURRENT_TIME = 0n;
|
||||
// XEvent is a union of 24 longs
|
||||
const EVENT_SIZE = 24 * 8;
|
||||
// XKeyEvent's fields on 64 bit systems
|
||||
const EVENT_STATE = 80;
|
||||
const EVENT_KEYCODE = 84;
|
||||
// how often it looks for grabbed keys, in milliseconds
|
||||
const POLL_MS = 4;
|
||||
|
||||
const X11 = {
|
||||
XOpenDisplay: { parameters: ["pointer"], result: "pointer" },
|
||||
XSetErrorHandler: { parameters: ["function"], result: "pointer" },
|
||||
XKeysymToKeycode: { parameters: ["pointer", "u64"], result: "u8" },
|
||||
XGetInputFocus: { parameters: ["pointer", "buffer", "buffer"], result: "i32" },
|
||||
XQueryTree: { parameters: ["pointer", "u64", "buffer", "buffer", "buffer", "buffer"], result: "i32" },
|
||||
XFree: { parameters: ["pointer"], result: "i32" },
|
||||
XGrabKey: { parameters: ["pointer", "i32", "u32", "u64", "i32", "i32", "i32"], result: "i32" },
|
||||
XUngrabKeyboard: { parameters: ["pointer", "u64"], result: "i32" },
|
||||
XPending: { parameters: ["pointer"], result: "i32" },
|
||||
XNextEvent: { parameters: ["pointer", "buffer"], result: "i32" },
|
||||
XFlush: { parameters: ["pointer"], result: "i32" },
|
||||
XSync: { parameters: ["pointer", "i32"], result: "i32" },
|
||||
} as const;
|
||||
|
||||
// grabs the shortcuts on the window once it has focus, which is when x11 can tell which window is the app's. nothing
|
||||
// happens without libX11
|
||||
export function guard_shortcuts_x11(win: Deno.BrowserWindow) {
|
||||
let lib: Deno.DynamicLibrary<typeof X11>;
|
||||
try {
|
||||
lib = Deno.dlopen("libX11.so.6", X11);
|
||||
} catch (e) {
|
||||
console.error(`Not guarding shortcuts, no libX11: ${(e as Error).message}`);
|
||||
return;
|
||||
}
|
||||
const x = lib.symbols;
|
||||
const display = x.XOpenDisplay(null);
|
||||
if (!display) {
|
||||
console.error("Not guarding shortcuts, no X display");
|
||||
return;
|
||||
}
|
||||
// xlib's own handler exits the process, like when another app already grabbed one of the keys
|
||||
const on_error = new Deno.UnsafeCallback({ parameters: ["pointer", "pointer"], result: "i32" }, () => 0);
|
||||
x.XSetErrorHandler(on_error.pointer);
|
||||
|
||||
const by_keycode = new Map<number, Key>();
|
||||
for (const key of KEYS) {
|
||||
const keycode = x.XKeysymToKeycode(display, BigInt(key.keysym));
|
||||
if (keycode) by_keycode.set(keycode, key);
|
||||
}
|
||||
|
||||
let grabbed = false;
|
||||
win.addEventListener("focus", () => {
|
||||
if (grabbed) return;
|
||||
const window = top_level(x, display);
|
||||
if (!window) return;
|
||||
for (const keycode of by_keycode.keys()) {
|
||||
for (const shift of [0, SHIFT_MASK]) {
|
||||
for (const locks of [0, LOCK_MASK, MOD2_MASK, LOCK_MASK | MOD2_MASK]) {
|
||||
const modifiers = CONTROL_MASK | shift | locks;
|
||||
x.XGrabKey(display, keycode, modifiers, window, 0, GRAB_MODE_ASYNC, GRAB_MODE_ASYNC);
|
||||
}
|
||||
}
|
||||
}
|
||||
x.XSync(display, 0);
|
||||
grabbed = true;
|
||||
});
|
||||
|
||||
const event = new Uint8Array(EVENT_SIZE);
|
||||
const view = new DataView(event.buffer);
|
||||
setInterval(() => {
|
||||
while (x.XPending(display) > 0) {
|
||||
x.XNextEvent(display, event);
|
||||
const type = view.getInt32(0, true);
|
||||
if (type !== KEY_PRESS && type !== KEY_RELEASE) continue;
|
||||
if (type === KEY_PRESS) {
|
||||
x.XUngrabKeyboard(display, CURRENT_TIME);
|
||||
x.XFlush(display);
|
||||
}
|
||||
const key = by_keycode.get(view.getUint32(EVENT_KEYCODE, true));
|
||||
const state = view.getUint32(EVENT_STATE, true);
|
||||
if (key) {
|
||||
const ctrl = (state & CONTROL_MASK) !== 0;
|
||||
send_key(win, type === KEY_PRESS ? "keydown" : "keyup", key, ctrl, (state & SHIFT_MASK) !== 0);
|
||||
}
|
||||
}
|
||||
}, POLL_MS);
|
||||
}
|
||||
|
||||
// the window that has focus, up to the one right under the root, which is the app's own window and not one of
|
||||
// chromium's inside it
|
||||
function top_level(x: Deno.DynamicLibrary<typeof X11>["symbols"], display: Deno.PointerObject): bigint | undefined {
|
||||
const focus = new BigUint64Array(1);
|
||||
x.XGetInputFocus(display, focus, new Int32Array(1));
|
||||
let window = focus[0];
|
||||
// None and PointerRoot
|
||||
if (window <= 1n) return undefined;
|
||||
const root = new BigUint64Array(1);
|
||||
const parent = new BigUint64Array(1);
|
||||
const children = new BigUint64Array(1);
|
||||
const count = new Uint32Array(1);
|
||||
while (true) {
|
||||
if (!x.XQueryTree(display, window, root, parent, children, count)) return undefined;
|
||||
if (children[0]) x.XFree(Deno.UnsafePointer.create(children[0]));
|
||||
if (parent[0] === root[0]) return window;
|
||||
window = parent[0];
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,503 @@
|
||||
The desktop app for Windows comes with two libraries, the same files their releases have.
|
||||
|
||||
SDL3.dll is SDL 3.4.20, from SDL3-3.4.20-win32-x64.zip at https://github.com/libsdl-org/SDL/releases/tag/release-3.4.20
|
||||
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
OpenAL32.dll is OpenAL Soft 1.25.2: bin/Win64/soft_oal.dll from openal-soft-1.25.2-bin.zip at https://github.com/kcat/openal-soft/releases/tag/1.25.2, renamed. Its source is at https://github.com/kcat/openal-soft/tree/1.25.2
|
||||
|
||||
OpenAL Soft is copyright (C) 1999-2007 by its authors. It's free software under the GNU Library General Public License as published by the Free Software Foundation, version 2 of the License or (at your option) any later version, which follows below. The game can use your own build of it instead: put it next to the game's executable, named OpenAL32.dll.
|
||||
|
||||
A modified PFFFT is included, with the following license.
|
||||
|
||||
Copyright (c) 2023 Christopher Robinson
|
||||
|
||||
Copyright (c) 2013 Julien Pommier ( pommier@modartt.com )
|
||||
|
||||
Copyright (c) 2004 the University Corporation for Atmospheric
|
||||
Research ("UCAR"). All rights reserved. Developed by NCAR's
|
||||
Computational and Information Systems Laboratory, UCAR,
|
||||
www.cisl.ucar.edu.
|
||||
|
||||
Redistribution and use of the Software in source and binary forms,
|
||||
with or without modification, is permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
- Neither the names of NCAR's Computational and Information Systems
|
||||
Laboratory, the University Corporation for Atmospheric Research,
|
||||
nor the names of its sponsors or contributors may be used to
|
||||
endorse or promote products derived from this Software without
|
||||
specific prior written permission.
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notices, this list of conditions, and the disclaimer below.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions, and the disclaimer below in the
|
||||
documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
|
||||
SOFTWARE.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the library GPL. It is
|
||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Library General Public License, applies to some
|
||||
specially designated Free Software Foundation software, and to any
|
||||
other libraries whose authors decide to use it. You can use it for
|
||||
your libraries, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if
|
||||
you distribute copies of the library, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link a program with the library, you must provide
|
||||
complete object files to the recipients so that they can relink them
|
||||
with the library, after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
Our method of protecting your rights has two steps: (1) copyright
|
||||
the library, and (2) offer you this license which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
Also, for each distributor's protection, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
library. If the library is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original
|
||||
version, so that any problems introduced by others will not reflect on
|
||||
the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that companies distributing free
|
||||
software will individually obtain patent licenses, thus in effect
|
||||
transforming the program into proprietary software. To prevent this,
|
||||
we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary
|
||||
GNU General Public License, which was designed for utility programs. This
|
||||
license, the GNU Library General Public License, applies to certain
|
||||
designated libraries. This license is quite different from the ordinary
|
||||
one; be sure to read it in full, and don't assume that anything in it is
|
||||
the same as in the ordinary license.
|
||||
|
||||
The reason we have a separate public license for some libraries is that
|
||||
they blur the distinction we usually make between modifying or adding to a
|
||||
program and simply using it. Linking a program with a library, without
|
||||
changing the library, is in some sense simply using the library, and is
|
||||
analogous to running a utility program or application program. However, in
|
||||
a textual and legal sense, the linked executable is a combined work, a
|
||||
derivative of the original library, and the ordinary General Public License
|
||||
treats it as such.
|
||||
|
||||
Because of this blurred distinction, using the ordinary General
|
||||
Public License for libraries did not effectively promote software
|
||||
sharing, because most developers did not use the libraries. We
|
||||
concluded that weaker conditions might promote sharing better.
|
||||
|
||||
However, unrestricted linking of non-free programs would deprive the
|
||||
users of those programs of all benefit from the free status of the
|
||||
libraries themselves. This Library General Public License is intended to
|
||||
permit developers of non-free programs to use free libraries, while
|
||||
preserving your freedom as a user of such programs to change the free
|
||||
libraries that are incorporated in them. (We have not seen how to achieve
|
||||
this as regards changes in header files, but we have achieved it as regards
|
||||
changes in the actual functions of the Library.) The hope is that this
|
||||
will lead to faster development of free libraries.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, while the latter only
|
||||
works together with the library.
|
||||
|
||||
Note that it is possible for a library to be covered by the ordinary
|
||||
General Public License rather than by this special one.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library which
|
||||
contains a notice placed by the copyright holder or other authorized
|
||||
party saying it may be distributed under the terms of this Library
|
||||
General Public License (also called "this License"). Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also compile or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
c) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
d) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the source code distributed need not include anything that is normally
|
||||
distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Library General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -42,19 +42,20 @@ showed. These events fire for **every** player's actions, since they all go thro
|
||||
|
||||
## The Events
|
||||
|
||||
| Event | Before | After | Fields |
|
||||
| ---------------- | ------ | ----- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `block_break` | ✓ | ✓ | `player`, `block` (with its tile `data`), `item` held |
|
||||
| `block_place` | ✓ | ✓ | `player`, `block` (`{ id, x, y, z }`), `face` clicked, `hit` where on it (0-1 each axis), `item` held |
|
||||
| `block_interact` | ✓ | ✓ | `player`, `block`, `item` held. Before fires for every right click on a block, after only when a component's `on_interact` handled it |
|
||||
| `chat_send` | ✓ | ✓ | `player`, `message`. Before handlers can change `message` |
|
||||
| `entity_damage` | ✓ | ✓ | `entity`, `player`, `amount`, `cause`, `bypasses_invulnerability`. See below |
|
||||
| `player_death` | | ✓ | `player`, `cause`. They've dropped what they carried and respawn right after |
|
||||
| `player_join` | | ✓ | `player` |
|
||||
| `player_leave` | | ✓ | `player` |
|
||||
| `server_start` | | ✓ | none. Every mod's server phase has run |
|
||||
| `tick` | | ✓ | `dt`, in seconds. 20 times a second |
|
||||
| `new_day` | | ✓ | `day`. At 06:00, after every block's `on_new_day` |
|
||||
| Event | Before | After | Fields |
|
||||
| ----------------- | ------ | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `block_break` | ✓ | ✓ | `player`, `block` (with its tile `data`), `item` held |
|
||||
| `block_place` | ✓ | ✓ | `player`, `block` (`{ id, x, y, z }`), `face` clicked, `hit` where on it (0-1 each axis), `item` held |
|
||||
| `block_interact` | ✓ | ✓ | `player`, `block`, `item` held. Before fires for every right click on a block, after only when a component's `on_interact` handled it |
|
||||
| `entity_interact` | ✓ | | `player`, `entity` right clicked, `item` held. Cancelling it stops the held item being used, see [Interacting](../entities/index.md#interacting) |
|
||||
| `chat_send` | ✓ | ✓ | `player`, `message`. Before handlers can change `message` |
|
||||
| `entity_damage` | ✓ | ✓ | `entity`, `player`, `amount`, `cause`, `bypasses_invulnerability`. See below |
|
||||
| `player_death` | | ✓ | `player`, `cause`. They've dropped what they carried and respawn right after |
|
||||
| `player_join` | | ✓ | `player` |
|
||||
| `player_leave` | | ✓ | `player` |
|
||||
| `server_start` | | ✓ | none. Every mod's server phase has run |
|
||||
| `tick` | | ✓ | `dt`, in seconds. 20 times a second |
|
||||
| `new_day` | | ✓ | `day`. At 06:00, after every block's `on_new_day` |
|
||||
|
||||
`cause` is `"fall"`, `"void"`, `"starve"`, `"mob_attack"`, or whatever a mod passed to `damage(amount, cause)`.
|
||||
|
||||
|
||||
@@ -25,9 +25,10 @@ and players. Mods define new kinds in their `entities/` folder, and draw them wi
|
||||
| Field | Default | Meaning |
|
||||
| -------------------- | ---------- | ------------------------------------------------------------------------------------------------------ |
|
||||
| `id` | required | The entity's id. |
|
||||
| `texture` | required | Any texture, stretched over the model's `texture_width` and `texture_height`. |
|
||||
| `texture` | required | Any texture, stretched over the model's `texture_width` and `texture_height`. An object needs none. |
|
||||
| `model` | none | An [entity model](#entity-models). Without one it's drawn as its texture, facing the camera. |
|
||||
| `behavior` | `"animal"` | `"animal"`, `"monster"`, `"scripted"`, or a [custom behavior](#custom-behaviors)'s id. |
|
||||
| `behavior` | `"animal"` | `"animal"`, `"monster"`, `"scripted"`, `"object"`, or a [custom behavior](#custom-behaviors)'s id. |
|
||||
| `scale` | `1` | How much bigger it's drawn than its model, texture or item. Its box stays `width` and `height`. |
|
||||
| `category` | see below | `"monster"` or `"creature"`, see [Natural Spawning](#natural-spawning). |
|
||||
| `width`, `height` | required | Its collision box in blocks, up to 16. `width` is for both x and z. Its eyes are at 85% of the height. |
|
||||
| `max_health` | `10` | In half hearts. |
|
||||
@@ -92,6 +93,49 @@ the world, so a script never finds one it doesn't know about after a restart. Th
|
||||
}
|
||||
```
|
||||
|
||||
**Objects** lie around like a dropped item, holding one: they fall, slide and float in water the same way, but nobody
|
||||
picks them up by walking into them, and they never despawn or merge. They can't be hurt, don't think, don't stop blocks
|
||||
being placed where they are, and are saved with the world with what they hold. Without a `model`, an object is drawn as
|
||||
its item: the item's [model](../resources/models.md#entity-models-as-items) at the size it's made, times `scale`, turned
|
||||
the way the object faces.
|
||||
|
||||
An item lies around as an object instead of a dropped item when it names one as its
|
||||
[`entity`](../items/index.md#properties), like NeoForge's `hasCustomEntity`. Every way an item ends up in the world
|
||||
spawns the object holding it: thrown, dropped when its holder dies or when it doesn't fit, popped out of a broken block,
|
||||
or a script's `spawn_item` or `drop_item`. Dangerous Business's scrap is one, picked up by right clicking it (see
|
||||
[Interacting](#interacting)):
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"entity": {
|
||||
"id": "dangerous_business:scrap",
|
||||
"behavior": "object",
|
||||
"width": 0.7,
|
||||
"height": 0.7,
|
||||
"scale": 0.7
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Interacting
|
||||
|
||||
Right clicking an entity from up to 3 blocks away fires [`before.entity_interact`](../concepts/events.md#the-events),
|
||||
like NeoForge's `PlayerInteractEvent.EntityInteract`. Its handlers do whatever the click does and cancel it, otherwise
|
||||
the held item is used as if clicking nothing. A handler can also leave the entity be, like scrap with nowhere to go:
|
||||
|
||||
```ts
|
||||
ctx.events.before.entity_interact.subscribe((event) => {
|
||||
if (event.entity.type !== "dangerous_business:scrap") return;
|
||||
event.cancel = true;
|
||||
const item = event.entity.get_item();
|
||||
const slot = [0, 1, 2, 3].find((slot) => event.player.inventory.get(slot) === undefined);
|
||||
if (!item || slot === undefined) return;
|
||||
event.player.inventory.set(slot, item);
|
||||
event.entity.remove();
|
||||
});
|
||||
```
|
||||
|
||||
## Custom Behaviors
|
||||
|
||||
A mob can get its goals from a script instead, like NeoForge's `registerGoals`. Its json names a behavior id, and the
|
||||
@@ -288,8 +332,8 @@ interface EntityRef {
|
||||
push(x: number, y: number, z: number): void; // adds to its velocity
|
||||
remove(): void;
|
||||
kill(cause?: string): void; // players and mobs die, anything else is removed
|
||||
get_item(): ItemStack | undefined; // for an item lying around, a copy
|
||||
set_item(item: ItemStack | undefined): void; // for an item lying around, undefined takes it away
|
||||
get_item(): ItemStack | undefined; // for an item lying around or what an object holds, a copy
|
||||
set_item(item: ItemStack | undefined): void; // undefined takes an item lying around away, an object holds nothing
|
||||
}
|
||||
```
|
||||
|
||||
@@ -330,7 +374,8 @@ get the id `<mod id>:<name>`. From the file's first geometry, bworld uses:
|
||||
|
||||
- the description's `texture_width` and `texture_height`,
|
||||
- each bone's `name`, `parent`, `pivot` and `rotation`,
|
||||
- each cube's `origin`, `size`, `uv`, `inflate`, `pivot` and `rotation`.
|
||||
- each cube's `origin`, `size`, `uv`, `inflate`, `pivot` and `rotation`,
|
||||
- `item_display_transforms`, for an [item drawn with it](../resources/models.md#entity-models-as-items).
|
||||
|
||||
Cubes can use box UV (`"uv": [u, v]`) or per face UV (`"uv": { "north": { "uv": [u, v], "uv_size": [w, h] }, ... }`),
|
||||
where a face that's left out isn't drawn and a negative size flips it. Faces are drawn from both sides, like Bedrock's
|
||||
|
||||
+19
-18
@@ -42,24 +42,25 @@ down to 0 is gone.
|
||||
|
||||
## Properties
|
||||
|
||||
| Field | Default | Meaning |
|
||||
| ----------------- | ------------------- | -------------------------------------------------------------------------------------- |
|
||||
| `id` | required | The item's id. |
|
||||
| `texture` | required | The texture it's drawn with. Leave it out to [fill in a block's item](#block-items). |
|
||||
| `name` | from the id | What players see. `copper_tools:copper_ingot` is "Copper Ingot" when not set. |
|
||||
| `lore` | none | Tooltip text under the name. `\n` starts a new line. |
|
||||
| `max_stack` | `64`, `1` for tools | How many fit in one slot. |
|
||||
| `base_sell_value` | none | What one is worth when sold, a whole number of 0 or more. |
|
||||
| `places` | none | A block it places when used on a block, like seeds. |
|
||||
| `tool` | none | Makes it a [tool](tools.md). |
|
||||
| `food` | none | Makes it [edible](food.md). |
|
||||
| `data_textures` | none | Other textures, picked by the stack's `data`, see below. |
|
||||
| `model` | none | A [model](../resources/models.md#item-models) it's drawn with instead of its texture. |
|
||||
| `worn` | none | How it looks worn on a player, see [below](#worn-models). |
|
||||
| `targets_fluids` | `false` | Players holding it aim at fluids, like buckets and fishing rods. Others aim through. |
|
||||
| `fluid_container` | none | Makes it hold a fluid, like a bucket, see [Fluids](../resources/fluids.md#containers). |
|
||||
| `layers` | none | Textures drawn over its own, each in a color, see [below](#layers). |
|
||||
| `components` | none | [Item components](#item-components) and their parameters. |
|
||||
| Field | Default | Meaning |
|
||||
| ----------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `id` | required | The item's id. |
|
||||
| `texture` | required | The texture it's drawn with. Leave it out to [fill in a block's item](#block-items). |
|
||||
| `name` | from the id | What players see. `copper_tools:copper_ingot` is "Copper Ingot" when not set. |
|
||||
| `lore` | none | Tooltip text under the name. `\n` starts a new line. |
|
||||
| `max_stack` | `64`, `1` for tools | How many fit in one slot. |
|
||||
| `base_sell_value` | none | What one is worth when sold, a whole number of 0 or more. |
|
||||
| `places` | none | A block it places when used on a block, like seeds. |
|
||||
| `tool` | none | Makes it a [tool](tools.md). |
|
||||
| `food` | none | Makes it [edible](food.md). |
|
||||
| `data_textures` | none | Other textures, picked by the stack's `data`, see below. |
|
||||
| `model` | none | A [model](../resources/models.md#item-models) it's drawn with instead of its texture, or an [entity model](../resources/models.md#entity-models-as-items). |
|
||||
| `worn` | none | How it looks worn on a player, see [below](#worn-models). |
|
||||
| `entity` | none | An [object](../entities/index.md#behaviors) it lies in the world as instead of a dropped item, holding the stack. |
|
||||
| `targets_fluids` | `false` | Players holding it aim at fluids, like buckets and fishing rods. Others aim through. |
|
||||
| `fluid_container` | none | Makes it hold a fluid, like a bucket, see [Fluids](../resources/fluids.md#containers). |
|
||||
| `layers` | none | Textures drawn over its own, each in a color, see [below](#layers). |
|
||||
| `components` | none | [Item components](#item-components) and their parameters. |
|
||||
|
||||
### Textures From Data
|
||||
|
||||
|
||||
@@ -88,6 +88,13 @@ const doorways = room.blocks.filter((block) => room.palette[block.i].id === "cop
|
||||
|
||||
Positions in it are from its lowest corner, before it's turned. Changing the copy doesn't change what `place` puts.
|
||||
|
||||
`ids` gives every registered schematic's id, the files' and the ones scripts registered, in the order they were
|
||||
registered, like for a tool that lets players pick one:
|
||||
|
||||
```ts
|
||||
const rooms = ctx.schematics.ids().filter((id) => id.startsWith("copper_tools:room_"));
|
||||
```
|
||||
|
||||
Until `import_data` is built, a block's exported data goes back in as it is, so a chest placed from a schematic has its
|
||||
items' list in its data and no container.
|
||||
|
||||
|
||||
@@ -236,6 +236,17 @@ the same places Minecraft's do, so a transform made for Minecraft, like in Block
|
||||
here. A model gets its parent's transform for each place it doesn't set its own. Minecraft's other places, like third
|
||||
person, aren't used.
|
||||
|
||||
### Entity Models as Items
|
||||
|
||||
An item's `model` can also be an [entity model](../entities/index.md#entity-models), a `models/<name>.geo.json` made in
|
||||
Blockbench, drawn in the item's own `texture` laid out for the model's `texture_width` and `texture_height`. It stands
|
||||
in the middle of the block the way Blockbench shows it, 16 pixels to a block with its bottom at 0, and its faces are
|
||||
shaded like a block model's. Its pose is the one in the file, bones aren't animated.
|
||||
|
||||
Its display transforms are the geometry's `item_display_transforms`, which Blockbench's Display tab writes for the
|
||||
"Bedrock Block" format. Only `rotation`, `translation` and `scale` of the places above are used: `rotation_pivot`,
|
||||
`scale_pivot` and `fit_to_frame` aren't.
|
||||
|
||||
## Lighting
|
||||
|
||||
Faces flat against the block's edge get smooth lighting and ambient occlusion like a full block's. Anything inside the
|
||||
|
||||
@@ -431,7 +431,6 @@ saved before any of this plays exactly the same.
|
||||
- **Importing Minecraft's terrain.** Datapacks' noise settings assume a world from -64 to 320 and Minecraft's noises.
|
||||
The formats are close enough that an importer could translate them, but the result wouldn't look like Minecraft's. Not
|
||||
a goal for now.
|
||||
- **Generation's loose ends.** The packaged desktop build hasn't been tried with the worldgen worker, which the desktop
|
||||
task includes. In a world without land, the spawn search looks 32 chunks out on the game thread, which the server now
|
||||
does at startup. Saved chunks are read on the game thread, which waits for the host (see `read_chunk` in
|
||||
`server/game/worker.ts`): much faster than generating them, but Minecraft reads them ahead instead.
|
||||
- **Generation's loose ends.** In a world without land, the spawn search looks 32 chunks out on the game thread, which
|
||||
the server now does at startup. Saved chunks are read on the game thread, which waits for the host (see `read_chunk`
|
||||
in `server/game/worker.ts`): much faster than generating them, but Minecraft reads them ahead instead.
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:chain",
|
||||
"textures": { "chain": "dangerous_business:iron_chain" },
|
||||
"model": "dangerous_business:chain",
|
||||
"render_layer": "cutout",
|
||||
"shape": [[6.5, 0, 6.5, 9.5, 16, 9.5]]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:deepslate_tile_wall",
|
||||
"textures": {
|
||||
"wall": "dangerous_business:deepslate_tiles"
|
||||
},
|
||||
"render_layer": "cutout",
|
||||
"item_model": "dangerous_business:wall_inventory",
|
||||
"states": [
|
||||
{
|
||||
"name": "north",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "east",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "south",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "west",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"parts": [
|
||||
{
|
||||
"model": "dangerous_business:template_wall_post"
|
||||
},
|
||||
{
|
||||
"when": "north=1",
|
||||
"model": "dangerous_business:template_wall_side"
|
||||
},
|
||||
{
|
||||
"when": "east=1",
|
||||
"model": "dangerous_business:template_wall_side",
|
||||
"y": 90
|
||||
},
|
||||
{
|
||||
"when": "south=1",
|
||||
"model": "dangerous_business:template_wall_side",
|
||||
"y": 180
|
||||
},
|
||||
{
|
||||
"when": "west=1",
|
||||
"model": "dangerous_business:template_wall_side",
|
||||
"y": 270
|
||||
}
|
||||
],
|
||||
"components": {
|
||||
"dangerous_business:connects": {
|
||||
"solid": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:iron_bars",
|
||||
"textures": {
|
||||
"pane": "dangerous_business:iron_bars",
|
||||
"edge": "dangerous_business:iron_bars"
|
||||
},
|
||||
"render_layer": "cutout",
|
||||
"states": [
|
||||
{
|
||||
"name": "north",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "east",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "south",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "west",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"parts": [
|
||||
{
|
||||
"model": "dangerous_business:template_glass_pane_post"
|
||||
},
|
||||
{
|
||||
"when": "north=1",
|
||||
"model": "dangerous_business:template_glass_pane_side"
|
||||
},
|
||||
{
|
||||
"when": "north=0",
|
||||
"model": "dangerous_business:template_glass_pane_noside"
|
||||
},
|
||||
{
|
||||
"when": "east=1",
|
||||
"model": "dangerous_business:template_glass_pane_side",
|
||||
"y": 90
|
||||
},
|
||||
{
|
||||
"when": "east=0",
|
||||
"model": "dangerous_business:template_glass_pane_noside",
|
||||
"y": 90
|
||||
},
|
||||
{
|
||||
"when": "south=1",
|
||||
"model": "dangerous_business:template_glass_pane_side",
|
||||
"y": 180
|
||||
},
|
||||
{
|
||||
"when": "south=0",
|
||||
"model": "dangerous_business:template_glass_pane_noside",
|
||||
"y": 180
|
||||
},
|
||||
{
|
||||
"when": "west=1",
|
||||
"model": "dangerous_business:template_glass_pane_side",
|
||||
"y": 270
|
||||
},
|
||||
{
|
||||
"when": "west=0",
|
||||
"model": "dangerous_business:template_glass_pane_noside",
|
||||
"y": 270
|
||||
}
|
||||
],
|
||||
"components": {
|
||||
"dangerous_business:connects": {
|
||||
"solid": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:iron_block",
|
||||
"textures": "dangerous_business:iron_block"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:polished_andesite",
|
||||
"textures": "dangerous_business:polished_andesite"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:purpur_stairs",
|
||||
"textures": "dangerous_business:purpur_block",
|
||||
"render_layer": "cutout",
|
||||
"model": "dangerous_business:empty",
|
||||
"item_model": "dangerous_business:stairs",
|
||||
"shape": [
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
16,
|
||||
8,
|
||||
16
|
||||
],
|
||||
[
|
||||
8,
|
||||
8,
|
||||
0,
|
||||
16,
|
||||
16,
|
||||
16
|
||||
]
|
||||
],
|
||||
"states": [
|
||||
{
|
||||
"name": "facing",
|
||||
"bits": 2,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "half",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"variants": {
|
||||
"facing=0": {
|
||||
"y": 270
|
||||
},
|
||||
"facing=2": {
|
||||
"y": 90
|
||||
},
|
||||
"facing=3": {
|
||||
"y": 180
|
||||
},
|
||||
"half=1": {
|
||||
"shape": [
|
||||
[
|
||||
0,
|
||||
8,
|
||||
0,
|
||||
16,
|
||||
16,
|
||||
16
|
||||
],
|
||||
[
|
||||
8,
|
||||
0,
|
||||
0,
|
||||
16,
|
||||
8,
|
||||
16
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:smooth_sandstone_stairs",
|
||||
"textures": "dangerous_business:smooth_sandstone",
|
||||
"render_layer": "cutout",
|
||||
"model": "dangerous_business:stairs",
|
||||
"item_model": "dangerous_business:stairs",
|
||||
"states": [
|
||||
{
|
||||
"name": "facing",
|
||||
"bits": 2,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "half",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"variants": {
|
||||
"facing=0": {
|
||||
"y": 270,
|
||||
"uvlock": true
|
||||
},
|
||||
"facing=2": {
|
||||
"y": 90,
|
||||
"uvlock": true
|
||||
},
|
||||
"facing=3": {
|
||||
"y": 180,
|
||||
"uvlock": true
|
||||
},
|
||||
"half=1": {
|
||||
"x": 180,
|
||||
"uvlock": true,
|
||||
"shape": [
|
||||
[
|
||||
0,
|
||||
8,
|
||||
0,
|
||||
16,
|
||||
16,
|
||||
16
|
||||
],
|
||||
[
|
||||
8,
|
||||
0,
|
||||
0,
|
||||
16,
|
||||
8,
|
||||
16
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:spruce_fence",
|
||||
"textures": {
|
||||
"side": "dangerous_business:spruce_fence_side",
|
||||
"top": "dangerous_business:spruce_fence_side"
|
||||
},
|
||||
"item_model": "dangerous_business:fence_inventory",
|
||||
"render_layer": "cutout",
|
||||
"states": [
|
||||
{
|
||||
"name": "north",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "east",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "south",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "west",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"parts": [
|
||||
{
|
||||
"model": "dangerous_business:fence_post",
|
||||
"shape": [
|
||||
[
|
||||
6,
|
||||
0,
|
||||
6,
|
||||
10,
|
||||
16,
|
||||
10
|
||||
]
|
||||
],
|
||||
"collision_shape": [
|
||||
[
|
||||
6,
|
||||
0,
|
||||
6,
|
||||
10,
|
||||
24,
|
||||
10
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"when": "north=1",
|
||||
"model": "dangerous_business:fence_side",
|
||||
"shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
16,
|
||||
9
|
||||
]
|
||||
],
|
||||
"collision_shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
24,
|
||||
9
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"when": "east=1",
|
||||
"model": "dangerous_business:fence_side",
|
||||
"shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
16,
|
||||
9
|
||||
]
|
||||
],
|
||||
"collision_shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
24,
|
||||
9
|
||||
]
|
||||
],
|
||||
"y": 90
|
||||
},
|
||||
{
|
||||
"when": "south=1",
|
||||
"model": "dangerous_business:fence_side",
|
||||
"shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
16,
|
||||
9
|
||||
]
|
||||
],
|
||||
"collision_shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
24,
|
||||
9
|
||||
]
|
||||
],
|
||||
"y": 180
|
||||
},
|
||||
{
|
||||
"when": "west=1",
|
||||
"model": "dangerous_business:fence_side",
|
||||
"shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
16,
|
||||
9
|
||||
]
|
||||
],
|
||||
"collision_shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
24,
|
||||
9
|
||||
]
|
||||
],
|
||||
"y": 270
|
||||
}
|
||||
],
|
||||
"components": {
|
||||
"dangerous_business:connects": {
|
||||
"solid": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"block": {
|
||||
"id": "dangerous_business:stair_rail_collision",
|
||||
"textures": "cubi:missing",
|
||||
"render_layer": "cutout",
|
||||
"model": "dangerous_business:empty",
|
||||
"item_model": "cubi:cube",
|
||||
"shape": [
|
||||
[
|
||||
0,
|
||||
0,
|
||||
14,
|
||||
16,
|
||||
16,
|
||||
16
|
||||
]
|
||||
],
|
||||
"states": [
|
||||
{
|
||||
"name": "facing",
|
||||
"bits": 2,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"variants": {
|
||||
"facing=0": {
|
||||
"y": 180
|
||||
},
|
||||
"facing=1": {
|
||||
"y": 270
|
||||
},
|
||||
"facing=3": {
|
||||
"y": 90
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,47 @@
|
||||
"render_layer": "cutout",
|
||||
"model": "dangerous_business:tiny_pipe",
|
||||
"item_model": "dangerous_business:tiny_pipe",
|
||||
"shape": [[7, 0, 7, 9, 16, 9]],
|
||||
"shape": [
|
||||
[
|
||||
7,
|
||||
0,
|
||||
7,
|
||||
9,
|
||||
16,
|
||||
9
|
||||
]
|
||||
],
|
||||
"components": {
|
||||
"dangerous_business:pipe": {}
|
||||
},
|
||||
"states": [
|
||||
{
|
||||
"name": "facing",
|
||||
"bits": 2,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "horizontal",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"variants": {
|
||||
"horizontal=1,facing=0": {
|
||||
"x": 90
|
||||
},
|
||||
"horizontal=1,facing=1": {
|
||||
"x": 90,
|
||||
"y": 90
|
||||
},
|
||||
"horizontal=1,facing=2": {
|
||||
"x": 90,
|
||||
"y": 180
|
||||
},
|
||||
"horizontal=1,facing=3": {
|
||||
"x": 90,
|
||||
"y": 270
|
||||
},
|
||||
"facing=0": {
|
||||
"y": 180
|
||||
},
|
||||
|
||||
@@ -8,7 +8,16 @@
|
||||
"render_layer": "cutout",
|
||||
"model": "dangerous_business:tiny_pipe_curve",
|
||||
"item_model": "dangerous_business:tiny_pipe_curve",
|
||||
"shape": [[7, 0, 0, 9, 9, 9]],
|
||||
"shape": [
|
||||
[
|
||||
7,
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
16,
|
||||
9
|
||||
]
|
||||
],
|
||||
"states": [
|
||||
{
|
||||
"name": "facing",
|
||||
|
||||
@@ -8,7 +8,16 @@
|
||||
"render_layer": "cutout",
|
||||
"model": "dangerous_business:tiny_pipe_curve4",
|
||||
"item_model": "dangerous_business:tiny_pipe_curve4",
|
||||
"shape": [[7, 0, 0, 16, 9, 9]],
|
||||
"shape": [
|
||||
[
|
||||
7,
|
||||
7,
|
||||
0,
|
||||
16,
|
||||
16,
|
||||
9
|
||||
]
|
||||
],
|
||||
"states": [
|
||||
{
|
||||
"name": "facing",
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"entity": {
|
||||
"id": "dangerous_business:scrap",
|
||||
"behavior": "object",
|
||||
"width": 0.7,
|
||||
"height": 0.7,
|
||||
"scale": 0.7
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "dangerous_business:air_horn",
|
||||
"texture": "dangerous_business:air_horn",
|
||||
"model": "dangerous_business:air_horn",
|
||||
"entity": "dangerous_business:scrap",
|
||||
"max_stack": 1
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.air_horn",
|
||||
"texture_width": 48,
|
||||
"texture_height": 48,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "air_horn",
|
||||
"pivot": [0, 2.375, 3],
|
||||
"rotation": [-70, 0, 90],
|
||||
"cubes": [
|
||||
{"origin": [-2.5, -7, 2], "size": [5, 9, 5], "uv": [0, 0]},
|
||||
{"origin": [-1.5, 2, 3], "size": [3, 4, 3], "uv": [20, 0]},
|
||||
{"origin": [-1, 3, 1], "size": [2, 2, 7], "uv": [0, 14]},
|
||||
{"origin": [-2, 2, -4], "size": [4, 4, 5], "uv": [18, 14]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.air_horn",
|
||||
"texture_width": 48,
|
||||
"texture_height": 48,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "air_horn",
|
||||
"pivot": [0, 2.375, 3],
|
||||
"rotation": [-70, 0, 90],
|
||||
"cubes": [
|
||||
{ "origin": [-2.5, -7, 2], "size": [5, 9, 5], "uv": [0, 0] },
|
||||
{ "origin": [-1.5, 2, 3], "size": [3, 4, 3], "uv": [20, 0] },
|
||||
{ "origin": [-1, 3, 1], "size": [2, 2, 7], "uv": [0, 14] },
|
||||
{ "origin": [-2, 2, -4], "size": [4, 4, 5], "uv": [18, 14] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,57 +1,84 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.apparatus",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "root",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-3, 2, -8], "size": [6, 6, 10], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "prongs",
|
||||
"parent": "root",
|
||||
"pivot": [-2, 5, 7],
|
||||
"cubes": [
|
||||
{"origin": [-0.5, 1, -8], "size": [1, 0, 10], "pivot": [0, 5, -3], "rotation": [0, 0, -90], "uv": [14, 0]},
|
||||
{"origin": [-0.5, 1, -8], "size": [1, 0, 10], "pivot": [0, 5, -3], "rotation": [0, 0, 90], "uv": [14, 0], "mirror": true},
|
||||
{"origin": [-0.5, 1, -8], "size": [1, 0, 10], "pivot": [0, 5, -3], "rotation": [0, 0, -180], "uv": [14, 0], "mirror": true},
|
||||
{"origin": [-0.5, 9, -8], "size": [1, 0, 10], "pivot": [0, 5, -3], "rotation": [0, 0, 180], "uv": [14, 0], "mirror": true},
|
||||
{"origin": [1, 6, 6], "size": [1, 1, 4], "uv": [30, 0]},
|
||||
{"origin": [-2, 6, 6], "size": [1, 1, 4], "uv": [30, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "prongs2",
|
||||
"parent": "root",
|
||||
"pivot": [-2, 2, 7],
|
||||
"cubes": [
|
||||
{"origin": [1, 3, 6], "size": [1, 1, 4], "uv": [30, 0]},
|
||||
{"origin": [-2, 3, 6], "size": [1, 1, 4], "uv": [30, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bases",
|
||||
"parent": "root",
|
||||
"pivot": [2.5, 4.5, 3],
|
||||
"cubes": [
|
||||
{"origin": [-4, 1, -11], "size": [8, 8, 2], "uv": [0, 28]},
|
||||
{"origin": [-5, 0, -9], "size": [10, 10, 1], "uv": [24, 16]},
|
||||
{"origin": [-5, 0, 4], "size": [10, 10, 2], "uv": [0, 16]},
|
||||
{"origin": [-4.5, 0.5, 2], "size": [9, 9, 2], "uv": [22, 27]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.apparatus",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "root",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-3, 2, -8], "size": [6, 6, 10], "uv": [0, 0] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "prongs",
|
||||
"parent": "root",
|
||||
"pivot": [-2, 5, 7],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-0.5, 1, -8],
|
||||
"size": [1, 0, 10],
|
||||
"pivot": [0, 5, -3],
|
||||
"rotation": [0, 0, -90],
|
||||
"uv": [14, 0]
|
||||
},
|
||||
{
|
||||
"origin": [-0.5, 1, -8],
|
||||
"size": [1, 0, 10],
|
||||
"pivot": [0, 5, -3],
|
||||
"rotation": [0, 0, 90],
|
||||
"uv": [14, 0],
|
||||
"mirror": true
|
||||
},
|
||||
{
|
||||
"origin": [-0.5, 1, -8],
|
||||
"size": [1, 0, 10],
|
||||
"pivot": [0, 5, -3],
|
||||
"rotation": [0, 0, -180],
|
||||
"uv": [14, 0],
|
||||
"mirror": true
|
||||
},
|
||||
{
|
||||
"origin": [-0.5, 9, -8],
|
||||
"size": [1, 0, 10],
|
||||
"pivot": [0, 5, -3],
|
||||
"rotation": [0, 0, 180],
|
||||
"uv": [14, 0],
|
||||
"mirror": true
|
||||
},
|
||||
{ "origin": [1, 6, 6], "size": [1, 1, 4], "uv": [30, 0] },
|
||||
{ "origin": [-2, 6, 6], "size": [1, 1, 4], "uv": [30, 0] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "prongs2",
|
||||
"parent": "root",
|
||||
"pivot": [-2, 2, 7],
|
||||
"cubes": [
|
||||
{ "origin": [1, 3, 6], "size": [1, 1, 4], "uv": [30, 0] },
|
||||
{ "origin": [-2, 3, 6], "size": [1, 1, 4], "uv": [30, 0] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bases",
|
||||
"parent": "root",
|
||||
"pivot": [2.5, 4.5, 3],
|
||||
"cubes": [
|
||||
{ "origin": [-4, 1, -11], "size": [8, 8, 2], "uv": [0, 28] },
|
||||
{ "origin": [-5, 0, -9], "size": [10, 10, 1], "uv": [24, 16] },
|
||||
{ "origin": [-5, 0, 4], "size": [10, 10, 2], "uv": [0, 16] },
|
||||
{ "origin": [-4.5, 0.5, 2], "size": [9, 9, 2], "uv": [22, 27] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.big_bolt",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "item3d",
|
||||
"pivot": [-1, 3.45, 0],
|
||||
"rotation": [0, 0, 24]
|
||||
},
|
||||
{
|
||||
"name": "big_bolt",
|
||||
"parent": "item3d",
|
||||
"pivot": [-1, 0.3, 0],
|
||||
"rotation": [0, 90, 0],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-5, 0.3, -6],
|
||||
"size": [8, 8, 4],
|
||||
"pivot": [-1, 4.3, -4],
|
||||
"rotation": [0, 0, -45],
|
||||
"uv": {
|
||||
"north": {"uv": [4, 16], "uv_size": [8, 8]},
|
||||
"east": {"uv": [0, 16], "uv_size": [4, 8]},
|
||||
"south": {"uv": [16, 16], "uv_size": [8, 8]},
|
||||
"west": {"uv": [12, 16], "uv_size": [4, 8]},
|
||||
"up": {"uv": [4, 12], "uv_size": [8, 4]},
|
||||
"down": {"uv": [12, 16], "uv_size": [8, -4]}
|
||||
}
|
||||
},
|
||||
{
|
||||
"origin": [-3, 2.3, -2],
|
||||
"size": [4, 4, 8],
|
||||
"uv": {
|
||||
"north": {"uv": [8, 8], "uv_size": [4, 4]},
|
||||
"east": {"uv": [0, 8], "uv_size": [8, 4]},
|
||||
"south": {"uv": [20, 8], "uv_size": [4, 4]},
|
||||
"west": {"uv": [12, 8], "uv_size": [8, 4]},
|
||||
"up": {"uv": [8, 0], "uv_size": [4, 8]},
|
||||
"down": {"uv": [12, 8], "uv_size": [4, -8]}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.big_bolt",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "item3d",
|
||||
"pivot": [-1, 3.45, 0],
|
||||
"rotation": [0, 0, 24]
|
||||
},
|
||||
{
|
||||
"name": "big_bolt",
|
||||
"parent": "item3d",
|
||||
"pivot": [-1, 0.3, 0],
|
||||
"rotation": [0, 90, 0],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-5, 0.3, -6],
|
||||
"size": [8, 8, 4],
|
||||
"pivot": [-1, 4.3, -4],
|
||||
"rotation": [0, 0, -45],
|
||||
"uv": {
|
||||
"north": { "uv": [4, 16], "uv_size": [8, 8] },
|
||||
"east": { "uv": [0, 16], "uv_size": [4, 8] },
|
||||
"south": { "uv": [16, 16], "uv_size": [8, 8] },
|
||||
"west": { "uv": [12, 16], "uv_size": [4, 8] },
|
||||
"up": { "uv": [4, 12], "uv_size": [8, 4] },
|
||||
"down": { "uv": [12, 16], "uv_size": [8, -4] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"origin": [-3, 2.3, -2],
|
||||
"size": [4, 4, 8],
|
||||
"uv": {
|
||||
"north": { "uv": [8, 8], "uv_size": [4, 4] },
|
||||
"east": { "uv": [0, 8], "uv_size": [8, 4] },
|
||||
"south": { "uv": [20, 8], "uv_size": [4, 4] },
|
||||
"west": { "uv": [12, 8], "uv_size": [8, 4] },
|
||||
"up": { "uv": [8, 0], "uv_size": [4, 8] },
|
||||
"down": { "uv": [12, 8], "uv_size": [4, -8] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,28 +1,34 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.boombox",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "item3d",
|
||||
"pivot": [0.92341, 9.4492, 0.51353],
|
||||
"cubes": [
|
||||
{"origin": [-7, 9, -1], "size": [1, 2, 2], "uv": [0, 4]},
|
||||
{"origin": [6, 9, -1], "size": [1, 2, 2], "uv": [0, 0]},
|
||||
{"origin": [-6, 10, -1], "size": [12, 1, 2], "uv": [0, 17]},
|
||||
{"origin": [-8, 0, -4], "size": [16, 9, 8], "uv": [0, 0]},
|
||||
{"origin": [1.425, 7.75, 3], "size": [5, 10, 0], "pivot": [5.5, 14, 3], "rotation": [-8.90928, -8.80348, -24.31282], "uv": [0, 20]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.boombox",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "item3d",
|
||||
"pivot": [0.92341, 9.4492, 0.51353],
|
||||
"cubes": [
|
||||
{ "origin": [-7, 9, -1], "size": [1, 2, 2], "uv": [0, 4] },
|
||||
{ "origin": [6, 9, -1], "size": [1, 2, 2], "uv": [0, 0] },
|
||||
{ "origin": [-6, 10, -1], "size": [12, 1, 2], "uv": [0, 17] },
|
||||
{ "origin": [-8, 0, -4], "size": [16, 9, 8], "uv": [0, 0] },
|
||||
{
|
||||
"origin": [1.425, 7.75, 3],
|
||||
"size": [5, 10, 0],
|
||||
"pivot": [5.5, 14, 3],
|
||||
"rotation": [-8.90928, -8.80348, -24.31282],
|
||||
"uv": [0, 20]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,111 +1,167 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.bottles",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "bottles",
|
||||
"pivot": [0, 0.1, 0],
|
||||
"cubes": [
|
||||
{"origin": [-8, 0, -5], "size": [16, 8, 10], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle",
|
||||
"parent": "bottles",
|
||||
"pivot": [-6.40739, 6.03333, -3.40976],
|
||||
"rotation": [0, 0, -7.5],
|
||||
"cubes": [
|
||||
{"origin": [-7.4, 8.3, -4.4], "size": [2, 1, 2], "uv": [0, 6]},
|
||||
{"origin": [-7.9, 0.1, -4.9], "size": [3, 5, 3], "uv": [0, 18]},
|
||||
{"origin": [-7.7, 4.7, -3.9], "size": [2, 4, 2], "inflate": -0.4, "pivot": [-7.2, 8.2, -3.5], "rotation": [0, 45, 0], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle2",
|
||||
"parent": "bottles",
|
||||
"pivot": [-2.90739, 6.03333, -3.40976],
|
||||
"rotation": [5, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-3.9, 8.3, -4.4], "size": [2, 1, 2], "uv": [0, 6]},
|
||||
{"origin": [-4.4, 0.1, -4.9], "size": [3, 5, 3], "uv": [0, 18]},
|
||||
{"origin": [-4.2, 4.7, -3.9], "size": [2, 4, 2], "inflate": -0.4, "pivot": [-3.7, 8.2, -3.5], "rotation": [0, 45, 0], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle3",
|
||||
"parent": "bottles",
|
||||
"pivot": [7, 0.1, -2.9],
|
||||
"cubes": [
|
||||
{"origin": [-0.5, 8.3, -4.4], "size": [2, 1, 2], "uv": [0, 6]},
|
||||
{"origin": [-1, 0.1, -4.9], "size": [3, 5, 3], "uv": [0, 18]},
|
||||
{"origin": [-0.8, 4.7, -3.9], "size": [2, 4, 2], "inflate": -0.4, "pivot": [-0.3, 8.2, -3.5], "rotation": [0, 45, 0], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle4",
|
||||
"parent": "bottles",
|
||||
"pivot": [4.19261, 6.13333, -3.20976],
|
||||
"rotation": [0, 10, 7.5],
|
||||
"cubes": [
|
||||
{"origin": [3.2, 8.4, -4.2], "size": [2, 1, 2], "uv": [0, 6]},
|
||||
{"origin": [2.7, 0.2, -4.7], "size": [3, 5, 3], "uv": [0, 18]},
|
||||
{"origin": [2.9, 4.8, -3.7], "size": [2, 4, 2], "inflate": -0.4, "pivot": [3.4, 8.3, -3.3], "rotation": [0, 45, 0], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle5",
|
||||
"parent": "bottles",
|
||||
"pivot": [-4.80739, 2.03333, 0.59024],
|
||||
"rotation": [12.5, 0, -87.5],
|
||||
"cubes": [
|
||||
{"origin": [-5.8, 4.3, -0.4], "size": [2, 1, 2], "uv": [0, 6]},
|
||||
{"origin": [-6.3, -3.9, -0.9], "size": [3, 5, 3], "uv": [0, 18]},
|
||||
{"origin": [-6.1, 0.7, 0.1], "size": [2, 4, 2], "inflate": -0.4, "pivot": [-5.6, 4.2, 0.5], "rotation": [0, 45, 0], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle6",
|
||||
"parent": "bottles",
|
||||
"pivot": [1.19261, 6.13333, 0.59024],
|
||||
"rotation": [-4.3361, 11.73507, -20.44582],
|
||||
"cubes": [
|
||||
{"origin": [0.2, 8.4, -0.4], "size": [2, 1, 2], "uv": [0, 6]},
|
||||
{"origin": [-0.3, 0.2, -0.9], "size": [3, 5, 3], "uv": [0, 18]},
|
||||
{"origin": [-0.1, 4.8, 0.1], "size": [2, 4, 2], "inflate": -0.4, "pivot": [0.4, 8.3, 0.5], "rotation": [0, 45, 0], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle7",
|
||||
"parent": "bottles",
|
||||
"pivot": [-5.80739, 6.03333, 2.59024],
|
||||
"rotation": [-0.65399, 30.16227, -2.3516],
|
||||
"cubes": [
|
||||
{"origin": [-6.8, 8.3, 1.6], "size": [2, 1, 2], "uv": [0, 6]},
|
||||
{"origin": [-7.3, 0.1, 1.1], "size": [3, 5, 3], "uv": [0, 18]},
|
||||
{"origin": [-7.1, 4.7, 2.1], "size": [2, 4, 2], "inflate": -0.4, "pivot": [-6.6, 8.2, 2.5], "rotation": [0, 45, 0], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle8",
|
||||
"parent": "bottles",
|
||||
"pivot": [5.19261, 6.03333, 1.59024],
|
||||
"rotation": [0, -27.5, 0],
|
||||
"cubes": [
|
||||
{"origin": [4.2, 8.3, 0.6], "size": [2, 1, 2], "uv": [0, 6]},
|
||||
{"origin": [3.7, 0.1, 0.1], "size": [3, 5, 3], "uv": [0, 18]},
|
||||
{"origin": [3.9, 4.7, 1.1], "size": [2, 4, 2], "inflate": -0.4, "pivot": [4.4, 8.2, 1.5], "rotation": [0, 45, 0], "uv": [0, 0]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.bottles",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "bottles",
|
||||
"pivot": [0, 0.1, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-8, 0, -5], "size": [16, 8, 10], "uv": [0, 0] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle",
|
||||
"parent": "bottles",
|
||||
"pivot": [-6.40739, 6.03333, -3.40976],
|
||||
"rotation": [0, 0, -7.5],
|
||||
"cubes": [
|
||||
{ "origin": [-7.4, 8.3, -4.4], "size": [2, 1, 2], "uv": [0, 6] },
|
||||
{ "origin": [-7.9, 0.1, -4.9], "size": [3, 5, 3], "uv": [0, 18] },
|
||||
{
|
||||
"origin": [-7.7, 4.7, -3.9],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": -0.4,
|
||||
"pivot": [-7.2, 8.2, -3.5],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle2",
|
||||
"parent": "bottles",
|
||||
"pivot": [-2.90739, 6.03333, -3.40976],
|
||||
"rotation": [5, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-3.9, 8.3, -4.4], "size": [2, 1, 2], "uv": [0, 6] },
|
||||
{ "origin": [-4.4, 0.1, -4.9], "size": [3, 5, 3], "uv": [0, 18] },
|
||||
{
|
||||
"origin": [-4.2, 4.7, -3.9],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": -0.4,
|
||||
"pivot": [-3.7, 8.2, -3.5],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle3",
|
||||
"parent": "bottles",
|
||||
"pivot": [7, 0.1, -2.9],
|
||||
"cubes": [
|
||||
{ "origin": [-0.5, 8.3, -4.4], "size": [2, 1, 2], "uv": [0, 6] },
|
||||
{ "origin": [-1, 0.1, -4.9], "size": [3, 5, 3], "uv": [0, 18] },
|
||||
{
|
||||
"origin": [-0.8, 4.7, -3.9],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": -0.4,
|
||||
"pivot": [-0.3, 8.2, -3.5],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle4",
|
||||
"parent": "bottles",
|
||||
"pivot": [4.19261, 6.13333, -3.20976],
|
||||
"rotation": [0, 10, 7.5],
|
||||
"cubes": [
|
||||
{ "origin": [3.2, 8.4, -4.2], "size": [2, 1, 2], "uv": [0, 6] },
|
||||
{ "origin": [2.7, 0.2, -4.7], "size": [3, 5, 3], "uv": [0, 18] },
|
||||
{
|
||||
"origin": [2.9, 4.8, -3.7],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": -0.4,
|
||||
"pivot": [3.4, 8.3, -3.3],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle5",
|
||||
"parent": "bottles",
|
||||
"pivot": [-4.80739, 2.03333, 0.59024],
|
||||
"rotation": [12.5, 0, -87.5],
|
||||
"cubes": [
|
||||
{ "origin": [-5.8, 4.3, -0.4], "size": [2, 1, 2], "uv": [0, 6] },
|
||||
{ "origin": [-6.3, -3.9, -0.9], "size": [3, 5, 3], "uv": [0, 18] },
|
||||
{
|
||||
"origin": [-6.1, 0.7, 0.1],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": -0.4,
|
||||
"pivot": [-5.6, 4.2, 0.5],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle6",
|
||||
"parent": "bottles",
|
||||
"pivot": [1.19261, 6.13333, 0.59024],
|
||||
"rotation": [-4.3361, 11.73507, -20.44582],
|
||||
"cubes": [
|
||||
{ "origin": [0.2, 8.4, -0.4], "size": [2, 1, 2], "uv": [0, 6] },
|
||||
{ "origin": [-0.3, 0.2, -0.9], "size": [3, 5, 3], "uv": [0, 18] },
|
||||
{
|
||||
"origin": [-0.1, 4.8, 0.1],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": -0.4,
|
||||
"pivot": [0.4, 8.3, 0.5],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle7",
|
||||
"parent": "bottles",
|
||||
"pivot": [-5.80739, 6.03333, 2.59024],
|
||||
"rotation": [-0.65399, 30.16227, -2.3516],
|
||||
"cubes": [
|
||||
{ "origin": [-6.8, 8.3, 1.6], "size": [2, 1, 2], "uv": [0, 6] },
|
||||
{ "origin": [-7.3, 0.1, 1.1], "size": [3, 5, 3], "uv": [0, 18] },
|
||||
{
|
||||
"origin": [-7.1, 4.7, 2.1],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": -0.4,
|
||||
"pivot": [-6.6, 8.2, 2.5],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bottle8",
|
||||
"parent": "bottles",
|
||||
"pivot": [5.19261, 6.03333, 1.59024],
|
||||
"rotation": [0, -27.5, 0],
|
||||
"cubes": [
|
||||
{ "origin": [4.2, 8.3, 0.6], "size": [2, 1, 2], "uv": [0, 6] },
|
||||
{ "origin": [3.7, 0.1, 0.1], "size": [3, 5, 3], "uv": [0, 18] },
|
||||
{
|
||||
"origin": [3.9, 4.7, 1.1],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": -0.4,
|
||||
"pivot": [4.4, 8.2, 1.5],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 0]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.brass_bell",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "bell",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-2, 1, -2], "size": [4, 5, 4], "uv": [0, 9]},
|
||||
{"origin": [-1, 6, -0.5], "size": [2, 1, 1], "uv": [0, 0]},
|
||||
{"origin": [-1.5, 6.5, -0.5], "size": [3, 3, 1], "uv": [0, 18]},
|
||||
{"origin": [-3.5, 0, -3.5], "size": [7, 1, 7], "uv": [2, 0]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.brass_bell",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "bell",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-2, 1, -2], "size": [4, 5, 4], "uv": [0, 9] },
|
||||
{ "origin": [-1, 6, -0.5], "size": [2, 1, 1], "uv": [0, 0] },
|
||||
{ "origin": [-1.5, 6.5, -0.5], "size": [3, 3, 1], "uv": [0, 18] },
|
||||
{ "origin": [-3.5, 0, -3.5], "size": [7, 1, 7], "uv": [2, 0] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.candy",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "Candy",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-3, 0, 1], "size": [6, 1, 6], "uv": [0, 0]},
|
||||
{"origin": [-0.5, 0, -7], "size": [1, 1, 8], "uv": [0, 7]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.candy",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "Candy",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-3, 0, 1], "size": [6, 1, 6], "uv": [0, 0] },
|
||||
{ "origin": [-0.5, 0, -7], "size": [1, 1, 8], "uv": [0, 7] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,49 +1,88 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.cash_register",
|
||||
"texture_width": 128,
|
||||
"texture_height": 128,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "cash_register",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-8, 3, 5], "size": [16, 12, 3], "inflate": 0.01, "uv": [0, 41]},
|
||||
{"origin": [8, 5, 3], "size": [1, 3, 3], "pivot": [8.5, 6.5, 4.5], "rotation": [-45, 0, 0], "uv": [48, 33]},
|
||||
{"origin": [-8, 3, 0], "size": [16, 6, 5], "inflate": 0.01, "uv": [38, 41]},
|
||||
{"origin": [-8, 9, 0], "size": [16, 3, 5], "inflate": 0.0002, "pivot": [8, 12, 5], "rotation": [25, 0, 0], "uv": [48, 17]},
|
||||
{"origin": [-8, 5.88691, -7.78154], "size": [16, 4, 8.25], "pivot": [8, 9.88691, 0.46846], "rotation": [57.5, 0, 0], "uv": [0, 17]},
|
||||
{"origin": [-8, 0, -6], "size": [16, 3, 14], "inflate": 0.01, "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bone2",
|
||||
"parent": "cash_register",
|
||||
"pivot": [9, 5.5, 4.5],
|
||||
"rotation": [35, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [9, 5.81915, 4.57358], "size": [2, 1, 1], "uv": [48, 39]},
|
||||
{"origin": [10, 5.81915, 1.57358], "size": [1, 1, 3], "uv": [38, 52]},
|
||||
{"origin": [9.21367, 4.47212, -1.42642], "size": [1.5, 1.5, 3], "pivot": [11.5, 5.1, -0.5], "rotation": [0, 0, 45], "uv": [46, 52]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "buttons",
|
||||
"parent": "cash_register",
|
||||
"pivot": [8, 9.88691, 0.46846],
|
||||
"cubes": [
|
||||
{"origin": [-8, 9, 0], "size": [16, 3, 5], "inflate": 0.1, "pivot": [8, 12, 5], "rotation": [25, 0, 0], "uv": [48, 25]},
|
||||
{"origin": [-8, 5.79721, -7.88382], "size": [16, 4, 8.25], "inflate": 0.1, "pivot": [8, 9.79721, 0.36618], "rotation": [57.5, 0, 0], "uv": [0, 29]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.cash_register",
|
||||
"texture_width": 128,
|
||||
"texture_height": 128,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "cash_register",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-8, 3, 5], "size": [16, 12, 3], "inflate": 0.01, "uv": [0, 41] },
|
||||
{
|
||||
"origin": [8, 5, 3],
|
||||
"size": [1, 3, 3],
|
||||
"pivot": [8.5, 6.5, 4.5],
|
||||
"rotation": [-45, 0, 0],
|
||||
"uv": [48, 33]
|
||||
},
|
||||
{ "origin": [-8, 3, 0], "size": [16, 6, 5], "inflate": 0.01, "uv": [38, 41] },
|
||||
{
|
||||
"origin": [-8, 9, 0],
|
||||
"size": [16, 3, 5],
|
||||
"inflate": 0.0002,
|
||||
"pivot": [8, 12, 5],
|
||||
"rotation": [25, 0, 0],
|
||||
"uv": [48, 17]
|
||||
},
|
||||
{
|
||||
"origin": [-8, 5.88691, -7.78154],
|
||||
"size": [16, 4, 8.25],
|
||||
"pivot": [8, 9.88691, 0.46846],
|
||||
"rotation": [57.5, 0, 0],
|
||||
"uv": [0, 17]
|
||||
},
|
||||
{ "origin": [-8, 0, -6], "size": [16, 3, 14], "inflate": 0.01, "uv": [0, 0] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bone2",
|
||||
"parent": "cash_register",
|
||||
"pivot": [9, 5.5, 4.5],
|
||||
"rotation": [35, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [9, 5.81915, 4.57358], "size": [2, 1, 1], "uv": [48, 39] },
|
||||
{ "origin": [10, 5.81915, 1.57358], "size": [1, 1, 3], "uv": [38, 52] },
|
||||
{
|
||||
"origin": [9.21367, 4.47212, -1.42642],
|
||||
"size": [1.5, 1.5, 3],
|
||||
"pivot": [11.5, 5.1, -0.5],
|
||||
"rotation": [0, 0, 45],
|
||||
"uv": [46, 52]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "buttons",
|
||||
"parent": "cash_register",
|
||||
"pivot": [8, 9.88691, 0.46846],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-8, 9, 0],
|
||||
"size": [16, 3, 5],
|
||||
"inflate": 0.1,
|
||||
"pivot": [8, 12, 5],
|
||||
"rotation": [25, 0, 0],
|
||||
"uv": [48, 25]
|
||||
},
|
||||
{
|
||||
"origin": [-8, 5.79721, -7.88382],
|
||||
"size": [16, 4, 8.25],
|
||||
"inflate": 0.1,
|
||||
"pivot": [8, 9.79721, 0.36618],
|
||||
"rotation": [57.5, 0, 0],
|
||||
"uv": [0, 29]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"model": {
|
||||
"id": "dangerous_business:chain",
|
||||
"elements": [
|
||||
{
|
||||
"from": [6.5, 0, 8],
|
||||
"to": [9.5, 16, 8],
|
||||
"rotation": { "origin": [8, 8, 8], "axis": "y", "angle": 45 },
|
||||
"shade": false,
|
||||
"faces": {
|
||||
"north": { "texture": "#chain", "uv": [3, 0, 0, 16] },
|
||||
"south": { "texture": "#chain", "uv": [0, 0, 3, 16] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [8, 0, 6.5],
|
||||
"to": [8, 16, 9.5],
|
||||
"rotation": { "origin": [8, 8, 8], "axis": "y", "angle": 45 },
|
||||
"shade": false,
|
||||
"faces": {
|
||||
"east": { "texture": "#chain", "uv": [3, 0, 6, 16] },
|
||||
"west": { "texture": "#chain", "uv": [6, 0, 3, 16] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,91 +1,91 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.clown_horn",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "clown_horn",
|
||||
"pivot": [0, 2.1, 0],
|
||||
"rotation": [175, 0, -180],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-1, 1.1, -3],
|
||||
"size": [2, 2, 6],
|
||||
"uv": {
|
||||
"north": {"uv": [7, 13], "uv_size": [2, 2]},
|
||||
"east": {"uv": [5, 8], "uv_size": [6, 2]},
|
||||
"south": {"uv": [9, 13], "uv_size": [2, 2]},
|
||||
"west": {"uv": [9, 0], "uv_size": [6, 2]},
|
||||
"up": {"uv": [9, 2], "uv_size": [2, 6]},
|
||||
"down": {"uv": [0, 16], "uv_size": [2, -6]}
|
||||
}
|
||||
},
|
||||
{
|
||||
"origin": [-1.5, 0.6, -4],
|
||||
"size": [3, 3, 1],
|
||||
"uv": {
|
||||
"north": {"uv": [2, 10], "uv_size": [3, 3]},
|
||||
"east": {"uv": [15, 4], "uv_size": [1, 3]},
|
||||
"south": {"uv": [5, 10], "uv_size": [3, 3]},
|
||||
"west": {"uv": [7, 15], "uv_size": [1, 3]},
|
||||
"up": {"uv": [14, 13], "uv_size": [3, 1]},
|
||||
"down": {"uv": [15, 1], "uv_size": [3, -1]}
|
||||
}
|
||||
},
|
||||
{
|
||||
"origin": [-2, 0.1, -5],
|
||||
"size": [4, 4, 1],
|
||||
"uv": {
|
||||
"north": {"uv": [5, 0], "uv_size": [4, 4]},
|
||||
"east": {"uv": [14, 4], "uv_size": [1, 4]},
|
||||
"south": {"uv": [5, 4], "uv_size": [4, 4]},
|
||||
"west": {"uv": [14, 8], "uv_size": [1, 4]},
|
||||
"up": {"uv": [11, 14], "uv_size": [4, 1]},
|
||||
"down": {"uv": [14, 13], "uv_size": [4, -1]}
|
||||
}
|
||||
},
|
||||
{
|
||||
"origin": [-2.5, -0.4, -6],
|
||||
"size": [5, 5, 1],
|
||||
"uv": {
|
||||
"north": {"uv": [0, 0], "uv_size": [5, 5]},
|
||||
"east": {"uv": [5, 13], "uv_size": [1, 5]},
|
||||
"south": {"uv": [0, 5], "uv_size": [5, 5]},
|
||||
"west": {"uv": [6, 13], "uv_size": [1, 5]},
|
||||
"up": {"uv": [14, 2], "uv_size": [5, 1]},
|
||||
"down": {"uv": [14, 4], "uv_size": [5, -1]}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "honker",
|
||||
"parent": "clown_horn",
|
||||
"pivot": [-0.025, 2.1, 4.5],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-1.525, 0.6, 3],
|
||||
"size": [3, 3, 3],
|
||||
"uv": {
|
||||
"north": {"uv": [8, 10], "uv_size": [3, 3]},
|
||||
"east": {"uv": [11, 2], "uv_size": [3, 3]},
|
||||
"south": {"uv": [11, 5], "uv_size": [3, 3]},
|
||||
"west": {"uv": [11, 8], "uv_size": [3, 3]},
|
||||
"up": {"uv": [11, 11], "uv_size": [3, 3]},
|
||||
"down": {"uv": [2, 16], "uv_size": [3, -3]}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.clown_horn",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "clown_horn",
|
||||
"pivot": [0, 2.1, 0],
|
||||
"rotation": [175, 0, -180],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-1, 1.1, -3],
|
||||
"size": [2, 2, 6],
|
||||
"uv": {
|
||||
"north": { "uv": [7, 13], "uv_size": [2, 2] },
|
||||
"east": { "uv": [5, 8], "uv_size": [6, 2] },
|
||||
"south": { "uv": [9, 13], "uv_size": [2, 2] },
|
||||
"west": { "uv": [9, 0], "uv_size": [6, 2] },
|
||||
"up": { "uv": [9, 2], "uv_size": [2, 6] },
|
||||
"down": { "uv": [0, 16], "uv_size": [2, -6] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"origin": [-1.5, 0.6, -4],
|
||||
"size": [3, 3, 1],
|
||||
"uv": {
|
||||
"north": { "uv": [2, 10], "uv_size": [3, 3] },
|
||||
"east": { "uv": [15, 4], "uv_size": [1, 3] },
|
||||
"south": { "uv": [5, 10], "uv_size": [3, 3] },
|
||||
"west": { "uv": [7, 15], "uv_size": [1, 3] },
|
||||
"up": { "uv": [14, 13], "uv_size": [3, 1] },
|
||||
"down": { "uv": [15, 1], "uv_size": [3, -1] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"origin": [-2, 0.1, -5],
|
||||
"size": [4, 4, 1],
|
||||
"uv": {
|
||||
"north": { "uv": [5, 0], "uv_size": [4, 4] },
|
||||
"east": { "uv": [14, 4], "uv_size": [1, 4] },
|
||||
"south": { "uv": [5, 4], "uv_size": [4, 4] },
|
||||
"west": { "uv": [14, 8], "uv_size": [1, 4] },
|
||||
"up": { "uv": [11, 14], "uv_size": [4, 1] },
|
||||
"down": { "uv": [14, 13], "uv_size": [4, -1] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"origin": [-2.5, -0.4, -6],
|
||||
"size": [5, 5, 1],
|
||||
"uv": {
|
||||
"north": { "uv": [0, 0], "uv_size": [5, 5] },
|
||||
"east": { "uv": [5, 13], "uv_size": [1, 5] },
|
||||
"south": { "uv": [0, 5], "uv_size": [5, 5] },
|
||||
"west": { "uv": [6, 13], "uv_size": [1, 5] },
|
||||
"up": { "uv": [14, 2], "uv_size": [5, 1] },
|
||||
"down": { "uv": [14, 4], "uv_size": [5, -1] }
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "honker",
|
||||
"parent": "clown_horn",
|
||||
"pivot": [-0.025, 2.1, 4.5],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-1.525, 0.6, 3],
|
||||
"size": [3, 3, 3],
|
||||
"uv": {
|
||||
"north": { "uv": [8, 10], "uv_size": [3, 3] },
|
||||
"east": { "uv": [11, 2], "uv_size": [3, 3] },
|
||||
"south": { "uv": [11, 5], "uv_size": [3, 3] },
|
||||
"west": { "uv": [11, 8], "uv_size": [3, 3] },
|
||||
"up": { "uv": [11, 11], "uv_size": [3, 3] },
|
||||
"down": { "uv": [2, 16], "uv_size": [3, -3] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.cookie_mold_pan",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "cookie_mold_pan",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-9, 0, -7], "size": [17, 1, 14], "uv": [0, 0]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.cookie_mold_pan",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "cookie_mold_pan",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-9, 0, -7], "size": [17, 1, 14], "uv": [0, 0] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.duck",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "root",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-4, 0, -4], "size": [8, 5, 9], "inflate": -0.5, "uv": [0, 0]},
|
||||
{"origin": [-3, 0, -4], "size": [6, 5, 9], "uv": [0, 14]},
|
||||
{"origin": [-3, 5, 4], "size": [6, 1, 1], "uv": [25, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "head",
|
||||
"parent": "root",
|
||||
"pivot": [0, 4.7, -2.6],
|
||||
"cubes": [
|
||||
{"origin": [-2, 5, -6], "size": [4, 4, 4], "inflate": 0.3, "uv": [21, 14]},
|
||||
{"origin": [-2, 6, -8], "size": [4, 1, 2], "uv": [25, 2]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.duck",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "root",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-4, 0, -4], "size": [8, 5, 9], "inflate": -0.5, "uv": [0, 0] },
|
||||
{ "origin": [-3, 0, -4], "size": [6, 5, 9], "uv": [0, 14] },
|
||||
{ "origin": [-3, 5, 4], "size": [6, 1, 1], "uv": [25, 0] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "head",
|
||||
"parent": "root",
|
||||
"pivot": [0, 4.7, -2.6],
|
||||
"cubes": [
|
||||
{ "origin": [-2, 5, -6], "size": [4, 4, 4], "inflate": 0.3, "uv": [21, 14] },
|
||||
{ "origin": [-2, 6, -8], "size": [4, 1, 2], "uv": [25, 2] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.dust_pan",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "dust_pan",
|
||||
"pivot": [0, 0.1, 0],
|
||||
"rotation": [0, 180, 0],
|
||||
"cubes": [
|
||||
{"origin": [-1.5, 0.1, 3], "size": [3, 1.5, 5], "uv": [0, 8]},
|
||||
{"origin": [-5.5, 0.1, -8], "size": [11, 1.5, 7], "uv": [0, 0]},
|
||||
{"origin": [-1, 0.1, -1], "size": [2, 1, 4], "uv": [11, 8]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.dust_pan",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "dust_pan",
|
||||
"pivot": [0, 0.1, 0],
|
||||
"rotation": [0, 180, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-1.5, 0.1, 3], "size": [3, 1.5, 5], "uv": [0, 8] },
|
||||
{ "origin": [-5.5, 0.1, -8], "size": [11, 1.5, 7], "uv": [0, 0] },
|
||||
{ "origin": [-1, 0.1, -1], "size": [2, 1, 4], "uv": [11, 8] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,27 +1,33 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.egg_beater",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 3.5,
|
||||
"visible_bounds_offset": [0, 1.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "egg_beater",
|
||||
"pivot": [0, 1.94847, 2.69906],
|
||||
"rotation": [-87.5, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-1, -15.2182, 1.69906], "size": [2, 16, 2], "pivot": [0, -9.6182, 2.69906], "rotation": [0, -45, 0], "uv": [0, 12]},
|
||||
{"origin": [0, 0.7818, 2.19906], "size": [0, 5, 1], "uv": [8, 11]},
|
||||
{"origin": [-2, 5.7818, 0.69906], "size": [4, 8, 4], "uv": [0, 0]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.egg_beater",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 3.5,
|
||||
"visible_bounds_offset": [0, 1.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "egg_beater",
|
||||
"pivot": [0, 1.94847, 2.69906],
|
||||
"rotation": [-87.5, 0, 0],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-1, -15.2182, 1.69906],
|
||||
"size": [2, 16, 2],
|
||||
"pivot": [0, -9.6182, 2.69906],
|
||||
"rotation": [0, -45, 0],
|
||||
"uv": [0, 12]
|
||||
},
|
||||
{ "origin": [0, 0.7818, 2.19906], "size": [0, 5, 1], "uv": [8, 11] },
|
||||
{ "origin": [-2, 5.7818, 0.69906], "size": [4, 8, 4], "uv": [0, 0] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"model": {
|
||||
"id": "dangerous_business:fence_inventory",
|
||||
"elements": [
|
||||
{
|
||||
"from": [
|
||||
6,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"to": [
|
||||
10,
|
||||
16,
|
||||
4
|
||||
],
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"south": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"east": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"top": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
6,
|
||||
6,
|
||||
10,
|
||||
10
|
||||
]
|
||||
},
|
||||
"bottom": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
6,
|
||||
6,
|
||||
10,
|
||||
10
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [
|
||||
6,
|
||||
0,
|
||||
12
|
||||
],
|
||||
"to": [
|
||||
10,
|
||||
16,
|
||||
16
|
||||
],
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"south": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"east": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"top": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
6,
|
||||
6,
|
||||
10,
|
||||
10
|
||||
]
|
||||
},
|
||||
"bottom": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
6,
|
||||
6,
|
||||
10,
|
||||
10
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [
|
||||
7,
|
||||
12,
|
||||
0
|
||||
],
|
||||
"to": [
|
||||
9,
|
||||
15,
|
||||
16
|
||||
],
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
7,
|
||||
1,
|
||||
9,
|
||||
4
|
||||
]
|
||||
},
|
||||
"south": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
7,
|
||||
1,
|
||||
9,
|
||||
4
|
||||
]
|
||||
},
|
||||
"east": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
0,
|
||||
1,
|
||||
16,
|
||||
4
|
||||
]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
0,
|
||||
1,
|
||||
16,
|
||||
4
|
||||
]
|
||||
},
|
||||
"top": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
16
|
||||
]
|
||||
},
|
||||
"bottom": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
16
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [
|
||||
7,
|
||||
6,
|
||||
0
|
||||
],
|
||||
"to": [
|
||||
9,
|
||||
9,
|
||||
16
|
||||
],
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
7,
|
||||
7,
|
||||
9,
|
||||
10
|
||||
]
|
||||
},
|
||||
"south": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
7,
|
||||
7,
|
||||
9,
|
||||
10
|
||||
]
|
||||
},
|
||||
"east": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
0,
|
||||
7,
|
||||
16,
|
||||
10
|
||||
]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
0,
|
||||
7,
|
||||
16,
|
||||
10
|
||||
]
|
||||
},
|
||||
"top": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
16
|
||||
]
|
||||
},
|
||||
"bottom": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
16
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"model": {
|
||||
"id": "dangerous_business:fence_post",
|
||||
"elements": [
|
||||
{
|
||||
"from": [
|
||||
6,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"to": [
|
||||
10,
|
||||
16,
|
||||
10
|
||||
],
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"east": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"south": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
6,
|
||||
0,
|
||||
10,
|
||||
16
|
||||
]
|
||||
},
|
||||
"top": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
6,
|
||||
6,
|
||||
10,
|
||||
10
|
||||
],
|
||||
"cullface": "top"
|
||||
},
|
||||
"bottom": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
6,
|
||||
6,
|
||||
10,
|
||||
10
|
||||
],
|
||||
"cullface": "bottom"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"model": {
|
||||
"id": "dangerous_business:fence_side",
|
||||
"elements": [
|
||||
{
|
||||
"from": [
|
||||
7,
|
||||
12,
|
||||
0
|
||||
],
|
||||
"to": [
|
||||
9,
|
||||
15,
|
||||
9
|
||||
],
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
7,
|
||||
1,
|
||||
9,
|
||||
4
|
||||
],
|
||||
"cullface": "north"
|
||||
},
|
||||
"east": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
7,
|
||||
1,
|
||||
16,
|
||||
4
|
||||
]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
0,
|
||||
1,
|
||||
9,
|
||||
4
|
||||
]
|
||||
},
|
||||
"top": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
9
|
||||
]
|
||||
},
|
||||
"bottom": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
9
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [
|
||||
7,
|
||||
6,
|
||||
0
|
||||
],
|
||||
"to": [
|
||||
9,
|
||||
9,
|
||||
9
|
||||
],
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
7,
|
||||
7,
|
||||
9,
|
||||
10
|
||||
],
|
||||
"cullface": "north"
|
||||
},
|
||||
"east": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
7,
|
||||
7,
|
||||
16,
|
||||
10
|
||||
]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#side",
|
||||
"uv": [
|
||||
0,
|
||||
7,
|
||||
9,
|
||||
10
|
||||
]
|
||||
},
|
||||
"top": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
9
|
||||
]
|
||||
},
|
||||
"bottom": {
|
||||
"texture": "#top",
|
||||
"uv": [
|
||||
7,
|
||||
0,
|
||||
9,
|
||||
9
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,60 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.flashlight",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "flashlight",
|
||||
"pivot": [0, 1, 0],
|
||||
"cubes": [
|
||||
{"origin": [-1, 1, -4], "size": [2, 2, 7], "pivot": [0, 2, 0], "rotation": [0, 0, 45], "uv": [0, 0]},
|
||||
{"origin": [-1.5, 0.5, -6], "size": [3, 3, 4], "pivot": [0, 2, 0], "rotation": [0, 0, 45], "uv": [0, 9]},
|
||||
{"origin": [-1.5, 0.5, -7], "size": [3, 3, 1], "pivot": [0, 2, 0], "rotation": [0, 0, 45], "uv": [24, 0]},
|
||||
{"origin": [-1.5, 0.5, 2], "size": [3, 3, 2], "pivot": [0, 2, 0], "rotation": [0, 0, 45], "uv": [11, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "felt_thingy",
|
||||
"parent": "flashlight",
|
||||
"pivot": [0, 2, 4],
|
||||
"rotation": [75.5, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-1, -6, 4], "size": [2, 8, 0], "uv": [14, 9]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.flashlight",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 3,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "flashlight",
|
||||
"pivot": [0, 1, 0],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [-1, 1, -4],
|
||||
"size": [2, 2, 7],
|
||||
"pivot": [0, 2, 0],
|
||||
"rotation": [0, 0, 45],
|
||||
"uv": [0, 0]
|
||||
},
|
||||
{
|
||||
"origin": [-1.5, 0.5, -6],
|
||||
"size": [3, 3, 4],
|
||||
"pivot": [0, 2, 0],
|
||||
"rotation": [0, 0, 45],
|
||||
"uv": [0, 9]
|
||||
},
|
||||
{
|
||||
"origin": [-1.5, 0.5, -7],
|
||||
"size": [3, 3, 1],
|
||||
"pivot": [0, 2, 0],
|
||||
"rotation": [0, 0, 45],
|
||||
"uv": [24, 0]
|
||||
},
|
||||
{
|
||||
"origin": [-1.5, 0.5, 2],
|
||||
"size": [3, 3, 2],
|
||||
"pivot": [0, 2, 0],
|
||||
"rotation": [0, 0, 45],
|
||||
"uv": [11, 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "felt_thingy",
|
||||
"parent": "flashlight",
|
||||
"pivot": [0, 2, 4],
|
||||
"rotation": [75.5, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-1, -6, 4], "size": [2, 8, 0], "uv": [14, 9] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,26 +1,40 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.flask",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "flask",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-3, 0, -3], "size": [6, 6, 6], "uv": [0, 0]},
|
||||
{"origin": [-1, 6.2, -1], "size": [2, 4, 2], "inflate": 0.2, "pivot": [0, 8.5, 0], "rotation": [0, 45, 0], "uv": [12, 12]},
|
||||
{"origin": [-1.5, 10.6, -1.5], "size": [3, 2, 3], "inflate": 0.2, "pivot": [0, 8.5, 0], "rotation": [0, 45, 0], "uv": [0, 12]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.flask",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "flask",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-3, 0, -3], "size": [6, 6, 6], "uv": [0, 0] },
|
||||
{
|
||||
"origin": [-1, 6.2, -1],
|
||||
"size": [2, 4, 2],
|
||||
"inflate": 0.2,
|
||||
"pivot": [0, 8.5, 0],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [12, 12]
|
||||
},
|
||||
{
|
||||
"origin": [-1.5, 10.6, -1.5],
|
||||
"size": [3, 2, 3],
|
||||
"inflate": 0.2,
|
||||
"pivot": [0, 8.5, 0],
|
||||
"rotation": [0, 45, 0],
|
||||
"uv": [0, 12]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.garbage_lid",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "bone",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-6, 0, -6], "size": [12, 1, 12], "uv": [0, 0]},
|
||||
{"origin": [-5, 1, -5], "size": [10, 1, 10], "uv": [0, 13]},
|
||||
{"origin": [-2.5, 2, -0.5], "size": [5, 1, 1], "uv": [0, 24]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.garbage_lid",
|
||||
"texture_width": 64,
|
||||
"texture_height": 64,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "bone",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-6, 0, -6], "size": [12, 1, 12], "uv": [0, 0] },
|
||||
{ "origin": [-5, 1, -5], "size": [10, 1, 10], "uv": [0, 13] },
|
||||
{ "origin": [-2.5, 2, -0.5], "size": [5, 1, 1], "uv": [0, 24] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,52 +1,124 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.gift",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "gift",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-3, 0, -3], "size": [6, 6, 6], "uv": [0, 0]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "top",
|
||||
"parent": "gift",
|
||||
"pivot": [0, 6, 0],
|
||||
"cubes": [
|
||||
{"origin": [-3, 0, -3], "size": [6, 6, 6], "inflate": 0.25, "uv": [0, 20]}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ribbon",
|
||||
"parent": "top",
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [0, -22.5, 0],
|
||||
"cubes": [
|
||||
{"origin": [0, 6, -1], "size": [0, 3, 2], "pivot": [0, 6, 0], "rotation": [0, 0, -45], "uv": [23, 1]},
|
||||
{"origin": [-0.12124, 5.90481, -1], "size": [0, 3, 2], "pivot": [0, 6, 0], "rotation": [0, 0, -62], "uv": [25, 6]},
|
||||
{"origin": [-0.22354, 8.89778, -1], "size": [1, 0, 2], "pivot": [0, 6, 0], "rotation": [0, 0, -60], "uv": [19, 4]},
|
||||
{"origin": [0, 6, -1], "size": [0, 3, 2], "pivot": [0, 6, 0], "rotation": [-90, 45, -90], "uv": [23, 1]},
|
||||
{"origin": [-0.12124, 5.90481, -1], "size": [0, 3, 2], "pivot": [0, 6, 0], "rotation": [-90, 28, -90], "uv": [25, 6]},
|
||||
{"origin": [-0.22354, 8.89778, -1], "size": [1, 0, 2], "pivot": [0, 6, 0], "rotation": [-90, 30, -90], "uv": [19, 4]},
|
||||
{"origin": [0, 6, -1], "size": [0, 3, 2], "pivot": [0, 6, 0], "rotation": [180, 0, -135], "uv": [23, 1]},
|
||||
{"origin": [-0.12124, 5.90481, -1], "size": [0, 3, 2], "pivot": [0, 6, 0], "rotation": [-180, 0, -118], "uv": [25, 6]},
|
||||
{"origin": [-0.22354, 8.89778, -1], "size": [1, 0, 2], "pivot": [0, 6, 0], "rotation": [-180, 0, -120], "uv": [19, 4]},
|
||||
{"origin": [0, 6, -1], "size": [0, 3, 2], "pivot": [0, 6, 0], "rotation": [90, -45, -90], "uv": [23, 1]},
|
||||
{"origin": [-0.12124, 5.90481, -1], "size": [0, 3, 2], "pivot": [0, 6, 0], "rotation": [90, -28, -90], "uv": [25, 6]},
|
||||
{"origin": [-0.22354, 8.89778, -1], "size": [1, 0, 2], "pivot": [0, 6, 0], "rotation": [90, -30, -90], "uv": [19, 4]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.gift",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 2.5,
|
||||
"visible_bounds_offset": [0, 0.75, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "gift",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-3, 0, -3], "size": [6, 6, 6], "uv": [0, 0] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "top",
|
||||
"parent": "gift",
|
||||
"pivot": [0, 6, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-3, 0, -3], "size": [6, 6, 6], "inflate": 0.25, "uv": [0, 20] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ribbon",
|
||||
"parent": "top",
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [0, -22.5, 0],
|
||||
"cubes": [
|
||||
{
|
||||
"origin": [0, 6, -1],
|
||||
"size": [0, 3, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [0, 0, -45],
|
||||
"uv": [23, 1]
|
||||
},
|
||||
{
|
||||
"origin": [-0.12124, 5.90481, -1],
|
||||
"size": [0, 3, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [0, 0, -62],
|
||||
"uv": [25, 6]
|
||||
},
|
||||
{
|
||||
"origin": [-0.22354, 8.89778, -1],
|
||||
"size": [1, 0, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [0, 0, -60],
|
||||
"uv": [19, 4]
|
||||
},
|
||||
{
|
||||
"origin": [0, 6, -1],
|
||||
"size": [0, 3, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [-90, 45, -90],
|
||||
"uv": [23, 1]
|
||||
},
|
||||
{
|
||||
"origin": [-0.12124, 5.90481, -1],
|
||||
"size": [0, 3, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [-90, 28, -90],
|
||||
"uv": [25, 6]
|
||||
},
|
||||
{
|
||||
"origin": [-0.22354, 8.89778, -1],
|
||||
"size": [1, 0, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [-90, 30, -90],
|
||||
"uv": [19, 4]
|
||||
},
|
||||
{
|
||||
"origin": [0, 6, -1],
|
||||
"size": [0, 3, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [180, 0, -135],
|
||||
"uv": [23, 1]
|
||||
},
|
||||
{
|
||||
"origin": [-0.12124, 5.90481, -1],
|
||||
"size": [0, 3, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [-180, 0, -118],
|
||||
"uv": [25, 6]
|
||||
},
|
||||
{
|
||||
"origin": [-0.22354, 8.89778, -1],
|
||||
"size": [1, 0, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [-180, 0, -120],
|
||||
"uv": [19, 4]
|
||||
},
|
||||
{
|
||||
"origin": [0, 6, -1],
|
||||
"size": [0, 3, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [90, -45, -90],
|
||||
"uv": [23, 1]
|
||||
},
|
||||
{
|
||||
"origin": [-0.12124, 5.90481, -1],
|
||||
"size": [0, 3, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [90, -28, -90],
|
||||
"uv": [25, 6]
|
||||
},
|
||||
{
|
||||
"origin": [-0.22354, 8.89778, -1],
|
||||
"size": [1, 0, 2],
|
||||
"pivot": [0, 6, 0],
|
||||
"rotation": [90, -30, -90],
|
||||
"uv": [19, 4]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.gold_bar",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "gold_bar",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{"origin": [-1.5, 0, -5], "size": [3, 2, 9], "uv": [0, 0]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.gold_bar",
|
||||
"texture_width": 32,
|
||||
"texture_height": 32,
|
||||
"visible_bounds_width": 2,
|
||||
"visible_bounds_height": 1.5,
|
||||
"visible_bounds_offset": [0, 0.25, 0]
|
||||
},
|
||||
"bones": [
|
||||
{
|
||||
"name": "gold_bar",
|
||||
"pivot": [0, 0, 0],
|
||||
"cubes": [
|
||||
{ "origin": [-1.5, 0, -5], "size": [3, 2, 9], "uv": [0, 0] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user