Prevent players from placing blocks inside themselves

This commit is contained in:
2026-09-29 19:09:20 -03:00
parent f76cf2bf38
commit f0cf4e4eeb
5 changed files with 93 additions and 3 deletions
+26
View File
@@ -85,3 +85,29 @@ Deno.test("/summon spawns a mod's entity where the player is", async () => {
send(1, { type: "chat", text: "/summon bworld:item" });
assertStringIncludes(take(1).find((m) => m.type === "chat").text, "There's no entity bworld:item");
});
Deno.test("solid blocks can't be placed where a mob or player is", async () => {
const { join, take, send, game } = await test_game("mods");
join(1, "alice");
game.set_block(1, 100, 1, "bworld:stone");
send(1, { type: "move", x: 3.5, y: 101, z: 3.5, yaw: 0, pitch: 0 });
send(1, { type: "chat", text: "/give bworld:stone 2" });
const inventory = take(1).filter((m) => m.type === "container" && m.container === "inventory").at(-1).items;
send(1, { type: "select_slot", slot: inventory.findIndex((i: { id: string } | null) => i?.id === "bworld:stone") });
// the chicken's box pokes into the block above the stone, even from the one next to it
const chicken = create_entity(game.entities, "bworld:chicken")!;
chicken.set_position(2.1, 101, 1.5);
game.entities.add_entity(chicken);
send(1, { type: "use_block", x: 1, y: 100, z: 1, face: "top" });
assertEquals(game.world.get_block_id(1, 101, 1), "bworld:air");
chicken.set_position(2.5, 101, 1.5);
send(1, { type: "use_block", x: 1, y: 100, z: 1, face: "top" });
assertEquals(game.world.get_block_id(1, 101, 1), "bworld:stone");
// nor where a player is, the one placing it included
game.set_block(3, 100, 3, "bworld:stone");
send(1, { type: "use_block", x: 3, y: 100, z: 3, face: "top" });
assertEquals(game.world.get_block_id(3, 101, 3), "bworld:air");
});