Juicer press wow
This commit is contained in:
@@ -5,8 +5,18 @@
|
||||
"name": "Juicer",
|
||||
"textures": {},
|
||||
"model": "bworld:juicer",
|
||||
"item_model": "bworld:juicer",
|
||||
"item_model": "bworld:juicer_item",
|
||||
"render_layer": "cutout",
|
||||
"shape": [
|
||||
[0, 0, 0, 16, 2, 16],
|
||||
[0, 2, 0, 2, 14, 2],
|
||||
[14, 2, 0, 16, 14, 2],
|
||||
[14, 2, 14, 16, 14, 16],
|
||||
[0, 2, 14, 2, 14, 16],
|
||||
[0, 14, 0, 16, 16, 16],
|
||||
[5, 8, 5, 11, 10, 11],
|
||||
[7, 10, 7, 9, 14, 9]
|
||||
],
|
||||
"mining": {
|
||||
"toughness": 2,
|
||||
"tool": "pickaxe"
|
||||
|
||||
@@ -68,42 +68,6 @@
|
||||
"top": { "texture": "#0", "uv": [0, 0, 2, 2] },
|
||||
"bottom": { "texture": "#0", "uv": [0, 0, 2, 2] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [0, 14, 0],
|
||||
"to": [16, 16, 16],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"top": { "texture": "#2", "uv": [0, 0, 16, 16] },
|
||||
"bottom": { "texture": "#1", "uv": [0, 0, 16, 16] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [5, 8, 5],
|
||||
"to": [11, 10, 11],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"east": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"south": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"west": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"top": { "texture": "#2", "uv": [5, 5, 11, 11] },
|
||||
"bottom": { "texture": "#1", "uv": [5, 5, 11, 11] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [7, 10, 7],
|
||||
"to": [9, 14, 9],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"top": { "texture": "#0", "uv": [0, 0, 2, 2] },
|
||||
"bottom": { "texture": "#0", "uv": [0, 0, 2, 2] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"model": {
|
||||
"id": "bworld:juicer_item",
|
||||
"textures": {
|
||||
"0": "bworld:juicer_side",
|
||||
"1": "bworld:juicer_bottom",
|
||||
"2": "bworld:juicer_top",
|
||||
"particle": "bworld:juicer_side"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"from": [0, 0, 0],
|
||||
"to": [16, 2, 16],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"top": { "texture": "#1", "uv": [0, 0, 16, 16] },
|
||||
"bottom": { "texture": "#1", "uv": [0, 0, 16, 16] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [0, 2, 0],
|
||||
"to": [2, 14, 2],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"top": { "texture": "#0", "uv": [0, 0, 2, 2] },
|
||||
"bottom": { "texture": "#0", "uv": [0, 0, 2, 2] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [14, 2, 0],
|
||||
"to": [16, 14, 2],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"top": { "texture": "#0", "uv": [0, 0, 2, 2] },
|
||||
"bottom": { "texture": "#0", "uv": [0, 0, 2, 2] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [14, 2, 14],
|
||||
"to": [16, 14, 16],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"top": { "texture": "#0", "uv": [0, 0, 2, 2] },
|
||||
"bottom": { "texture": "#0", "uv": [0, 0, 2, 2] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [0, 2, 14],
|
||||
"to": [2, 14, 16],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 2, 12] },
|
||||
"top": { "texture": "#0", "uv": [0, 0, 2, 2] },
|
||||
"bottom": { "texture": "#0", "uv": [0, 0, 2, 2] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [0, 14, 0],
|
||||
"to": [16, 16, 16],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"top": { "texture": "#2", "uv": [0, 0, 16, 16] },
|
||||
"bottom": { "texture": "#1", "uv": [0, 0, 16, 16] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [5, 8, 5],
|
||||
"to": [11, 10, 11],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"east": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"south": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"west": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"top": { "texture": "#2", "uv": [5, 5, 11, 11] },
|
||||
"bottom": { "texture": "#1", "uv": [5, 5, 11, 11] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [7, 10, 7],
|
||||
"to": [9, 14, 9],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"top": { "texture": "#0", "uv": [0, 0, 2, 2] },
|
||||
"bottom": { "texture": "#0", "uv": [0, 0, 2, 2] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"model": {
|
||||
"id": "bworld:juicer_press",
|
||||
"textures": {
|
||||
"0": "bworld:juicer_side",
|
||||
"1": "bworld:juicer_bottom",
|
||||
"2": "bworld:juicer_top",
|
||||
"particle": "bworld:juicer_side"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"from": [0, 14, 0],
|
||||
"to": [16, 16, 16],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 16, 2] },
|
||||
"top": { "texture": "#2", "uv": [0, 0, 16, 16] },
|
||||
"bottom": { "texture": "#1", "uv": [0, 0, 16, 16] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [5, 8, 5],
|
||||
"to": [11, 10, 11],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"east": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"south": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"west": { "texture": "#0", "uv": [5, 0, 11, 2] },
|
||||
"top": { "texture": "#2", "uv": [5, 5, 11, 11] },
|
||||
"bottom": { "texture": "#1", "uv": [5, 5, 11, 11] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [7, 10, 7],
|
||||
"to": [9, 14, 9],
|
||||
"faces": {
|
||||
"north": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"east": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"south": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"west": { "texture": "#0", "uv": [0, 0, 2, 4] },
|
||||
"top": { "texture": "#0", "uv": [0, 0, 2, 2] },
|
||||
"bottom": { "texture": "#0", "uv": [0, 0, 2, 2] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import type {
|
||||
VisualBlock,
|
||||
} from "bworld/client";
|
||||
import { MINIGAMES } from "./minigames/mod.ts";
|
||||
import { JUICER_CAPACITY, type JuicerTank } from "./shared.ts";
|
||||
import { JUICER_CAPACITY, JUICER_PRESSES, type JuicerTank } from "./shared.ts";
|
||||
import { stonecutting_options, stonecutting_recipes } from "./stonecutting.ts";
|
||||
|
||||
const WIDTH = 176;
|
||||
@@ -44,13 +44,25 @@ const JUICER_ITEMS_A_COPY = 16;
|
||||
// it's full
|
||||
const JUICER_INSIDE = [2, 14];
|
||||
const JUICER_DEPTH = 12;
|
||||
// how far its press goes down, from where it rests to the floor, where the press that makes the juice would take it. it
|
||||
// goes a share of the way for each press toward the next juice, and back up once that's made
|
||||
const JUICER_PRESS_TRAVEL = 6 / 16;
|
||||
|
||||
// what's in the juicer and its juice, its "stack" and "tank" client data (see register_juicer in scripts/server.ts).
|
||||
// the items are drawn like create's basin draws its ingredients: tipped over and turned, with a copy more for every
|
||||
// the juicer's press, what's in it and its juice, by its "presses", "stack" and "tank" client data (see register_juicer
|
||||
// in scripts/server.ts). the press is its own model, not part of the block's, so it can go down as it's pressed. the
|
||||
// items are drawn like create's basin draws its ingredients: tipped over and turned, with a copy more for every
|
||||
// JUICER_ITEMS_A_COPY. each copy is turned further and a bit higher than the one under it, so they pile up
|
||||
function juicer_visual(block: VisualBlock, instances: Instances): Visual {
|
||||
const press = instances.transformed("bworld:juicer_press");
|
||||
const press_target = () => JUICER_PRESS_TRAVEL * (block.get_client_data<number>("presses") ?? 0) / JUICER_PRESSES;
|
||||
// how far down the press is, and where the presses say it goes, which it catches up with a quarter of the way each
|
||||
// tick. one made mid way starts there
|
||||
let target = press_target();
|
||||
let down: number | undefined;
|
||||
let last: number | undefined;
|
||||
let shown: Instance[] = [];
|
||||
const update = () => {
|
||||
target = press_target();
|
||||
for (const instance of shown) instance.delete();
|
||||
shown = [];
|
||||
const tank = block.get_client_data<JuicerTank>("tank");
|
||||
@@ -74,7 +86,17 @@ function juicer_visual(block: VisualBlock, instances: Instances): Visual {
|
||||
}));
|
||||
};
|
||||
update();
|
||||
return { update };
|
||||
return {
|
||||
update,
|
||||
on_frame(time) {
|
||||
const ticks = last === undefined ? 0 : time - last;
|
||||
last = time;
|
||||
if (down === target) return;
|
||||
down = down === undefined ? target : down + (target - down) * Math.min(1, ticks / 4);
|
||||
if (Math.abs(target - down) < 1 / 256) down = target;
|
||||
press.set_transform([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, -down, 0, 1]);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// a panel with the menu's title and the inventory's label over its rows, drawing anything else over it
|
||||
|
||||
@@ -8,7 +8,7 @@ import { register_effects } from "./effects.ts";
|
||||
import { register_fishing } from "./fishing.ts";
|
||||
import { stonecutting_options, stonecutting_recipes } from "./stonecutting.ts";
|
||||
import { register_verdigris } from "./verdigris/server.ts";
|
||||
import { type JuiceableParams, JUICER_CAPACITY, type JuicerTank } from "./shared.ts";
|
||||
import { type JuiceableParams, JUICER_CAPACITY, JUICER_PRESSES, type JuicerTank } from "./shared.ts";
|
||||
|
||||
export function setup(ctx: ServerContext) {
|
||||
register_hoeable(ctx);
|
||||
@@ -851,10 +851,9 @@ function register_buckets(ctx: ServerContext) {
|
||||
// the juicer has no screen. right clicking it with something juiceable puts that in, one kind at a time, and
|
||||
// pressing it (sneaking with an empty hand) JUICER_PRESSES times turns one of it into its juice, while that fits in the
|
||||
// tank. right clicking it with an empty fluid container fills it from the tank. breaking it drops what's in it, and the
|
||||
// juice is lost. clients see what's in it and its juice as its "stack" and "tank" client data, which its visual draws
|
||||
// (see scripts/client.ts)
|
||||
// juice is lost. clients see what's in it, its juice and how many times it's been pressed toward the next as its
|
||||
// "stack", "tank" and "presses" client data, which its visual draws (see scripts/client.ts)
|
||||
const JUICE = "bworld:juice";
|
||||
const JUICER_PRESSES = 4;
|
||||
|
||||
interface JuicerData {
|
||||
container?: string;
|
||||
@@ -910,6 +909,7 @@ function register_juicer(ctx: ServerContext) {
|
||||
const presses = (data.presses ?? 0) + 1;
|
||||
if (presses < JUICER_PRESSES) {
|
||||
block.data = { ...data, presses } satisfies JuicerData;
|
||||
block.set_client_data("presses", presses);
|
||||
return true;
|
||||
}
|
||||
item.count -= 1;
|
||||
@@ -917,6 +917,7 @@ function register_juicer(ctx: ServerContext) {
|
||||
const filled = { fluid: juice, amount: (tank?.amount ?? 0) + params.juice };
|
||||
block.data = { ...data, presses: 0, tank: filled } satisfies JuicerData;
|
||||
block.set_client_data("tank", filled);
|
||||
block.set_client_data("presses", undefined);
|
||||
return true;
|
||||
},
|
||||
on_break(block) {
|
||||
|
||||
@@ -147,6 +147,8 @@ export interface JuiceableParams {
|
||||
// how much juice the juicer holds, in mB, and the juice in it: in its tile data, and in its "tank" client data for its
|
||||
// visual to draw (see register_juicer in server.ts and juicer_visual in client.ts)
|
||||
export const JUICER_CAPACITY = 1000;
|
||||
// how many presses make one of what's in it into juice. its visual lowers its press for each one toward the next
|
||||
export const JUICER_PRESSES = 4;
|
||||
export interface JuicerTank {
|
||||
fluid: FluidVariant;
|
||||
amount: number;
|
||||
|
||||
+31
-4
@@ -96,6 +96,7 @@ Deno.test("the juicer takes juiceable items, juices one every 4 presses, and fil
|
||||
// what's in it and its juice, which clients see
|
||||
const shown = () => t.game.world.get_tile(1, 100, 0)?.client_data?.stack;
|
||||
const tank = () => t.game.world.get_tile(1, 100, 0)?.client_data?.tank;
|
||||
const presses = () => t.game.world.get_tile(1, 100, 0)?.client_data?.presses;
|
||||
const juice = { id: "bworld:juice", data: { item: CLOUDBERRY } };
|
||||
hold(CLOUDBERRY);
|
||||
use();
|
||||
@@ -107,14 +108,14 @@ Deno.test("the juicer takes juiceable items, juices one every 4 presses, and fil
|
||||
|
||||
// 2 cloudberries and 3 presses toward the next are 200 mB, not a bottle's 250
|
||||
press(11);
|
||||
assertEquals(tank(), { fluid: juice, amount: 200 });
|
||||
assertEquals([tank(), presses()], [{ fluid: juice, amount: 200 }, 3]);
|
||||
hold("bworld:glass_bottle");
|
||||
use();
|
||||
assertEquals(bottles(), [{ id: "bworld:glass_bottle", count: 2 }]);
|
||||
|
||||
// the 3rd makes 300 mB, a bottle and 50 mB left, which isn't another
|
||||
press(1);
|
||||
assertEquals(shown(), { id: CLOUDBERRY, count: 1 });
|
||||
assertEquals([shown(), presses()], [{ id: CLOUDBERRY, count: 1 }, undefined]);
|
||||
hold("bworld:glass_bottle");
|
||||
use();
|
||||
use();
|
||||
@@ -163,11 +164,15 @@ async function drawn_juicer() {
|
||||
return { visuals, set, done };
|
||||
}
|
||||
|
||||
Deno.test("the juicer draws what's in it, more of it the more there is, and nothing when it's empty", async () => {
|
||||
Deno.test("the juicer draws its press, what's in it, more of it the more there is, and nothing when it's empty", async () => {
|
||||
const { visuals, set, done } = await drawn_juicer();
|
||||
// the press, whatever's in it
|
||||
const press = [...visuals.groups()].filter((group) => group.instances.length > 0);
|
||||
assertEquals(press.map((group) => group.instances.length), [1]);
|
||||
// one item, however many of it are drawn
|
||||
const drawn = () =>
|
||||
[...visuals.groups()].filter((group) => group.instances.length > 0).map((group) => group.instances.length);
|
||||
[...visuals.groups()].filter((group) => !press.includes(group) && group.instances.length > 0)
|
||||
.map((group) => group.instances.length);
|
||||
|
||||
set("stack", { id: CLOUDBERRY, count: 1 });
|
||||
const one = drawn();
|
||||
@@ -203,3 +208,25 @@ Deno.test("the juicer's juice fills its 12 by 12 floor, a pixel deep while there
|
||||
assertEquals(boxes(), []);
|
||||
done();
|
||||
});
|
||||
|
||||
Deno.test("the juicer's press goes down a share of the way each press, easing there, and back up once there's juice", async () => {
|
||||
const { visuals, set, done } = await drawn_juicer();
|
||||
const [press] = [...visuals.groups()].filter((group) => group.instances.length > 0);
|
||||
// how far below its block it is
|
||||
const down = () => 100 - press.instances[0].placement[13];
|
||||
const frame = (time: number) => visuals.frame([{ x: 0, z: 0 }], time);
|
||||
frame(0);
|
||||
assertEquals(down(), 0);
|
||||
|
||||
// half way to the 4th press, which would take it 6 pixels down to the floor
|
||||
set("presses", 2);
|
||||
frame(1);
|
||||
assert(down() > 0 && down() < 3 / 16, `${down()}`);
|
||||
frame(5);
|
||||
assertEquals(down(), 3 / 16);
|
||||
// the juice is made, so it's back up
|
||||
set("presses", undefined);
|
||||
frame(9);
|
||||
assertEquals(down(), 0);
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user