|
|
|
@@ -12,6 +12,7 @@ export function setup(ctx: ServerContext) {
|
|
|
|
|
register_trapdoor(ctx);
|
|
|
|
|
register_farming(ctx);
|
|
|
|
|
register_fishing(ctx);
|
|
|
|
|
register_buckets(ctx);
|
|
|
|
|
register_curios(ctx);
|
|
|
|
|
register_effects(ctx);
|
|
|
|
|
}
|
|
|
|
@@ -573,6 +574,52 @@ function register_farming(ctx: ServerContext) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// buckets, like minecraft's: right clicking water with a bucket picks it up into a water bucket, which places it back
|
|
|
|
|
// and is a bucket again
|
|
|
|
|
|
|
|
|
|
// right clicking it with a bucket takes it away, giving the filled bucket
|
|
|
|
|
interface BucketableParams {
|
|
|
|
|
into: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// what a filled bucket is once it has placed its block
|
|
|
|
|
interface FilledBucketParams {
|
|
|
|
|
empty: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BUCKET = "bworld:bucket";
|
|
|
|
|
|
|
|
|
|
function register_buckets(ctx: ServerContext) {
|
|
|
|
|
ctx.components.register_block<BucketableParams>("bworld:bucketable", {
|
|
|
|
|
on_interact(block, params, player) {
|
|
|
|
|
const bucket = player.held_item;
|
|
|
|
|
if (bucket?.id !== BUCKET) return false;
|
|
|
|
|
ctx.world.set_block(block.x, block.y, block.z, "bworld:air");
|
|
|
|
|
bucket.count -= 1;
|
|
|
|
|
// the last one becomes the filled bucket in the hand, from a stack it goes in the inventory
|
|
|
|
|
if (bucket.count <= 0) player.inventory.set(player.selected_slot, { id: params.into, count: 1 });
|
|
|
|
|
else player.give_item(params.into);
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// read from the item's json when it places its block
|
|
|
|
|
ctx.components.register_item<FilledBucketParams>("bworld:filled_bucket", {});
|
|
|
|
|
// the empty bucket for what each player is placing. the event's item is their slot, which placing empties, so it's
|
|
|
|
|
// read before
|
|
|
|
|
const emptying = new Map<string, string>();
|
|
|
|
|
ctx.events.before.block_place.subscribe(({ player, item }) => {
|
|
|
|
|
const params = item && ctx.items.components(item.id)["bworld:filled_bucket"] as FilledBucketParams | undefined;
|
|
|
|
|
if (params) emptying.set(player.id, params.empty);
|
|
|
|
|
else emptying.delete(player.id);
|
|
|
|
|
});
|
|
|
|
|
ctx.events.after.block_place.subscribe(({ player }) => {
|
|
|
|
|
const empty = emptying.get(player.id);
|
|
|
|
|
emptying.delete(player.id);
|
|
|
|
|
if (empty) player.inventory.set(player.selected_slot, { id: empty, count: 1 });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fishing, like minecraft's: right click water with a rod to cast, wait for a bite, and right click again before it
|
|
|
|
|
// gets away to reel it in. the hook floats on the water, and goes under when something bites
|
|
|
|
|
|
|
|
|
|