Remove duplicate code
This commit is contained in:
@@ -44,8 +44,9 @@ function chest_screen(menu: ClientMenu): MenuScreen {
|
||||
function furnace_screen(menu: ClientMenu): MenuScreen {
|
||||
return container_screen(menu, HEIGHT, (g) => {
|
||||
// the fuel left burns down, the progress fills to the right
|
||||
bar(g, 55, 34, "up", menu.data.fuel, menu.data.fuel_max, "bworld:fire_empty", "bworld:fire_full");
|
||||
bar(g, 85, 34, "right", menu.data.progress, menu.data.progress_max, "bworld:arrow_empty", "bworld:arrow_full");
|
||||
const { fuel, fuel_max, progress, progress_max } = menu.data;
|
||||
g.progress("bworld:fire_empty", "bworld:fire_full", 55, 34, 18, 18, fuel / fuel_max, "up");
|
||||
g.progress("bworld:arrow_empty", "bworld:arrow_full", 85, 34, 18, 18, progress / progress_max);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -125,27 +126,6 @@ function stonecutter_screen(ctx: ClientContext, menu: ClientMenu): MenuScreen {
|
||||
});
|
||||
}
|
||||
|
||||
// an 18 pixel square progress bar, value / max of full drawn over empty
|
||||
function bar(
|
||||
g: Graphics,
|
||||
x: number,
|
||||
y: number,
|
||||
direction: "up" | "right",
|
||||
value = 0,
|
||||
max = 0,
|
||||
empty: string,
|
||||
full: string,
|
||||
) {
|
||||
const size = 18;
|
||||
const done = max > 0 ? Math.max(0, Math.min(1, value / max)) : 0;
|
||||
g.texture(empty, x, y, size, size);
|
||||
if (direction === "right") {
|
||||
g.texture(full, x, y, size * done, size, [0, 0, done, 1]);
|
||||
} else {
|
||||
g.texture(full, x, y + size * (1 - done), size, size * done, [0, 1 - done, 1, done]);
|
||||
}
|
||||
}
|
||||
|
||||
// a fishing minigame's screen, by the minigame's name, see minigames/mod.ts
|
||||
function fishing_minigame_screen(menu: ClientMenu): MenuScreen {
|
||||
const { minigame, fish } = menu.open_data as { minigame: string; fish: ItemStack };
|
||||
|
||||
@@ -105,20 +105,10 @@ function grow_tree(kind: TreeKind, x: number, y: number, z: number, rng: Random,
|
||||
|
||||
let top: number;
|
||||
switch (kind) {
|
||||
case "oak": {
|
||||
const height = random(4, 6);
|
||||
top = y + height + 1;
|
||||
if (top >= CHUNK_HEIGHT - 1) return false;
|
||||
trunk(height);
|
||||
layer(y + height - 2, 2, true);
|
||||
layer(y + height - 1, 2, true);
|
||||
layer(y + height, 1, true);
|
||||
layer(y + height + 1, 1, false);
|
||||
break;
|
||||
}
|
||||
case "oak":
|
||||
case "birch": {
|
||||
// oak's canopy on a taller, straight trunk
|
||||
const height = random(5, 7);
|
||||
// birch is oak's canopy on a taller, straight trunk
|
||||
const height = kind === "birch" ? random(5, 7) : random(4, 6);
|
||||
top = y + height + 1;
|
||||
if (top >= CHUNK_HEIGHT - 1) return false;
|
||||
trunk(height);
|
||||
|
||||
Reference in New Issue
Block a user