Crabpot !!
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"loot_table": {
|
||||
"pools": [
|
||||
{
|
||||
"entries": [
|
||||
{ "item": "bworld:crayfish" },
|
||||
{ "item": "bworld:chorus_snail" },
|
||||
{ "item": "bworld:leech" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"loot_table": {
|
||||
"pools": [
|
||||
{
|
||||
"entries": [
|
||||
{ "item": "bworld:ocean_hermit_crab" },
|
||||
{ "item": "bworld:cold_ocean_hermit_crab" },
|
||||
{ "item": "bworld:frozen_ocean_hermit_crab" },
|
||||
{ "item": "bworld:lukewarm_ocean_hermit_crab" },
|
||||
{ "item": "bworld:warm_ocean_hermit_crab" },
|
||||
{ "item": "bworld:clam" },
|
||||
{ "item": "bworld:lobster" },
|
||||
{ "item": "bworld:shrimp" },
|
||||
{ "item": "bworld:crab" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -263,9 +263,12 @@ const ADDITION = 2;
|
||||
const RESULT = 3;
|
||||
|
||||
// the crab pot's menu: its bait slot at the top, and a row of 9 slots under it for what it catches, which players can
|
||||
// only take from. it doesn't catch anything yet
|
||||
// only take from. every morning a crab pot in water with worms in it uses one up to catch something: from the
|
||||
// saltwater table in an ocean, the freshwater one anywhere else. a catch that doesn't fit is let go, and keeps the
|
||||
// worm
|
||||
const CRABPOT_BAIT = 0;
|
||||
const CRABPOT_OUTPUT = 9;
|
||||
const CRABPOT_WORMS = "bworld:worms";
|
||||
|
||||
function register_crabpot(ctx: ServerContext) {
|
||||
const menu_type = ctx.menus.register<BlockRef>("bworld:crabpot", (menu, block) => {
|
||||
@@ -287,6 +290,41 @@ function register_crabpot(ctx: ServerContext) {
|
||||
on_break(block) {
|
||||
drop_contents(ctx, block);
|
||||
},
|
||||
on_new_day(block) {
|
||||
const { x, y, z } = block;
|
||||
if (ctx.world.get_state(x, y, z, "waterlogged") !== 1) {
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
if (!bait || bait.id !== CRABPOT_WORMS) {
|
||||
return;
|
||||
}
|
||||
|
||||
const table = ctx.tags.has("biomes", "bworld:is_ocean", block.biome)
|
||||
? "bworld:gameplay/crabpot_saltwater"
|
||||
: "bworld:gameplay/crabpot_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
|
||||
let slot = -1;
|
||||
for (let i = 1; i <= CRABPOT_OUTPUT && slot < 0; i++) {
|
||||
const there = container.get(i);
|
||||
if (there?.id === item.id && there.count + item.count <= ctx.items.max_stack(item.id)) {
|
||||
slot = i;
|
||||
}
|
||||
}
|
||||
for (let i = 1; i <= CRABPOT_OUTPUT && slot < 0; i++) {
|
||||
if (!container.get(i)) slot = i;
|
||||
}
|
||||
if (slot < 0) return;
|
||||
const there = container.get(slot);
|
||||
if (there) there.count += item.count;
|
||||
else container.set(slot, item);
|
||||
}
|
||||
bait.count -= 1;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user