Recipe viewer for crabpots
This commit is contained in:
@@ -32,7 +32,18 @@
|
||||
"waterloggable": "bworld:water",
|
||||
"interactive": true,
|
||||
"components": {
|
||||
"bworld:crabpot": {}
|
||||
"bworld:crabpot": {
|
||||
"baits": {
|
||||
"bworld:worms": {
|
||||
"freshwater": "bworld:gameplay/crabpot_worms_freshwater",
|
||||
"saltwater": "bworld:gameplay/crabpot_worms_saltwater"
|
||||
},
|
||||
"bworld:grubs": {
|
||||
"freshwater": "bworld:gameplay/crabpot_grubs_freshwater",
|
||||
"saltwater": "bworld:gameplay/crabpot_grubs_saltwater"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,8 +274,11 @@ const RESULT = 3;
|
||||
// bait
|
||||
const CRABPOT_BAIT = 0;
|
||||
const CRABPOT_OUTPUT = 9;
|
||||
// each bait's loot tables, bworld:gameplay/crabpot_<name>_saltwater and _freshwater
|
||||
const CRABPOT_BAITS: Record<string, string> = { "bworld:worms": "worms", "bworld:grubs": "grubs" };
|
||||
|
||||
// the bworld:crabpot component's params: each bait's loot tables, read by the recipe viewer too
|
||||
interface CrabpotParams {
|
||||
baits: Record<string, { freshwater: string; saltwater: string }>;
|
||||
}
|
||||
|
||||
function register_crabpot(ctx: ServerContext) {
|
||||
const menu_type = ctx.menus.register<BlockRef>("bworld:crabpot", (menu, block) => {
|
||||
@@ -289,7 +292,7 @@ function register_crabpot(ctx: ServerContext) {
|
||||
menu.still_valid_near(block);
|
||||
});
|
||||
|
||||
ctx.components.register_block("bworld:crabpot", {
|
||||
ctx.components.register_block<CrabpotParams>("bworld:crabpot", {
|
||||
on_interact(block, _params, player) {
|
||||
menu_type.open(player, block);
|
||||
return true;
|
||||
@@ -297,7 +300,7 @@ function register_crabpot(ctx: ServerContext) {
|
||||
on_break(block) {
|
||||
drop_contents(ctx, block);
|
||||
},
|
||||
on_new_day(block) {
|
||||
on_new_day(block, params) {
|
||||
const { x, y, z } = block;
|
||||
if (ctx.world.get_state(x, y, z, "waterlogged") !== 1) {
|
||||
return;
|
||||
@@ -305,13 +308,12 @@ function register_crabpot(ctx: ServerContext) {
|
||||
// one that's never been opened has nothing in it
|
||||
const container = block.data?.container && ctx.containers.get(block.data.container);
|
||||
const bait = container && container.get(CRABPOT_BAIT);
|
||||
const bait_name = bait && CRABPOT_BAITS[bait.id];
|
||||
if (!bait || !bait_name) {
|
||||
const tables = bait && params.baits[bait.id];
|
||||
if (!bait || !tables) {
|
||||
return;
|
||||
}
|
||||
|
||||
const water = ctx.tags.has("biomes", "bworld:is_ocean", block.biome) ? "saltwater" : "freshwater";
|
||||
const table = `bworld:gameplay/crabpot_${bait_name}_${water}`;
|
||||
const table = ctx.tags.has("biomes", "bworld:is_ocean", block.biome) ? tables.saltwater : tables.freshwater;
|
||||
const position = { x: x + 0.5, y: y + 0.5, z: z + 0.5 };
|
||||
for (const item of ctx.loot.roll(table, { position })) {
|
||||
// onto a stack of it with room, or into an empty output slot
|
||||
|
||||
Reference in New Issue
Block a user