Files
behavior_pack
resource_pack
Code
11 462
behavior_pack/scripts/main.js
import { world, system } from "@minecraft/server";
const END_ID = "minecraft:the_end";
const RIFT_TYPE = "voidrift:void_rift";
const CENTER = { x: 100000, y: 80, z: 100000 };
const PLATFORM_Y = 70;
const REGION_RADIUS = 260;
const MAX_RIFTS = 24;
const RIFT_TRIGGER_DIST2 = 2.3 * 2.3;
const TRAVEL_COOLDOWN = 40;
const PROP_RIFTS = "voidrift:rifts";
const PROP_GENERATED = "voidrift:generated";
const RETURN_PREFIX = "voidrift:return:";
const FOG_ID = "voidrift:luminous_depths";
const FOG_TAG = "voidrift_depths";
let rifts = [];
let generating = false;
const fogged = new Set();
const travelCooldown = new Map();
system.runTimeout(loadState, 40);
function loadState() {
try {
const raw = world.getDynamicProperty(PROP_RIFTS);
if (typeof raw === "string") rifts = JSON.parse(raw);
} catch (e) {
rifts = [];
}
}
function saveRifts() {
try {
world.setDynamicProperty(PROP_RIFTS, JSON.stringify(rifts));
} catch (e) {}
}
function getEnd() {
return world.getDimension(END_ID);
}
function dist2(a, b) {
const dx = a.x - b.x;
const dy = a.y - b.y;
const dz = a.z - b.z;
return dx * dx + dy * dy + dz * dz;
}
function inBiomeRegion(loc) {
const dx = loc.x - CENTER.x;
const dz = loc.z - CENTER.z;
return dx * dx + dz * dz <= REGION_RADIUS * REGION_RADIUS;
}
// Spawn glowing rifts in the void near End players
system.runInterval(() => {
for (const player of world.getPlayers()) {
if (player.dimension.id !== END_ID) continue;
if (inBiomeRegion(player.location)) continue;
if (Math.random() < 0.4) trySpawnRift(player);
}
}, 160);
function trySpawnRift(player) {
if (rifts.length >= MAX_RIFTS) return;
const dim = getEnd();
const angle = Math.random() * Math.PI * 2;
const dist = 14 + Math.random() * 26;
const x = Math.floor(player.location.x + Math.cos(angle) * dist);
const z = Math.floor(player.location.z + Math.sin(angle) * dist);
const y = 6 + Math.floor(Math.random() * 34);
const block = dim.getBlock({ x, y, z });
if (!block || !block.isAir) return;
for (let i = 1; i <= 6; i++) {
const below = dim.getBlock({ x, y: y - i, z });
if (below && !below.isAir) return;
}
block.setType(RIFT_TYPE);
rifts.push({ x, y, z });
saveRifts();
}
// Prune rifts whose block was broken
system.runInterval(() => {
const dim = getEnd();
let changed = false;
for (let i = rifts.length - 1; i >= 0; i--) {
const block = dim.getBlock(rifts[i]);
if (!block || block.typeId !== RIFT_TYPE) {
rifts.splice(i, 1);
changed = true;
}
}
if (changed) saveRifts();
}, 200);
// Rift glow particles
system.runInterval(() => {
const dim = getEnd();
const players = world.getPlayers().filter((p) => p.dimension.id === END_ID);
for (const rift of rifts) {
const near = players.some((p) => dist2(p.location, rift) < 64 * 64);
if (!near) continue;
const center = { x: rift.x + 0.5, y: rift.y + 0.5, z: rift.z + 0.5 };
try {
dim.spawnParticle("minecraft:endrod", center);
dim.spawnParticle("minecraft:sculk_charge_pop_particle", center);
} catch (e) {}
}
}, 15);
// Travel detection
system.runInterval(() => {
const dim = getEnd();
for (const player of world.getPlayers()) {
if (player.dimension.id !== END_ID) continue;
const last = travelCooldown.get(player.id) ?? -1000;
if (system.currentTick - last < TRAVEL_COOLDOWN) continue;
for (let i = 0; i < rifts.length; i++) {
const rift = rifts[i];
const center = { x: rift.x + 0.5, y: rift.y + 0.5, z: rift.z + 0.5 };
if (dist2(player.location, center) > RIFT_TRIGGER_DIST2) continue;
travelCooldown.set(player.id, system.currentTick);
travel(player, dim, i);
break;
}
}
}, 8);
function travel(player, dim, riftIndex) {
const key = RETURN_PREFIX + player.id;
if (inBiomeRegion(player.location)) {
let target = null;
try {
const raw = world.getDynamicProperty(key);
if (typeof raw === "string") target = JSON.parse(raw);
} catch (e) {}
world.setDynamicProperty(key, undefined);
removeFog(player);
if (target) {
player.teleport({ x: target.x, y: target.y, z: target.z }, { dimension: dim });
} else {
player.teleport({ x: 100.5, y: 49, z: 0.5 }, { dimension: dim });
}
player.addEffect("minecraft:slow_falling", 100, { showParticles: false });
player.sendMessage("§7The rift folds shut behind you, returning you to the outer End.");
player.playSound("portal.travel");
} else {
ensureBiomeGenerated(dim);
try {
world.setDynamicProperty(key, JSON.stringify({
x: player.location.x,
y: player.location.y,
z: player.location.z
}));
} catch (e) {}
collapseRift(dim, riftIndex);
player.teleport({ x: CENTER.x + 4.5, y: PLATFORM_Y + 1, z: CENTER.z + 0.5 }, { dimension: dim });
applyFog(player);
player.addEffect("minecraft:slow_falling", 200, { showParticles: false });
player.addEffect("minecraft:night_vision", 600, { showParticles: false });
player.sendMessage("§5§lThe glowing void swallows you... §d§oWelcome to the Luminous Depths.");
player.playSound("block.end_portal.spawn");
}
}
function collapseRift(dim, index) {
const rift = rifts[index];
if (!rift) return;
const block = dim.getBlock(rift);
if (block && block.typeId === RIFT_TYPE) block.setType("minecraft:air");
rifts.splice(index, 1);
saveRifts();
}
// Fog handling
function applyFog(player) {
if (fogged.has(player.id)) return;
try {
player.runCommand(`fog @s push ${FOG_ID} ${FOG_TAG}`);
fogged.add(player.id);
} catch (e) {}
}
function removeFog(player) {
if (!fogged.has(player.id)) return;
try {
player.runCommand(`fog @s pop ${FOG_TAG}`);
} catch (e) {}
fogged.delete(player.id);
}
system.runInterval(() => {
for (const player of world.getPlayers()) {
if (player.dimension.id !== END_ID) continue;
if (inBiomeRegion(player.location)) applyFog(player);
else removeFog(player);
}
}, 40);