Predict interactions with blocks
This commit is contained in:
@@ -10,7 +10,6 @@ export function setup(ctx: ServerContext) {
|
||||
register_shipping_bin(ctx, storage_menu);
|
||||
register_furnace(ctx);
|
||||
register_smithing_table(ctx);
|
||||
register_trapdoor(ctx);
|
||||
register_farming(ctx);
|
||||
register_fishing(ctx);
|
||||
register_buckets(ctx);
|
||||
@@ -32,17 +31,6 @@ function register_hoeable(ctx: ServerContext) {
|
||||
});
|
||||
}
|
||||
|
||||
// a trapdoor opens and closes when right clicked, like a wooden one in minecraft. how it's placed is in shared.ts
|
||||
function register_trapdoor(ctx: ServerContext) {
|
||||
ctx.components.register_block("bworld:trapdoor", {
|
||||
on_interact(block) {
|
||||
const open = ctx.world.get_state(block.x, block.y, block.z, "open") ?? 0;
|
||||
ctx.world.set_state(block.x, block.y, block.z, "open", open ? 0 : 1);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// the container a block keeps its items in, made the first time it's needed. blocks placed before tile data
|
||||
// existed don't have one yet
|
||||
function block_container(ctx: ServerContext, block: BlockRef, size: number): Container {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// the base game's block rules: how blocks are placed and how they change with the blocks beside them. they run on the
|
||||
// server and on every client, so players see a fence join or a trapdoor turn the moment they place it
|
||||
// server and on every client, so players see a fence join or a trapdoor turn the moment they place it, and a trapdoor
|
||||
// open the moment they click it
|
||||
import type { SharedBlock, SharedContext } from "bworld/shared";
|
||||
|
||||
export function setup(ctx: SharedContext) {
|
||||
@@ -47,9 +48,14 @@ const FACINGS = ["north", "east", "south", "west"];
|
||||
|
||||
// placed against the side of a block, a trapdoor hangs from that block, in the half of the side that was clicked.
|
||||
// placed on top of a block it lies in the bottom half, and under one in the top half, swinging open away from the
|
||||
// player, like minecraft's TrapDoorBlock
|
||||
// player, like minecraft's TrapDoorBlock. it opens and closes when right clicked, like a wooden one, here so the
|
||||
// player who clicks sees it move right away
|
||||
function register_trapdoor(ctx: SharedContext) {
|
||||
ctx.components.register_block("bworld:trapdoor", {
|
||||
on_interact(block) {
|
||||
const open = ctx.world.get_state(block.x, block.y, block.z, "open") ?? 0;
|
||||
return ctx.world.set_state(block.x, block.y, block.z, "open", open ? 0 : 1);
|
||||
},
|
||||
state_for_placement(placement): Record<string, number> {
|
||||
if (placement.face !== "top" && placement.face !== "bottom") {
|
||||
return { facing: FACINGS.indexOf(placement.face), half: placement.hit[1] > 0.5 ? 1 : 0 };
|
||||
|
||||
Reference in New Issue
Block a user