Juicer recipes
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
// how each recipe type is shown, like jei's IRecipeCategory: a title, a fixed size every recipe of it is drawn in, the
|
||||
// blocks it's made in (jei's recipe catalysts), and where its items go. types no category knows get one from their
|
||||
// recipes' json, see mod_category
|
||||
import type { ClientContext, TagApi } from "bworld/client";
|
||||
import type { ClientContext, FluidVariant, TagApi } from "bworld/client";
|
||||
import { type Ingredient, mod_recipe_inputs, outputs, type Recipe, seconds, stack } from "./recipes.ts";
|
||||
|
||||
// in gui pixels, a slot with its border, like minecraft's
|
||||
@@ -17,6 +17,8 @@ const ARROW = 16;
|
||||
export interface RecipeLayout {
|
||||
// a slot, empty when ingredient is undefined. alternatives take turns
|
||||
slot(ingredient: Ingredient | undefined, x: number, y: number, tooltip?: string[]): void;
|
||||
// an amount of a fluid in a slot, in mB, like jei's fluid ingredients
|
||||
fluid(fluid: FluidVariant, amount: number, x: number, y: number, tooltip?: string[]): void;
|
||||
texture(id: string, x: number, y: number, w: number, h: number): void;
|
||||
text(text: string, x: number, y: number): void;
|
||||
}
|
||||
@@ -158,9 +160,40 @@ function base_categories(tags: TagApi): RecipeCategory[] {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
// what the juicer presses an item into, see juicing_recipes
|
||||
type: JUICING,
|
||||
title: "Juicing",
|
||||
width: 116,
|
||||
height: 18,
|
||||
catalysts: [JUICER],
|
||||
draw(recipe, layout) {
|
||||
const { fluid, amount } = recipe.juice as { fluid: FluidVariant; amount: number };
|
||||
layout.slot({ ids: [recipe.input], count: 1 }, 0, 0);
|
||||
layout.texture("bworld:arrow_full", 31, 1, ARROW, ARROW);
|
||||
layout.fluid(fluid, amount, 60, 0);
|
||||
layout.text(`${amount} mB`, 82, 5);
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
// the base game's juicer, from the items with bworld:juiceable: a recipe of its own type for each, that presses one
|
||||
// of it into its juice. the item is an input like any recipe's, the juice is under "juice", which reading a recipe's
|
||||
// inputs skips. the juice's data is the item it's from, like the juicer makes it
|
||||
const JUICING = "bworld:juicing";
|
||||
const JUICER = "bworld:juicer";
|
||||
|
||||
export function juicing_recipes(ctx: ClientContext): Recipe[] {
|
||||
if (!ctx.fluids.exists("bworld:juice")) return [];
|
||||
return ctx.items.ids().flatMap((id) => {
|
||||
const params = ctx.items.components(id)["bworld:juiceable"] as { juice?: number } | undefined;
|
||||
if (!params?.juice) return [];
|
||||
const juice = { fluid: { id: "bworld:juice", data: { item: id } }, amount: params.juice };
|
||||
return [{ type: JUICING, input: id, juice }];
|
||||
});
|
||||
}
|
||||
|
||||
// the base game's fish, the items with bworld:fish, as recipes of their own type that make them, so clicking one shows
|
||||
// when and where it bites. their params are under "fish", which reading a recipe's inputs skips
|
||||
const FISHING = "bworld:fishing";
|
||||
@@ -300,6 +333,7 @@ export function category_name(type: string): string {
|
||||
smithing: "Smithing",
|
||||
[FISHING]: "Fishing",
|
||||
[CRABPOT]: "Crab Pot",
|
||||
[JUICING]: "Juicing",
|
||||
};
|
||||
if (base[type]) return base[type];
|
||||
const name = type.split(":")[1] ?? type;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// every item, right of the inventory and of the recipes screen, like jei's ingredient list overlay: the page and its
|
||||
// arrows on top, the items, and the search box under them
|
||||
import type { ClientContext, Color, Graphics } from "bworld/client";
|
||||
import type { ClientContext, Color, FluidVariant, Graphics } from "bworld/client";
|
||||
import { SLOT } from "./categories.ts";
|
||||
|
||||
const GAP = 5;
|
||||
@@ -13,6 +13,8 @@ export const SLOT_COLOR: Color = [0.07, 0.07, 0.11, 0.6];
|
||||
const HOVER_COLOR: Color = [0.96, 0.76, 0.91, 0.35];
|
||||
export const LABEL_COLOR: Color = [0.65, 0.68, 0.78, 1];
|
||||
const MOD_COLOR: Color = [0.54, 0.71, 0.98, 1];
|
||||
// the engine's for the fluid in an item's tooltip
|
||||
const FLUID_COLOR: Color = [0.55, 0.75, 0.95, 1];
|
||||
|
||||
// show the recipes that make an item, or the ones that use it
|
||||
export type Mode = "recipes" | "uses";
|
||||
@@ -48,6 +50,33 @@ export function item_cell(
|
||||
return true;
|
||||
}
|
||||
|
||||
// an amount of a fluid in a slot, hovered for its name and amount. fluids have no recipes of their own to open
|
||||
export function fluid_cell(
|
||||
g: Graphics,
|
||||
ctx: ClientContext,
|
||||
fluid: FluidVariant,
|
||||
amount: number,
|
||||
x: number,
|
||||
y: number,
|
||||
tooltip: string[] = [],
|
||||
) {
|
||||
g.rect(x, y, SLOT, SLOT, SLOT_COLOR);
|
||||
g.fluid(fluid, x, y);
|
||||
const { mouse } = g;
|
||||
if (mouse.x < x || mouse.y < y || mouse.x >= x + SLOT || mouse.y >= y + SLOT) return;
|
||||
g.rect(x, y, SLOT, SLOT, HOVER_COLOR);
|
||||
g.tooltip(
|
||||
[
|
||||
ctx.fluids.name(fluid),
|
||||
{ text: `${amount} mB`, color: FLUID_COLOR },
|
||||
...tooltip.map((text) => ({ text, color: LABEL_COLOR })),
|
||||
{ text: fluid.id, color: LABEL_COLOR },
|
||||
],
|
||||
mouse.x,
|
||||
mouse.y,
|
||||
);
|
||||
}
|
||||
|
||||
export class ItemList {
|
||||
// kept between screens, like jei
|
||||
page = 0;
|
||||
|
||||
@@ -9,12 +9,13 @@ import type { ClientContext, Graphics, Screen } from "bworld/client";
|
||||
import {
|
||||
crabpot_recipes,
|
||||
fishing_recipes,
|
||||
juicing_recipes,
|
||||
make_categories,
|
||||
type RecipeCategory,
|
||||
type RecipeLayout,
|
||||
SLOT,
|
||||
} from "./categories.ts";
|
||||
import { BUTTON, item_cell, ItemList, LABEL_COLOR, type Mode, SLOT_COLOR } from "./item_list.ts";
|
||||
import { BUTTON, fluid_cell, item_cell, ItemList, LABEL_COLOR, type Mode, SLOT_COLOR } from "./item_list.ts";
|
||||
import { type Ingredient, inputs, outputs, type Recipe } from "./recipes.ts";
|
||||
|
||||
// jei's sizes, in gui pixels
|
||||
@@ -42,7 +43,12 @@ export class RecipeIndex {
|
||||
|
||||
get categories(): RecipeCategory[] {
|
||||
if (!this.#categories) {
|
||||
this.#recipes = [...this.ctx.recipes.list(), ...fishing_recipes(this.ctx), ...crabpot_recipes(this.ctx)];
|
||||
this.#recipes = [
|
||||
...this.ctx.recipes.list(),
|
||||
...fishing_recipes(this.ctx),
|
||||
...crabpot_recipes(this.ctx),
|
||||
...juicing_recipes(this.ctx),
|
||||
];
|
||||
this.#categories = make_categories(this.ctx, this.#recipes);
|
||||
}
|
||||
return this.#categories;
|
||||
@@ -208,6 +214,7 @@ export class RecipesScreen implements Screen {
|
||||
const options = { slot: true, count: ingredient.count, tooltip: [...any, ...tooltip] };
|
||||
if (this.#cell(g, id, x + dx, y + dy, options)) hovered = id;
|
||||
},
|
||||
fluid: (fluid, amount, dx, dy, tooltip) => fluid_cell(g, this.ctx, fluid, amount, x + dx, y + dy, tooltip),
|
||||
texture: (id, dx, dy, w, h) => g.texture(id, x + dx, y + dy, w, h),
|
||||
text: (text, dx, dy) => g.text(text, x + dx, y + dy, { color: LABEL_COLOR }),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user