Loot tables

This commit is contained in:
2026-10-08 00:54:45 -03:00
parent 757ee74bc7
commit ec2b53c02a
45 changed files with 1733 additions and 150 deletions
+2 -6
View File
@@ -33,6 +33,7 @@
"mining": {
"toughness": 0
},
"loot_table": "bworld:blocks/carrots",
"item": false,
"place_on": [
"bworld:hoed_dirt"
@@ -48,12 +49,7 @@
"bworld:crop": {
"days": 3,
"stages": 4,
"fertilizer": "bworld:bone_meal",
"drops": {
"young": "bworld:carrot",
"mature": "bworld:carrot",
"bonus": "bworld:carrot"
}
"fertilizer": "bworld:bone_meal"
}
}
}
+2 -6
View File
@@ -33,6 +33,7 @@
"mining": {
"toughness": 0
},
"loot_table": "bworld:blocks/potatoes",
"item": false,
"place_on": [
"bworld:hoed_dirt"
@@ -48,12 +49,7 @@
"bworld:crop": {
"days": 6,
"stages": 4,
"fertilizer": "bworld:bone_meal",
"drops": {
"young": "bworld:potato",
"mature": "bworld:potato",
"bonus": "bworld:potato"
}
"fertilizer": "bworld:bone_meal"
}
}
}
+2 -6
View File
@@ -53,6 +53,7 @@
"mining": {
"toughness": 0
},
"loot_table": "bworld:blocks/wheat",
"item": false,
"place_on": [
"bworld:hoed_dirt"
@@ -68,12 +69,7 @@
"bworld:crop": {
"days": 7,
"stages": 8,
"fertilizer": "bworld:bone_meal",
"drops": {
"young": "bworld:wheat_seeds",
"mature": "bworld:wheat",
"bonus": "bworld:wheat_seeds"
}
"fertilizer": "bworld:bone_meal"
}
}
}
+9 -6
View File
@@ -10,12 +10,15 @@
"lore": "Right click to cast into water, and again when something bites.",
"components": {
"bworld:fishing_rod": {
"wait": [100, 600],
"bite": [20, 40],
"loot": [
{ "item": "bworld:cod", "weight": 60 },
{ "item": "bworld:salmon", "weight": 25 }
]
"wait": [
100,
600
],
"bite": [
20,
40
],
"loot_table": "bworld:gameplay/fishing"
}
}
}
@@ -0,0 +1,39 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:carrot"
}
]
},
{
"conditions": [
{
"condition": "block_state",
"states": {
"age": 3
}
}
],
"entries": [
{
"item": "bworld:carrot",
"functions": [
{
"function": "set_count",
"count": {
"n": 3,
"p": 0.5714
},
"add": true
}
]
}
]
}
]
}
}
@@ -0,0 +1,39 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:potato"
}
]
},
{
"conditions": [
{
"condition": "block_state",
"states": {
"age": 3
}
}
],
"entries": [
{
"item": "bworld:potato",
"functions": [
{
"function": "set_count",
"count": {
"n": 3,
"p": 0.5714
},
"add": true
}
]
}
]
}
]
}
}
+61
View File
@@ -0,0 +1,61 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:wheat",
"conditions": [
{
"condition": "block_state",
"states": {
"age": 7
}
}
]
},
{
"item": "bworld:wheat_seeds",
"conditions": [
{
"condition": "inverted",
"term": {
"condition": "block_state",
"states": {
"age": 7
}
}
}
]
}
]
},
{
"conditions": [
{
"condition": "block_state",
"states": {
"age": 7
}
}
],
"entries": [
{
"item": "bworld:wheat_seeds",
"functions": [
{
"function": "set_count",
"count": {
"n": 3,
"p": 0.5714
},
"add": true
}
]
}
]
}
]
}
}
@@ -0,0 +1,19 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:cod",
"weight": 60
},
{
"item": "bworld:salmon",
"weight": 25
}
]
}
]
}
}
+10 -49
View File
@@ -352,18 +352,6 @@ interface WateringCanData {
}
// items as they appear in crop params: one id, or several
type Items = string | string[];
// what a crop drops when broken, like the loot tables of minecraft's and farmer's delight's crops
interface CropDrops {
// before it's fully grown, like wheat's seeds
young?: Items;
// fully grown, like wheat's wheat
mature?: Items;
// fully grown, 1 to 4 of this, like the seeds from wheat (minecraft's loot tables: 1 plus 3 tries at 57%)
bonus?: string;
}
// a crop, like minecraft's CropBlock: its "age" state is its stage, and it grows one day every morning its farmland was
// watered the day before. see docs/modding/blocks/crops.md
interface CropParams {
@@ -371,10 +359,10 @@ interface CropParams {
days: number;
// how many stages it shows, ages 0 to stages - 1. its "age" state must fit them
stages: number;
drops?: CropDrops;
// grows back after it's harvested by right clicking, like tomatoes
// grows back after it's harvested by right clicking, like tomatoes, giving what this loot table does. what it
// drops when broken is the block's own loot table
regrow_days?: number;
harvest?: { item: string; count: [number, number] };
harvest?: string;
// grows it a day right away, like bone meal
fertilizer?: string;
// "farmland" (the default) needs watered farmland under it, "always" grows every morning, like rice in water
@@ -388,7 +376,6 @@ interface CropParams {
// the top of a two block crop. it grows with the crop under it, and breaking it breaks the whole plant
interface CropTopParams {
stages: number;
drops?: CropDrops;
}
function register_farming(ctx: ServerContext) {
@@ -439,17 +426,6 @@ function register_farming(ctx: ServerContext) {
},
});
const list = (items: Items | undefined) => items === undefined ? [] : typeof items === "string" ? [items] : items;
const drop = (x: number, y: number, z: number, drops: CropDrops | undefined, mature: boolean) => {
for (const id of list(mature ? drops?.mature : drops?.young)) ctx.world.drop_item(x, y, z, { id, count: 1 });
if (mature && drops?.bonus) {
let count = 1;
for (let i = 0; i < 3; i++) if (Math.random() < 0.5714) count++;
ctx.world.drop_item(x, y, z, { id: drops.bonus, count });
}
};
// the stage for how many days it has grown: evenly spread, fully grown on the last day
const stage_for = (params: CropParams, days: number) => {
const stages = params.stages + (params.upper?.stages ?? 0);
@@ -486,8 +462,6 @@ function register_farming(ctx: ServerContext) {
ctx.world.set_state(block.x, block.y + 1, block.z, "age", stage - params.stages);
};
const is_grown = (block: BlockRef, params: CropParams) => days_of(block, params) >= params.days;
ctx.components.register_block<CropParams>("bworld:crop", {
// block data so on_new_day runs for it. placed at a later stage (by a script), it has grown that long
on_create(block, params) {
@@ -517,16 +491,14 @@ function register_farming(ctx: ServerContext) {
}
// regrowing crops are picked by hand and grow back, like farmer's delight's tomatoes
if (params.regrow_days && params.harvest && days >= params.days) {
const [min, max] = params.harvest.count;
const count = min + Math.floor(Math.random() * (max - min + 1));
ctx.world.drop_item(block.x, block.y, block.z, { id: params.harvest.item, count });
const loot = ctx.loot.roll(params.harvest, { block, player, tool: held });
for (const item of loot) ctx.world.drop_item(block.x, block.y, block.z, item);
set_days(block, params, Math.max(0, params.days - params.regrow_days));
return true;
}
return false;
},
on_break(block, params) {
drop(block.x, block.y, block.z, params.drops, is_grown(block, params));
if (params.leaves) {
const { x, y, z } = block;
const leaves = params.leaves;
@@ -539,9 +511,7 @@ function register_farming(ctx: ServerContext) {
});
ctx.components.register_block<CropTopParams>("bworld:crop_top", {
on_break(block, params) {
const age = ctx.world.get_state(block.x, block.y, block.z, "age") ?? 0;
drop(block.x, block.y, block.z, params.drops, age >= params.stages - 1);
on_break(block) {
// the plant under it goes too, once this is gone
const { x, y, z } = block;
const lower = ctx.world.get_block(x, y - 1, z);
@@ -658,7 +628,8 @@ interface FishingRodParams {
wait: [number, number];
// ticks it stays on the hook before it gets away
bite: [number, number];
loot: { item: string; weight: number }[];
// what's caught, a loot table
loot_table: string;
}
interface Cast {
@@ -684,16 +655,6 @@ function register_fishing(ctx: ServerContext) {
const between = ([min, max]: [number, number]) => min + Math.floor(Math.random() * (max - min + 1));
const pick = (loot: FishingRodParams["loot"]) => {
const total = loot.reduce((sum, entry) => sum + entry.weight, 0);
let roll = Math.random() * total;
for (const entry of loot) {
roll -= entry.weight;
if (roll < 0) return entry.item;
}
return loot.at(-1)?.item;
};
const fishable = new Map<string, boolean>();
const is_fishable = (id: string) => {
let result = fishable.get(id);
@@ -745,8 +706,8 @@ function register_fishing(ctx: ServerContext) {
const cast = casts.get(player.id);
if (cast) {
if (cast.escape_at !== undefined) {
const item = pick(params.loot);
if (item) player.give_item(item);
const loot = ctx.loot.roll(params.loot_table, { position: cast.position, player, tool: rod });
for (const item of loot) player.give_item(item.id, item.count, item.data);
}
stop(player, player.id);
return;
+2 -6
View File
@@ -53,6 +53,7 @@
"mining": {
"toughness": 0
},
"loot_table": "farmersdelight:blocks/cabbages",
"item": false,
"place_on": [
"bworld:hoed_dirt"
@@ -68,12 +69,7 @@
"bworld:crop": {
"days": 12,
"stages": 8,
"fertilizer": "bworld:bone_meal",
"drops": {
"young": "farmersdelight:cabbage_seeds",
"mature": "farmersdelight:cabbage",
"bonus": "farmersdelight:cabbage_seeds"
}
"fertilizer": "bworld:bone_meal"
}
}
}
+2 -6
View File
@@ -33,6 +33,7 @@
"mining": {
"toughness": 0
},
"loot_table": "farmersdelight:blocks/onions",
"item": false,
"place_on": [
"bworld:hoed_dirt"
@@ -48,12 +49,7 @@
"bworld:crop": {
"days": 4,
"stages": 4,
"fertilizer": "bworld:bone_meal",
"drops": {
"young": "farmersdelight:onion",
"mature": "farmersdelight:onion",
"bonus": "farmersdelight:onion"
}
"fertilizer": "bworld:bone_meal"
}
}
}
+2 -5
View File
@@ -40,6 +40,7 @@
"mining": {
"toughness": 0
},
"loot_table": "farmersdelight:blocks/rice",
"item": false,
"place_on": [
"bworld:dirt",
@@ -67,11 +68,7 @@
"stages": 4,
"supporting_age": 4
},
"leaves": "bworld:water",
"drops": {
"young": "farmersdelight:rice",
"mature": "farmersdelight:rice"
}
"leaves": "bworld:water"
}
}
}
@@ -33,6 +33,7 @@
"mining": {
"toughness": 0
},
"loot_table": "farmersdelight:blocks/rice_panicles",
"item": false,
"place_on": [
"farmersdelight:rice"
@@ -46,10 +47,7 @@
],
"components": {
"bworld:crop_top": {
"stages": 4,
"drops": {
"mature": "farmersdelight:rice_panicle"
}
"stages": 4
}
}
}
+2 -14
View File
@@ -53,6 +53,7 @@
"mining": {
"toughness": 0
},
"loot_table": "farmersdelight:blocks/tomatoes",
"item": false,
"place_on": [
"bworld:hoed_dirt"
@@ -70,20 +71,7 @@
"stages": 8,
"fertilizer": "bworld:bone_meal",
"regrow_days": 4,
"harvest": {
"item": "farmersdelight:tomato",
"count": [
1,
2
]
},
"drops": {
"young": "farmersdelight:tomato_seeds",
"mature": [
"farmersdelight:tomato",
"farmersdelight:tomato_seeds"
]
}
"harvest": "farmersdelight:harvest/tomatoes"
}
}
}
@@ -0,0 +1,61 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "farmersdelight:cabbage",
"conditions": [
{
"condition": "block_state",
"states": {
"age": 7
}
}
]
},
{
"item": "farmersdelight:cabbage_seeds",
"conditions": [
{
"condition": "inverted",
"term": {
"condition": "block_state",
"states": {
"age": 7
}
}
}
]
}
]
},
{
"conditions": [
{
"condition": "block_state",
"states": {
"age": 7
}
}
],
"entries": [
{
"item": "farmersdelight:cabbage_seeds",
"functions": [
{
"function": "set_count",
"count": {
"n": 3,
"p": 0.5714
},
"add": true
}
]
}
]
}
]
}
}
@@ -0,0 +1,39 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "farmersdelight:onion"
}
]
},
{
"conditions": [
{
"condition": "block_state",
"states": {
"age": 3
}
}
],
"entries": [
{
"item": "farmersdelight:onion",
"functions": [
{
"function": "set_count",
"count": {
"n": 3,
"p": 0.5714
},
"add": true
}
]
}
]
}
]
}
}
@@ -0,0 +1,14 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "farmersdelight:rice"
}
]
}
]
}
}
@@ -0,0 +1,22 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"conditions": [
{
"condition": "block_state",
"states": {
"age": 3
}
}
],
"entries": [
{
"item": "farmersdelight:rice_panicle"
}
]
}
]
}
}
@@ -0,0 +1,29 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "farmersdelight:tomato_seeds"
}
]
},
{
"conditions": [
{
"condition": "block_state",
"states": {
"age": 7
}
}
],
"entries": [
{
"item": "farmersdelight:tomato"
}
]
}
]
}
}
@@ -0,0 +1,18 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "farmersdelight:tomato",
"count": {
"min": 1,
"max": 2
}
}
]
}
]
}
}