Compare commits

..
3 Commits
Author SHA1 Message Date
paula 7369bf2e5f Dangerous business work 2026-11-16 21:27:24 -03:00
paula 5301e0307c Creative 2026-11-16 13:39:34 -03:00
paula be0770f3cf Facility door 2026-11-15 21:55:17 -03:00
24 changed files with 625 additions and 12 deletions
+2
View File
@@ -126,6 +126,8 @@ export class LocalPlayer extends Player {
sprinting = false;
// what the server says, see /fly
flying = false;
// what the server says, see /creative
creative = false;
#fov_scale = 1;
#prev_fov_scale = 1;
#prev_eye_height = PLAYER_EYE_HEIGHT;
+6 -3
View File
@@ -45,7 +45,8 @@ export class MultiPlayerGameMode {
this.destroy_progress = 0;
}
this.destroy_pos = { x: hit.x, y: hit.y, z: hit.z };
this.destroy_time = block_info.toughness ?? 9999;
// blocks without a toughness, like water, can only be broken in creative
this.destroy_time = this.client.player.creative ? 0 : block_info.toughness ?? 9999;
this.destroy_progress += TICK_DELTA * (tool && tool.type === block_info.tool_to_break ? tool.speed : 1);
if (this.destroy_progress >= this.destroy_time) {
@@ -134,8 +135,10 @@ export class MultiPlayerGameMode {
if ((!block_info.interactive || skips_block) && place_id && placeable) {
level.add_block({ ...target, id: place_id }, place_value! >>> 16);
predict_neighbors(target.x, target.y, target.z);
const slot = this.#held_slot();
slot.amount = slot.amount! - 1;
if (!this.client.player.creative) {
const slot = this.#held_slot();
slot.amount = slot.amount! - 1;
}
}
}
+3
View File
@@ -95,6 +95,9 @@ export class ClientPacketListener {
case "flying":
client.player.flying = message.flying;
break;
case "creative":
client.player.creative = message.creative;
break;
case "effects":
client.player.effects = message.effects;
break;
+1 -1
View File
@@ -627,7 +627,7 @@ export interface BlockApi {
// how long breaking it by hand takes without a tool, in seconds, from the block's mining. Infinity for one that
// can't be broken. for machines that break blocks, like a drill
toughness(id: Id): number;
// the components its json lists and their params, a copy, like ItemApi.components
// the components its json lists and their params, a copy, like ItemApi.components. air has none
components(id: Id): Record<Id, unknown>;
// whether it's solid like stone: drawn in the solid layer, and a whole block to bump into in every state. glass,
// leaves, slabs and chests aren't. what passes signals on, and what wire turns corners around. false for air
+3 -1
View File
@@ -12,7 +12,7 @@ export const AIR_ID = "cubi:air";
// bump when a client and server of different versions can't play together.
// the server rejects a different version before the client downloads anything
export const PROTOCOL_VERSION = 28;
export const PROTOCOL_VERSION = 29;
export interface PlayerInfo {
id: string;
@@ -301,6 +301,8 @@ export type ServerMessage =
| { type: "using_item"; using: boolean }
// whether the player flies, see /fly, when it changes
| { type: "flying"; flying: boolean }
// whether the player is in creative, see /creative, when it changes
| { type: "creative"; creative: boolean }
// the player's own effects that show an icon, when they change. duration is in ticks, -1 for forever, and the
// client counts it down itself, so it isn't sent every tick
| { type: "effects"; effects: { id: string; amplifier: number; duration: number }[] }
+1 -1
View File
@@ -61,7 +61,7 @@ export function blocks_api(): SharedContext["blocks"] {
};
return {
exists: (id) => EverythingRegistry.get("blocks", id) !== undefined,
components: (id) => structuredClone(known(id).components ?? {}),
components: (id) => id === AIR_ID ? {} : structuredClone(known(id).components ?? {}),
solid: (id) => id !== AIR_ID && is_solid(known(id)),
};
}
+1
View File
@@ -119,6 +119,7 @@ Commands can only be registered while the server phase runs.
| `/tp <x> <y> <z>` | Teleports you there |
| `/fill <x1> <y1> <z1> <x2> <y2> <z2> <block>` | Fills the box between two corners with a block, `air` to clear it |
| `/fly` | Toggles flying: jump goes up, sneak goes down, sprint goes faster |
| `/creative` | Toggles placing blocks without using them up and instant breaking |
| `/tps` | Shows how the game loop keeps up |
| `/viewdistance [chunks]` | Shows or changes how far the server sends chunks, until it restarts |
| `/skin [url] [slim\|normal]` | Changes your skin to a 64×64 PNG, or back to the default |
@@ -0,0 +1,85 @@
{
"format_version": 1,
"block": {
"id": "dangerous_business:facility_door",
"name": "Facility Door",
"textures": {
"item": "dangerous_business:facility_door",
"bottom": "dangerous_business:facility_door_bottom",
"top": "dangerous_business:facility_door_top"
},
"model": "dangerous_business:door_bottom",
"render_layer": "cutout",
"states": [
{
"name": "facing",
"bits": 2,
"default": 0
},
{
"name": "half",
"bits": 1,
"default": 0
},
{
"name": "hinge",
"bits": 1,
"default": 0
}
],
"variants": {
"half=0,hinge=1": {
"model": "dangerous_business:door_bottom_rh"
},
"half=1,hinge=0": {
"model": "dangerous_business:door_top_rh"
},
"half=1,hinge=1": {
"model": "dangerous_business:door_top_rh"
},
"half=1": {
"model": "dangerous_business:door_top"
},
"facing=0": {
"y": 270
},
"facing=0,hinge=0": {
"y": 0
},
"facing=0,hinge=1": {
"y": 180
},
"facing=1": {
"y": 0
},
"facing=1,hinge=0": {
"y": 90
},
"facing=1,hinge=1": {
"y": 270
},
"facing=2": {
"y": 90
},
"facing=2,hinge=0": {
"y": 180
},
"facing=2,hinge=1": {
"y": 0
},
"facing=3": {
"y": 180
},
"facing=3,hinge=0": {
"y": 270
},
"facing=3,hinge=1": {
"y": 90
}
},
"interactive": true,
"components": {
"dangerous_business:facility_door": {}
}
}
}
@@ -0,0 +1,93 @@
{
"format_version": 1,
"block": {
"id": "dangerous_business:factory_door",
"name": "Factory Door",
"textures": {
"item": "dangerous_business:factory_door_top",
"bottom": "dangerous_business:factory_door_bottom",
"top": "dangerous_business:factory_door_top"
},
"model": "dangerous_business:door_bottom",
"render_layer": "cutout",
"states": [
{
"name": "facing",
"bits": 2,
"default": 0
},
{
"name": "half",
"bits": 1,
"default": 0
},
{
"name": "open",
"bits": 1,
"default": 0
},
{
"name": "hinge",
"bits": 1,
"default": 0
}
],
"variants": {
"half=0,hinge=0,open=1": {
"model": "dangerous_business:door_bottom_rh"
},
"half=0,hinge=1,open=0": {
"model": "dangerous_business:door_bottom_rh"
},
"half=1,hinge=0,open=1": {
"model": "dangerous_business:door_top_rh"
},
"half=1,hinge=1,open=0": {
"model": "dangerous_business:door_top_rh"
},
"half=1": {
"model": "dangerous_business:door_top"
},
"facing=0,open=0": {
"y": 270
},
"facing=0,open=1,hinge=0": {
"y": 0
},
"facing=0,open=1,hinge=1": {
"y": 180
},
"facing=1,open=0": {
"y": 0
},
"facing=1,open=1,hinge=0": {
"y": 90
},
"facing=1,open=1,hinge=1": {
"y": 270
},
"facing=2,open=0": {
"y": 90
},
"facing=2,open=1,hinge=0": {
"y": 180
},
"facing=2,open=1,hinge=1": {
"y": 0
},
"facing=3,open=0": {
"y": 180
},
"facing=3,open=1,hinge=0": {
"y": 270
},
"facing=3,open=1,hinge=1": {
"y": 90
}
},
"interactive": true,
"components": {
"dangerous_business:door": { "pairs_with": "dangerous_business:door" }
}
}
}
@@ -0,0 +1,38 @@
{
"format_version": 1,
"model": {
"id": "dangerous_business:door_bottom",
"elements": [
{
"from": [0, 0, 0],
"to": [3, 16, 16],
"faces": {
"bottom": {
"texture": "#bottom",
"uv": [13, 0, 16, 16],
"cullface": "bottom"
},
"north": {
"texture": "#bottom",
"uv": [3, 0, 0, 16],
"cullface": "north"
},
"south": {
"texture": "#bottom",
"uv": [0, 0, 3, 16],
"cullface": "south"
},
"west": {
"texture": "#bottom",
"uv": [0, 0, 16, 16],
"cullface": "west"
},
"east": {
"texture": "#bottom",
"uv": [16, 0, 0, 16]
}
}
}
]
}
}
@@ -0,0 +1,38 @@
{
"format_version": 1,
"model": {
"id": "dangerous_business:door_bottom_rh",
"elements": [
{
"from": [0, 0, 0],
"to": [3, 16, 16],
"faces": {
"bottom": {
"texture": "#bottom",
"uv": [13, 0, 16, 16],
"cullface": "bottom"
},
"north": {
"texture": "#bottom",
"uv": [3, 0, 0, 16],
"cullface": "north"
},
"south": {
"texture": "#bottom",
"uv": [0, 0, 3, 16],
"cullface": "south"
},
"west": {
"texture": "#bottom",
"uv": [16, 0, 0, 16],
"cullface": "west"
},
"east": {
"texture": "#bottom",
"uv": [0, 0, 16, 16]
}
}
}
]
}
}
@@ -0,0 +1,38 @@
{
"format_version": 1,
"model": {
"id": "dangerous_business:door_top",
"elements": [
{
"from": [0, 0, 0],
"to": [3, 16, 16],
"faces": {
"top": {
"texture": "#bottom",
"uv": [13, 0, 16, 16],
"cullface": "top"
},
"north": {
"texture": "#top",
"uv": [3, 0, 0, 16],
"cullface": "north"
},
"south": {
"texture": "#top",
"uv": [0, 0, 3, 16],
"cullface": "south"
},
"west": {
"texture": "#top",
"uv": [0, 0, 16, 16],
"cullface": "west"
},
"east": {
"texture": "#top",
"uv": [16, 0, 0, 16]
}
}
}
]
}
}
@@ -0,0 +1,38 @@
{
"format_version": 1,
"model": {
"id": "dangerous_business:door_top_rh",
"elements": [
{
"from": [0, 0, 0],
"to": [3, 16, 16],
"faces": {
"top": {
"texture": "#bottom",
"uv": [13, 0, 16, 16],
"cullface": "top"
},
"north": {
"texture": "#top",
"uv": [3, 0, 0, 16],
"cullface": "north"
},
"south": {
"texture": "#top",
"uv": [0, 0, 3, 16],
"cullface": "south"
},
"west": {
"texture": "#top",
"uv": [16, 0, 0, 16],
"cullface": "west"
},
"east": {
"texture": "#top",
"uv": [0, 0, 16, 16]
}
}
}
]
}
}
Binary file not shown.
+124 -1
View File
@@ -1,10 +1,133 @@
import type { ClientContext } from "cubi/client";
import type { ServerContext } from "cubi/server";
import { DOOR, FACILITY_DOOR } from "./shared.ts";
export { shared } from "./shared.ts";
// a standalone game that doesn't build on bworld, so everything it needs comes from this mod or the engine
export function server(_ctx: ServerContext) {
export function server(ctx: ServerContext) {
register_facility_door(ctx);
register_door(ctx);
register_commands(ctx);
}
export function client(_ctx: ClientContext) {
}
// doors are two blocks, a lower and an upper half, see register_door in shared.ts. one is only placed with air above
// it, where the upper half goes, and breaking either half takes the other away with it. only the half that was broken
// drops the door, the other is just taken away
function register_facility_door(ctx: ServerContext) {
const is_door = (id: string) => FACILITY_DOOR in ctx.blocks.components(id);
ctx.events.before.block_place.subscribe((event) => {
const { id, x, y, z } = event.block;
if (is_door(id) && ctx.world.get_block(x, y + 1, z) !== "cubi:air") event.cancel = true;
});
ctx.events.after.block_place.subscribe(({ block: { id, x, y, z } }) => {
if (!is_door(id)) return;
ctx.world.set_block(x, y + 1, z, id);
for (const state of ["facing", "hinge"]) {
ctx.world.set_state(x, y + 1, z, state, ctx.world.get_state(x, y, z, state) ?? 0);
}
ctx.world.set_state(x, y + 1, z, "half", 1);
});
// the halves being taken away, so the other half's on_break doesn't take the first away again
const breaking = new Set<string>();
ctx.components.register_block(FACILITY_DOOR, {
on_break(block) {
const { x, y, z } = block;
if (breaking.has(`${x},${y},${z}`)) return;
const other = ctx.world.get_state(x, y, z, "half") ? y - 1 : y + 1;
if (ctx.world.get_block(x, other, z) !== block.id) return;
const halves = [`${x},${y},${z}`, `${x},${other},${z}`];
for (const half of halves) breaking.add(half);
try {
ctx.world.set_block(x, other, z, "cubi:air");
} finally {
for (const half of halves) breaking.delete(half);
}
},
});
}
function register_door(ctx: ServerContext) {
const is_door = (id: string) => DOOR in ctx.blocks.components(id);
ctx.events.before.block_place.subscribe((event) => {
const { id, x, y, z } = event.block;
if (is_door(id) && ctx.world.get_block(x, y + 1, z) !== "cubi:air") event.cancel = true;
});
ctx.events.after.block_place.subscribe(({ block: { id, x, y, z } }) => {
if (!is_door(id)) return;
ctx.world.set_block(x, y + 1, z, id);
for (const state of ["facing", "open", "hinge"]) {
ctx.world.set_state(x, y + 1, z, state, ctx.world.get_state(x, y, z, state) ?? 0);
}
ctx.world.set_state(x, y + 1, z, "half", 1);
// it took its open state from the lower half, but it can be the half that's powered
if (ctx.world.get_state(x, y + 1, z, "powered")) {
ctx.world.set_state(x, y, z, "open", 1);
ctx.world.set_state(x, y + 1, z, "open", 1);
}
});
// the halves being taken away, so the other half's on_break doesn't take the first away again
const breaking = new Set<string>();
ctx.components.register_block(DOOR, {
on_break(block) {
const { x, y, z } = block;
if (breaking.has(`${x},${y},${z}`)) return;
const other = ctx.world.get_state(x, y, z, "half") ? y - 1 : y + 1;
if (ctx.world.get_block(x, other, z) !== block.id) return;
const halves = [`${x},${y},${z}`, `${x},${other},${z}`];
for (const half of halves) breaking.add(half);
try {
ctx.world.set_block(x, other, z, "cubi:air");
} finally {
for (const half of halves) breaking.delete(half);
}
},
on_state_change(block, _params, before) {
const { x, y, z } = block;
const powered = ctx.world.get_state(x, y, z, "powered");
if (powered === before.powered) return;
const other = ctx.world.get_state(x, y, z, "half") ? y - 1 : y + 1;
const paired = ctx.world.get_block(x, other, z) === block.id;
const other_powered = paired && ctx.world.get_state(x, other, z, "powered") === 1;
const open = powered === 1 || other_powered;
if (open === (before.powered === 1 || other_powered)) return;
ctx.world.set_state(x, y, z, "open", open ? 1 : 0);
if (paired) ctx.world.set_state(x, other, z, "open", open ? 1 : 0);
},
});
}
function register_commands(ctx: ServerContext) {
const { literal, argument, types } = ctx.commands;
ctx.commands.register(
literal("startday")
.describe("Starts a new day")
.executes((context) => {
clear_map(ctx);
place_surface(ctx);
context.source.send_message("A new day starts");
}),
);
}
const interior_tiles = [];
function clear_map(ctx: ServerContext) {
// theres no need to clear the surface but we do need to clear each tile
}
function place_surface(ctx: ServerContext) {
ctx.schematics.place(
"dangerous_business:assurance",
{ position: { x: -80, y: 150, z: -80 } },
);
}
function generate_interior(ctx: ServerContext) {
}
+95
View File
@@ -0,0 +1,95 @@
import type { SharedContext } from "cubi/shared";
export const FACILITY_DOOR = "dangerous_business:facility_door";
export const DOOR = "dangerous_business:door";
const FACINGS = ["north", "east", "south", "west"];
// the way along the ground each facing goes, in FACINGS' order
const FACING_STEPS = [[0, -1], [1, 0], [0, 1], [-1, 0]];
export function shared(ctx: SharedContext) {
register_door(ctx);
register_facility_door(ctx);
}
// a door is two blocks, its lower half (half 0) and its upper half (half 1), with the same states. it faces the way the
// player placing it looks, and is hinged on the side away from a door of the same kind beside it, so the two meet in
// the middle as a double door. without one, on the side of the block the player clicked toward. the server places the
// upper half and takes away the other half when one breaks, see register_door in main.ts
function register_facility_door(ctx: SharedContext) {
ctx.components.register_block(FACILITY_DOOR, {
state_for_placement(placement): Record<string, number> {
const facing = FACINGS.indexOf(placement.facing);
const { x, y, z } = placement;
const door_at = ([step_x, step_z]: number[]) => {
const id = ctx.world.get_block(x + step_x, y, z + step_z);
return id !== undefined && FACILITY_DOOR in ctx.blocks.components(id) &&
ctx.world.get_state(x + step_x, y, z + step_z, "half") === 0;
};
const door_left = door_at(FACING_STEPS[(facing + 3) % 4]);
const door_right = door_at(FACING_STEPS[(facing + 1) % 4]);
if (door_left !== door_right) return { facing, half: 0, hinge: door_left ? 1 : 0 };
const [step_x, step_z] = FACING_STEPS[facing];
const [hit_x, , hit_z] = placement.hit;
const right = (step_x < 0 && hit_z < 0.5) || (step_x > 0 && hit_z > 0.5) ||
(step_z < 0 && hit_x > 0.5) || (step_z > 0 && hit_x < 0.5);
return { facing, half: 0, hinge: right ? 1 : 0 };
},
});
}
interface DoorParams {
pairs_with: string;
}
function register_door(ctx: SharedContext) {
// a door's lower half there, of the kind this one pairs with
const door_at = (x: number, y: number, z: number, params: DoorParams) => {
const id = ctx.world.get_block(x, y, z);
return id !== undefined && ctx.tags.has("blocks", params.pairs_with, id) &&
ctx.world.get_state(x, y, z, "half") === 0;
};
// opens or closes both halves of the door whose lower half is there
const set_open = (x: number, y: number, z: number, open: number) => {
if (ctx.world.get_block(x, y + 1, z) === ctx.world.get_block(x, y, z)) {
ctx.world.set_state(x, y + 1, z, "open", open);
}
return ctx.world.set_state(x, y, z, "open", open);
};
ctx.components.register_block<DoorParams>("dangerous_business:door", {
on_interact(block, params) {
const { x, z } = block;
const y = ctx.world.get_state(x, block.y, z, "half") ? block.y - 1 : block.y;
const state = (name: string, at_x = x, at_z = z) => ctx.world.get_state(at_x, y, at_z, name);
const was_open = state("open");
const open = was_open ? 0 : 1;
// the other door of a double door is beside its free edge, facing the same way, hinged the other way, and
// open or closed like it
const facing = state("facing")!;
const [step_x, step_z] = FACING_STEPS[(facing + (state("hinge") ? 3 : 1)) % 4];
const [px, pz] = [x + step_x, z + step_z];
if (
door_at(px, y, pz, params) && state("facing", px, pz) === facing &&
state("hinge", px, pz) !== state("hinge") && state("open", px, pz) === was_open
) {
set_open(px, y, pz, open);
}
return set_open(x, y, z, open);
},
state_for_placement(placement, params): Record<string, number> {
const facing = FACINGS.indexOf(placement.facing);
const { x, y, z } = placement;
const [left_x, left_z] = FACING_STEPS[(facing + 3) % 4];
const [right_x, right_z] = FACING_STEPS[(facing + 1) % 4];
const door_left = door_at(x + left_x, y, z + left_z, params);
const door_right = door_at(x + right_x, y, z + right_z, params);
if (door_left !== door_right) return { facing, half: 0, hinge: door_left ? 1 : 0 };
const [step_x, step_z] = FACING_STEPS[facing];
const [hit_x, , hit_z] = placement.hit;
const right = (step_x < 0 && hit_z < 0.5) || (step_x > 0 && hit_z > 0.5) ||
(step_z < 0 && hit_x > 0.5) || (step_z > 0 && hit_x < 0.5);
return { facing, half: 0, hinge: right ? 1 : 0 };
},
});
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

+19 -5
View File
@@ -1273,8 +1273,8 @@ export class GameServer {
#break_block(player: ServerPlayer, x: number, y: number, z: number) {
const info = this.world.get_block_info(x, y, z);
// air, or something like water that can't be broken
if (!info || info.toughness === undefined || !this.#in_reach(player, x, y, z)) {
// air, or something like water that can't be broken outside creative
if (!info || (info.toughness === undefined && !player.creative) || !this.#in_reach(player, x, y, z)) {
this.#correct(player, x, y, z);
return;
}
@@ -1291,7 +1291,8 @@ export class GameServer {
return;
}
this.destroy_block(x, y, z, player);
// creative breaks drop nothing, since placing doesn't use anything up
this.destroy_block(x, y, z, player, { collect: player.creative });
player.vitals.add_exhaustion(EXHAUSTION.break_block);
this.mods.after.block_break.emit(event);
}
@@ -1537,7 +1538,7 @@ export class GameServer {
if (!place) return;
this.set_block(tx, ty, tz, held.block_id, player, state);
held_slot.amount = held_slot.amount! - 1;
if (!player.creative) held_slot.amount = held_slot.amount! - 1;
this.mods.after.block_place.emit(place);
}
@@ -1559,7 +1560,7 @@ export class GameServer {
z,
set_state_value(this.world.get_block_value(x, y, z), info, "waterlogged", 1)! >>> 16,
);
held_slot.amount = held_slot.amount! - 1;
if (!player.creative) held_slot.amount = held_slot.amount! - 1;
this.mods.after.block_place.emit(place);
}
@@ -1924,6 +1925,17 @@ export class GameServer {
}),
);
// TODO: only let operators do this
register(
literal<ServerCommandSource>("creative")
.describe("Toggles placing blocks without using them up and breaking any block instantly")
.executes((context) => {
const player = context.source.server_player;
player.creative = !player.creative;
context.source.send_message(player.creative ? "You're in creative" : "You're out of creative");
}),
);
// TODO: only let operators do this
register(
literal<ServerCommandSource>("viewdistance").describe("Shows or changes the server's view distance")
@@ -2337,6 +2349,8 @@ export class GameServer {
sync("using_item", using, () => ({ type: "using_item", using }));
const flying = player.flying;
sync("flying", flying, () => ({ type: "flying", flying }));
const creative = player.creative;
sync("creative", creative, () => ({ type: "creative", creative }));
const effects = [...player.effects.values()]
.filter((effect) => effect.show_icon)
.map(({ type, amplifier, duration }) => ({ id: type.id, amplifier, duration }));
+7
View File
@@ -38,6 +38,8 @@ export interface SavedPlayer {
slim?: boolean;
// see /fly
flying?: boolean;
// see /creative
creative?: boolean;
}
// the connection of the player machines use items as, see GameServer.use_item_on. nothing is ever sent to it
@@ -68,6 +70,9 @@ export class ServerPlayer extends LivingEntity {
using: { slot: number; type_id: string; ticks: number; duration: number } | undefined;
// flying, from /fly. their client moves them without gravity, and they don't fall or get hungry from moving
flying = false;
// from /creative: placing doesn't use up what they hold, and breaking is instant and drops nothing. their client
// times breaking, so it only needs to know
creative = false;
inventory = new Container(INVENTORY_SIZE);
// hunger and saturation, health is the entity's
@@ -240,6 +245,7 @@ export class ServerPlayer extends LivingEntity {
skin: this.skin,
slim: this.slim || undefined,
flying: this.flying || undefined,
creative: this.creative || undefined,
};
}
@@ -256,5 +262,6 @@ export class ServerPlayer extends LivingEntity {
this.skin = saved.skin;
this.slim = saved.slim ?? false;
this.flying = saved.flying === true;
this.creative = saved.creative === true;
}
}
+33
View File
@@ -202,3 +202,36 @@ Deno.test("how far players reach is an attribute, which their client is sent", a
assertEquals(game.world.get_block_id(0, 99, 9), "cubi:air");
cleanup();
});
Deno.test("/creative places blocks without using them up and breaks blocks without drops", async () => {
const { game, send, take, hold, cleanup } = await setup();
const [alice] = game.players();
hold("testmod:pillar");
send(1, { type: "chat", text: "/creative" });
game.tick();
assert(take(1).some((m) => m.type === "creative" && m.creative), "the player hears they're in creative");
send(1, { type: "use_block", x: 1, y: 99, z: 1, face: "top" });
send(1, { type: "use_block", x: 1, y: 100, z: 1, face: "top" });
assertEquals(game.world.get_block_id(1, 101, 1), "testmod:pillar");
assertEquals(alice.inventory.get_slot(alice.selected_slot).amount, 1);
game.set_block(2, 100, 1, "bworld:dirt");
send(1, { type: "break_block", x: 2, y: 100, z: 1 });
assertEquals(game.world.get_block_id(2, 100, 1), "cubi:air");
assertEquals(game.item_entities(), []);
// even ones that can't be broken otherwise
game.set_block(2, 100, 1, "bworld:water");
send(1, { type: "break_block", x: 2, y: 100, z: 1 });
assertEquals(game.world.get_block_id(2, 100, 1), "cubi:air");
// out of it, placing uses the block up again and breaking drops
send(1, { type: "chat", text: "/creative" });
send(1, { type: "use_block", x: 1, y: 101, z: 1, face: "top" });
assertEquals(game.world.get_block_id(1, 102, 1), "testmod:pillar");
assert(!alice.inventory.get_slot(alice.selected_slot).has_item());
game.set_block(2, 100, 1, "bworld:dirt");
send(1, { type: "break_block", x: 2, y: 100, z: 1 });
assertEquals(game.item_entities().length, 1);
cleanup();
});