Fishing hook

This commit is contained in:
2026-09-28 20:52:53 -03:00
parent d606bc4b55
commit ad6adb49dc
16 changed files with 258 additions and 37 deletions
+31
View File
@@ -11,6 +11,7 @@ import type {
CommandSource,
Container,
ContainerScreenOptions,
EntityRef,
EventSignal,
ItemComponent,
ItemStack,
@@ -40,6 +41,8 @@ import { AIR_ID } from "$/common/protocol.ts";
import type { GameServer } from "./game_server.ts";
import type { OpenScreen, ServerPlayer } from "./player.ts";
import { MAX_HEALTH } from "./vitals.ts";
import type { Entity } from "./entity/entity.ts";
import { create_entity } from "./entity/entity_types.ts";
import type { ScreenLayout } from "$/common/protocol.ts";
// a list of handlers that can't break each other: one throwing is logged under its mod and the rest still run
@@ -432,6 +435,15 @@ export class ModRuntime {
},
get_block_data: (x, y, z) => game().world.get_tile(x, y, z)?.mod_data as never,
drop_item: (x, y, z, item) => void game().pop_item(x, y, z, new_stack(item)),
spawn_entity: (id, x, y, z) => {
const entity = EverythingRegistry.get("entities", id)
? create_entity(game().entities, id)
: undefined;
if (!entity) throw new Error(`unknown entity ${id}`);
entity.set_position(x, y, z);
game().entities.add_entity(entity);
return entity_ref(entity);
},
is_loaded: () => true,
get seed() {
return game().world.seed;
@@ -788,3 +800,22 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
},
};
}
function entity_ref(entity: Entity): EntityRef {
return {
id: entity.id,
type: entity.type,
get position() {
return { x: entity.x, y: entity.y, z: entity.z };
},
get removed() {
return entity.removed;
},
teleport(x, y, z) {
if (!entity.removed) entity.set_position(x, y, z);
},
remove() {
entity.remove();
},
};
}