Compare commits
2
Commits
3cf4b10b8c
...
5481ec94a4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5481ec94a4 | ||
|
|
4524cfe960 |
@@ -177,10 +177,17 @@ function seeded_random(seed: string) {
|
||||
};
|
||||
}
|
||||
|
||||
// the block a block's own item looks like. other items that place a block, like seeds or a water bucket, look like
|
||||
// their own texture
|
||||
export function placed_block(item: ItemStack): BlockRegistry | undefined {
|
||||
const item_info = EverythingRegistry.get<ItemRegistry>("items", item.type_id);
|
||||
if (!item_info?.block_id || item_info.block_id !== item.type_id) return undefined;
|
||||
return EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id);
|
||||
}
|
||||
|
||||
// the full block an item places, drawn as a cube. blocks that aren't cubes, like plants, are drawn as their sprite
|
||||
export function item_block(item: ItemStack): BlockRegistry | undefined {
|
||||
const item_info = EverythingRegistry.get<ItemRegistry>("items", item.type_id);
|
||||
const block = item_info?.block_id ? EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id) : undefined;
|
||||
const block = placed_block(item);
|
||||
return block && block_item_texture(block) === undefined ? block : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
ITEM_FACE_SHADE,
|
||||
item_tint,
|
||||
} from "$/common/block_models.ts";
|
||||
import { item_model_quads, sprite_u, sprite_v } from "./item_renderer.ts";
|
||||
import { item_model_quads, placed_block, sprite_u, sprite_v } from "./item_renderer.ts";
|
||||
import {
|
||||
draw_rect,
|
||||
draw_text,
|
||||
@@ -83,9 +83,7 @@ export function draw_item(item: ItemStack, x: number, y: number) {
|
||||
throw Error(`Didn't find item registry for '${item.type_id}'`);
|
||||
}
|
||||
|
||||
const block_info = item_info.block_id
|
||||
? EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id)
|
||||
: undefined;
|
||||
const block_info = placed_block(item);
|
||||
// blocks that aren't cubes, like plants, show a flat sprite
|
||||
const model = block_info && item_model_quads(block_info);
|
||||
if (block_info && model) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"check-mods": "deno run --allow-read --allow-run tools/check_mods.ts",
|
||||
"pack-mod": "deno run --allow-read --allow-write --allow-run --allow-env tools/pack_mod.ts",
|
||||
"test": "deno test --allow-read --allow-write --allow-run tests/",
|
||||
"desktop": "deno run -A build.ts --once && deno desktop --allow-read --allow-write --allow-net --allow-ffi --allow-env=BWORLD_SERVER,BWORLD_CLIENT_UPDATES,HOME,USERPROFILE,APPDATA,XDG_DATA_HOME --include build --include server_mods --include server/game/worker.ts --include desktop/config.json desktop/main.ts && deno run --allow-read --allow-write desktop/linux_launcher.ts dist/bworld"
|
||||
"desktop": "deno run -A build.ts --once && deno desktop --allow-read --allow-write --allow-net --allow-ffi --allow-env=BWORLD_SERVER,BWORLD_CLIENT_UPDATES,HOME,USERPROFILE,APPDATA,XDG_DATA_HOME,DEBUG --include build --include server_mods --include server/game/worker.ts --include desktop/config.json desktop/main.ts && deno run --allow-read --allow-write desktop/linux_launcher.ts dist/bworld"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"lib": ["dom", "dom.asynciterable", "dom.iterable", "deno.ns", "deno.unstable", "deno.webgpu"]
|
||||
|
||||
@@ -77,6 +77,10 @@ win.addEventListener("close", async (event) => {
|
||||
Deno.exit(0);
|
||||
});
|
||||
|
||||
if (Deno.env.get("DEBUG")) {
|
||||
win.openDevtools();
|
||||
}
|
||||
|
||||
// deno desktop binds this to a private local address and opens the window on it, the port given here is ignored
|
||||
Deno.serve(async (req) => {
|
||||
const url = new URL(req.url);
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
"replaceable": true,
|
||||
"components": {
|
||||
"bworld:water_source": {},
|
||||
"bworld:fishable": {}
|
||||
"bworld:fishable": {},
|
||||
"bworld:bucketable": {
|
||||
"into": "bworld:water_bucket"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "bworld:bucket",
|
||||
"texture": "bworld:bucket",
|
||||
"max_stack": 16,
|
||||
"base_sell_value": 180
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "bworld:water_bucket",
|
||||
"texture": "bworld:water_bucket",
|
||||
"max_stack": 1,
|
||||
"places": "bworld:water",
|
||||
"base_sell_value": 180,
|
||||
"components": {
|
||||
"bworld:filled_bucket": {
|
||||
"empty": "bworld:bucket"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user