feat: add multi-world hub system with lobby portals and hub-return addon
Lobby addon detects players in portal zones at X: -15/0/15 and transfers them to Jamie/Lyla/Mya survival worlds. Hub-return addon gives players a recovery compass and chat commands (!hub, !lobby) to return to the lobby. Includes docker-compose.yml for 4 Bedrock servers (lobby + 3 child worlds), spark pet behavior/resource packs, and updated .gitignore. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
53
lobby-addon/lobby_transfer_BP/scripts/main.js
Normal file
53
lobby-addon/lobby_transfer_BP/scripts/main.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import { world, system } from "@minecraft/server";
|
||||
|
||||
// Portal definitions: name, center position, and direct transfer target
|
||||
const portals = [
|
||||
{ name: "Jamie's World", x: -15, y: 65, z: -24, host: "10.0.0.247", port: 19133 },
|
||||
{ name: "Lyla's World", x: 0, y: 65, z: -24, host: "10.0.0.247", port: 19134 },
|
||||
{ name: "Mya's World", x: 15, y: 65, z: -24, host: "10.0.0.247", port: 19135 },
|
||||
];
|
||||
|
||||
const PORTAL_RADIUS_X = 2.5;
|
||||
const PORTAL_RADIUS_Z = 2.0;
|
||||
const PORTAL_RADIUS_Y = 2.0;
|
||||
const COOLDOWN_TICKS = 100; // 5 seconds cooldown
|
||||
|
||||
// Track cooldowns per player
|
||||
const cooldowns = new Map();
|
||||
|
||||
system.runInterval(() => {
|
||||
for (const player of world.getAllPlayers()) {
|
||||
const pos = player.location;
|
||||
const playerId = player.id;
|
||||
|
||||
// Check cooldown
|
||||
const lastTransfer = cooldowns.get(playerId) || 0;
|
||||
if (system.currentTick - lastTransfer < COOLDOWN_TICKS) continue;
|
||||
|
||||
for (const portal of portals) {
|
||||
const dx = Math.abs(pos.x - portal.x);
|
||||
const dy = Math.abs(pos.y - portal.y);
|
||||
const dz = Math.abs(pos.z - portal.z);
|
||||
|
||||
if (dx < PORTAL_RADIUS_X && dy < PORTAL_RADIUS_Y && dz < PORTAL_RADIUS_Z) {
|
||||
cooldowns.set(playerId, system.currentTick);
|
||||
player.sendMessage(`§6Transferring to ${portal.name}...`);
|
||||
try {
|
||||
player.runCommand(`transfer "${player.name}" ${portal.host} ${portal.port}`);
|
||||
} catch (e) {
|
||||
player.sendMessage(`§cTransfer failed: ${e.message}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 10); // Check every half second
|
||||
|
||||
// Clean up cooldowns when players leave
|
||||
world.afterEvents.playerLeave.subscribe((event) => {
|
||||
cooldowns.delete(event.playerId);
|
||||
});
|
||||
|
||||
system.run(() => {
|
||||
world.sendMessage("§6[Hub] §7Portal transfer system loaded!");
|
||||
});
|
||||
Reference in New Issue
Block a user