Compare commits
4
Commits
eedaa955f6
...
8c2364fa91
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c2364fa91 | ||
|
|
8230fe297d | ||
|
|
1b06fa29e1 | ||
|
|
188b05f598 |
@@ -15,6 +15,8 @@ import { RemoteEntity } from "./entity/remote_entity.ts";
|
||||
import { Player } from "./entity/player.ts";
|
||||
import type { Entity } from "./entity/entity.ts";
|
||||
|
||||
const CREATIVE_DESTROY_DELAY = 2;
|
||||
|
||||
// breaking and using blocks against a server, like minecraft's MultiPlayerGameMode. the client times breaking
|
||||
// and guesses the results so they feel instant, the server decides what really happens
|
||||
export class MultiPlayerGameMode {
|
||||
@@ -24,6 +26,9 @@ export class MultiPlayerGameMode {
|
||||
destroy_pos: { x: number; y: number; z: number } | undefined;
|
||||
destroy_progress = 0;
|
||||
destroy_time = 0;
|
||||
// ticks left before creative can break another block while the button is held, so holding it doesn't clear a
|
||||
// line of blocks every tick
|
||||
destroy_delay = 0;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
@@ -36,6 +41,10 @@ export class MultiPlayerGameMode {
|
||||
|
||||
// called every tick the attack button is held on a block
|
||||
continue_destroy_block(hit: BlockHitResult) {
|
||||
if (this.destroy_delay > 0) {
|
||||
this.destroy_delay--;
|
||||
return;
|
||||
}
|
||||
const block_info = EverythingRegistry.get_by_id<BlockRegistry>("blocks", hit.block)!;
|
||||
const tool = this.held_item()?.tool;
|
||||
|
||||
@@ -58,10 +67,13 @@ export class MultiPlayerGameMode {
|
||||
});
|
||||
this.destroy_progress = 0;
|
||||
this.destroy_time = 0;
|
||||
if (this.client.player.creative) this.destroy_delay = CREATIVE_DESTROY_DELAY;
|
||||
}
|
||||
}
|
||||
|
||||
// letting go also ends the delay, so clicking again breaks right away
|
||||
stop_destroy_block() {
|
||||
this.destroy_delay = 0;
|
||||
this.destroy_pos = undefined;
|
||||
this.destroy_progress = 0;
|
||||
this.destroy_time = 0;
|
||||
|
||||
@@ -125,6 +125,8 @@ Commands can only be registered while the server phase runs.
|
||||
| `/skin [url] [slim\|normal]` | Changes your skin to a 64×64 PNG, or back to the default |
|
||||
| `/help [command]` | Every command's usage, or one's |
|
||||
|
||||
`/fill` and `/exportschematic` suggest the block you're looking at for each corner.
|
||||
|
||||
`/give`'s data is the stack's `data`, and with `fluid` it's the fluid's (see
|
||||
[Fluids](../resources/fluids.md#containers)):
|
||||
|
||||
|
||||
@@ -9,14 +9,37 @@
|
||||
"model": "dangerous_business:double_steel_pipes",
|
||||
"item_model": "dangerous_business:double_steel_pipes",
|
||||
"shape": [[0, 0, 4.5, 16, 16, 11.5]],
|
||||
"components": {
|
||||
"dangerous_business:pipe": {}
|
||||
},
|
||||
"states": [
|
||||
{
|
||||
"name": "facing",
|
||||
"bits": 2,
|
||||
"default": 0
|
||||
},
|
||||
{
|
||||
"name": "horizontal",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"variants": {
|
||||
"horizontal=1,facing=0": {
|
||||
"x": 90
|
||||
},
|
||||
"horizontal=1,facing=1": {
|
||||
"x": 90,
|
||||
"y": 90
|
||||
},
|
||||
"horizontal=1,facing=2": {
|
||||
"x": 90,
|
||||
"y": 180
|
||||
},
|
||||
"horizontal=1,facing=3": {
|
||||
"x": 90,
|
||||
"y": 270
|
||||
},
|
||||
"facing=0": {
|
||||
"y": 180
|
||||
},
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#texture",
|
||||
"uv": [0, 0, 11.5, 8]
|
||||
"uv": [11.5, 5, 0, 16]
|
||||
},
|
||||
"south": {
|
||||
"texture": "#texture",
|
||||
@@ -33,7 +33,7 @@
|
||||
"faces": {
|
||||
"north": {
|
||||
"texture": "#texture",
|
||||
"uv": [11.5, 8, 0, 0]
|
||||
"uv": [0, 16, 11.5, 5]
|
||||
},
|
||||
"south": {
|
||||
"texture": "#texture",
|
||||
@@ -56,7 +56,7 @@
|
||||
},
|
||||
"west": {
|
||||
"texture": "#texture",
|
||||
"uv": [0, 0, 11.5, 8]
|
||||
"uv": [11.5, 5, 0, 16]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -71,7 +71,7 @@
|
||||
"faces": {
|
||||
"east": {
|
||||
"texture": "#texture",
|
||||
"uv": [0, 0, 11.5, 8]
|
||||
"uv": [11.5, 5, 0, 16]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#texture",
|
||||
|
||||
@@ -842,7 +842,7 @@
|
||||
},
|
||||
"west": {
|
||||
"texture": "#texture",
|
||||
"uv": [12, 7.75, 8, 11.5]
|
||||
"uv": [12, 7.75, 16, 11.5]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
},
|
||||
"west": {
|
||||
"texture": "#texture",
|
||||
"uv": [12, 7.75, 8, 11.5]
|
||||
"uv": [12, 7.75, 16, 11.5]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -838,7 +838,7 @@
|
||||
"faces": {
|
||||
"east": {
|
||||
"texture": "#texture",
|
||||
"uv": [8, 7.75, 12, 11.5]
|
||||
"uv": [16, 7.75, 12, 11.5]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#texture",
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
"faces": {
|
||||
"east": {
|
||||
"texture": "#texture",
|
||||
"uv": [8, 7.75, 12, 11.5]
|
||||
"uv": [16, 7.75, 12, 11.5]
|
||||
},
|
||||
"west": {
|
||||
"texture": "#texture",
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
},
|
||||
"bottom": {
|
||||
"texture": "#texture",
|
||||
"uv": [15, 0, 7.5, 7.5]
|
||||
"uv": [7.5, 0, 0, 7.5]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ export function shared(ctx: SharedContext) {
|
||||
register_door(ctx);
|
||||
register_facility_door(ctx);
|
||||
register_half(ctx);
|
||||
register_pipe(ctx);
|
||||
register_connects(ctx);
|
||||
register_random_look(ctx);
|
||||
}
|
||||
@@ -28,6 +29,17 @@ function register_half(ctx: SharedContext) {
|
||||
});
|
||||
}
|
||||
|
||||
// stands up when placed against the top or bottom of a block, and lies along the way it was placed (horizontal 1, facing
|
||||
// that way) against a side, so a run of them can go up walls and along them
|
||||
function register_pipe(ctx: SharedContext) {
|
||||
ctx.components.register_block("dangerous_business:pipe", {
|
||||
state_for_placement(placement): Record<string, number> {
|
||||
if (placement.face === "top" || placement.face === "bottom") return { horizontal: 0 };
|
||||
return { horizontal: 1, facing: FACINGS.indexOf(placement.face) };
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// sets its north, east, south and west states (and top, with "up") to 1 where the same block is beside it, so it can
|
||||
// hide its edges there, like floor grates joining into one floor
|
||||
function register_connects(ctx: SharedContext) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
TICK_DELTA,
|
||||
TICKS_PER_SECOND,
|
||||
} from "@/common/constants.ts";
|
||||
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "@/common/everything_registry.ts";
|
||||
import { BlockRegistry, EverythingRegistry, is_fluid_block, ItemRegistry } from "@/common/everything_registry.ts";
|
||||
import { FluidFlow } from "./fluids.ts";
|
||||
import { contained_fluid, Container, ItemData, ItemStack } from "@/common/inventory.ts";
|
||||
import {
|
||||
@@ -43,7 +43,7 @@ import {
|
||||
set_state_value,
|
||||
waterlog_placement,
|
||||
} from "@/common/utils.ts";
|
||||
import { collision_shape_at, type Shape } from "@/common/block_shapes.ts";
|
||||
import { collision_shape_at, raycast_blocks, type Shape, shape_at } from "@/common/block_shapes.ts";
|
||||
import { physics } from "@/common/physics.ts";
|
||||
import { EXHAUSTION } from "./vitals.ts";
|
||||
import { entity_ref, ModRuntime, new_stack, run_guarded, type ServerCommandSource } from "./mod_runtime.ts";
|
||||
@@ -1859,14 +1859,21 @@ export class GameServer {
|
||||
);
|
||||
|
||||
// TODO: only let operators do this, it writes files on the server's disk
|
||||
// whole number arguments one after another, the last one running it or going on to next
|
||||
// whole number arguments one after another, the last one running it or going on to next. each corner's
|
||||
// three suggest the block the player is looking at: all of it at its x, what's left at y and z
|
||||
const coordinates = (
|
||||
names: string[],
|
||||
next: CommandFunction<ServerCommandSource> | CommandNode<ServerCommandSource>,
|
||||
index = 0,
|
||||
): CommandNode<ServerCommandSource> => {
|
||||
const [name, ...rest] = names;
|
||||
const node = argument<number, ServerCommandSource>(name, integer());
|
||||
if (rest.length) return node.then(coordinates(rest, next));
|
||||
node.suggests((partial, source) => {
|
||||
const target = this.#targeted_block(source.server_player);
|
||||
const text = target?.slice(index % 3).join(" ");
|
||||
return text?.startsWith(partial) ? [{ text }] : [];
|
||||
});
|
||||
if (rest.length) return node.then(coordinates(rest, next, index + 1));
|
||||
return next instanceof CommandNode ? node.then(next) : node.executes(next);
|
||||
};
|
||||
register(
|
||||
@@ -2529,6 +2536,23 @@ export class GameServer {
|
||||
this.#next_chunk_player = first + 1;
|
||||
}
|
||||
|
||||
// the block the player's crosshair is on, like their client's pick: the boxes it's drawn with, past fluids, as far
|
||||
// as they can reach
|
||||
#targeted_block(player: ServerPlayer): [number, number, number] | undefined {
|
||||
const { eye_position: eye, look_direction: look } = this.mods.player(player);
|
||||
const hit = raycast_blocks(
|
||||
[eye.x, eye.y, eye.z],
|
||||
[look.x, look.y, look.z],
|
||||
player.attribute(ATTRIBUTES.block_interaction_range),
|
||||
(x, y, z) => {
|
||||
const block = this.world.get_block_info(x, y, z);
|
||||
if (!block || is_fluid_block(block)) return undefined;
|
||||
return shape_at(block, this.world.get_block_value(x, y, z));
|
||||
},
|
||||
);
|
||||
return hit && [hit.x, hit.y, hit.z];
|
||||
}
|
||||
|
||||
// from the eyes to the block's middle
|
||||
#in_reach(player: ServerPlayer, x: number, y: number, z: number) {
|
||||
const dx = x + 0.5 - player.x;
|
||||
|
||||
@@ -241,3 +241,29 @@ Deno.test("/fill replaces every block between two corners, both included", async
|
||||
assertEquals(game.world.get_block_id(50, 120, 50), "cubi:air");
|
||||
assertEquals(say("/fill 0 0 0 1 1 1 bworld:nothing"), "There's no block bworld:nothing");
|
||||
});
|
||||
|
||||
Deno.test("/fill and /exportschematic suggest the block the player is looking at for each corner", async () => {
|
||||
const { game, join, take, send } = await test_game("mods");
|
||||
join(1, "alice");
|
||||
for (let z = -6; z <= 1; z++) {
|
||||
for (let y = 150; y <= 152; y++) game.set_block(0, y, z, "cubi:air");
|
||||
}
|
||||
// looking north, level, at a block 3 away at eye height
|
||||
send(1, { type: "move", x: 0.5, y: 150, z: 0.5, yaw: 0, pitch: 0 });
|
||||
const suggest = (text: string) => {
|
||||
take(1);
|
||||
send(1, { type: "suggest", id: 1, text });
|
||||
return take(1).find((m) => m.type === "suggestions").suggestions.map((s: { text: string }) => s.text);
|
||||
};
|
||||
assertEquals(suggest("/fill "), []);
|
||||
|
||||
game.set_block(0, 151, -3, "bworld:stone");
|
||||
assertEquals(suggest("/fill "), ["0 151 -3"]);
|
||||
assertEquals(suggest("/fill 0 "), ["151 -3"]);
|
||||
assertEquals(suggest("/fill 0 151 "), ["-3"]);
|
||||
assertEquals(suggest("/fill 5"), []);
|
||||
assertEquals(suggest("/fill 0 151 -3 "), ["0 151 -3"]);
|
||||
assertEquals(suggest("/fill 0 151 -3 0 151 "), ["-3"]);
|
||||
assertEquals(suggest("/exportschematic "), ["0 151 -3"]);
|
||||
assertEquals(suggest("/exportschematic 0 151 -3 0 "), ["151 -3"]);
|
||||
});
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// dangerous business's placement components: slabs and other blocks that go in the top or bottom half, blocks that
|
||||
// join the same block beside them, and blocks that pick some of their looks when placed. and the death block
|
||||
// join the same block beside them, blocks that pick some of their looks when placed, and pipes that stand up or lie
|
||||
// down. and the death block
|
||||
import { assert, assertEquals, assertNotEquals } from "@std/assert";
|
||||
import { ItemStack } from "@/common/inventory.ts";
|
||||
import { get_state_value } from "@/common/utils.ts";
|
||||
@@ -13,6 +14,7 @@ const CONNECTS = "dangerous_business:floor_grate";
|
||||
const RANDOM_LOOK = "dangerous_business:water_puddle";
|
||||
const FLOOR = "dangerous_business:concrete_floor";
|
||||
const DEATH = "dangerous_business:death";
|
||||
const PIPE = "dangerous_business:double_steel_pipes";
|
||||
|
||||
// alice on a concrete floor at y 100, south of 0 100 0 and looking north, holding each of the blocks. it's a game of
|
||||
// its own, which tests playing mods/ leave out
|
||||
@@ -28,7 +30,7 @@ async function setup() {
|
||||
}
|
||||
}
|
||||
t.send(1, { type: "move", x: 0.5, y: 100, z: 3.5, yaw: 0, pitch: 0 });
|
||||
for (const id of [HALF, CONNECTS, RANDOM_LOOK]) t.send(1, { type: "chat", text: `/give ${id} 64` });
|
||||
for (const id of [HALF, CONNECTS, RANDOM_LOOK, PIPE]) t.send(1, { type: "chat", text: `/give ${id} 64` });
|
||||
const hold = (slot: number) => t.send(1, { type: "select_slot", slot });
|
||||
const state = (x: number, y: number, z: number, name: string) =>
|
||||
get_state_value(t.game.world.get_block_value(x, y, z), t.game.world.get_block_info(x, y, z)!, name);
|
||||
@@ -51,6 +53,21 @@ Deno.test("a half block goes in the top half against the underside of a block or
|
||||
assertEquals(state(-1, 102, -1, "half"), 0);
|
||||
});
|
||||
|
||||
Deno.test("a pipe stands up on top of a block and lies along the way it was placed against a side", async () => {
|
||||
const { t, hold, state } = await setup();
|
||||
hold(3);
|
||||
t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.5, 1, 0.5] });
|
||||
assertEquals(state(0, 100, 0, "horizontal"), 0);
|
||||
|
||||
t.game.set_block(0, 101, -2, FLOOR);
|
||||
t.send(1, { type: "use_block", x: 0, y: 101, z: -2, face: "east", hit: [1, 0.5, 0.5] });
|
||||
assertEquals(state(1, 101, -2, "horizontal"), 1);
|
||||
assertEquals(state(1, 101, -2, "facing"), 1);
|
||||
t.send(1, { type: "use_block", x: 0, y: 101, z: -2, face: "south", hit: [0.5, 0.5, 1] });
|
||||
assertEquals(state(0, 101, -1, "horizontal"), 1);
|
||||
assertEquals(state(0, 101, -1, "facing"), 2);
|
||||
});
|
||||
|
||||
Deno.test("a connecting block joins the same block beside it, and parts when it's gone", async () => {
|
||||
const { t, hold, state } = await setup();
|
||||
hold(1);
|
||||
|
||||
Reference in New Issue
Block a user