fix(kubejs): update kubejs scripts

This commit is contained in:
Malasaur 2026-02-22 21:51:29 +01:00
parent 28a30d94c0
commit 57be389894
No known key found for this signature in database
13 changed files with 921 additions and 251 deletions

View file

@ -1,17 +1,3 @@
// Creates and configures custom dimensions
const raw = JsonIO.readJson("kubejs/config/settings.json");
const config = raw ? JSON.parse(raw.toString()) : {};
function hexToRgb(hex) {
const h = hex.replace("#", "");
return {
r: parseInt(h.substring(0, 2), 16),
g: parseInt(h.substring(2, 4), 16),
b: parseInt(h.substring(4, 6), 16),
};
}
var portalColor;
ServerEvents.highPriorityData((event) => {
@ -19,9 +5,8 @@ ServerEvents.highPriorityData((event) => {
config.dimensions.forEach((dimension) => {
const [modId, dimId] = dimension.id.split(":");
/////////////////
/// DIMENSION ///
/////////////////
// Add dimension
/** @type {any} */
const dimJson = { type: "minecraft:overworld" };
if (dimension.worldgen)
dimJson["generator"] = {
@ -41,29 +26,28 @@ ServerEvents.highPriorityData((event) => {
};
event.addJson(`${modId}:dimension/${dimId}.json`, dimJson);
//////////////
/// PORTAL ///
//////////////
// Add portal
const portal = dimension.portal;
if (portal) {
portalColor = hexToRgb(portal.color);
event.addJson(`${modId}:portals/${dimId}.json`, {
block: portal.material,
dim: dimension.id,
r: portalColor.r,
g: portalColor.g,
b: portalColor.b,
ignitionType: "FLUID",
ignitionSource: portal.fluid,
});
event.addJson(
`${modId}:portals/${dimId}.json`,
/** @type {any} */ ({
block: portal.material,
dim: dimension.id,
r: portalColor.r,
g: portalColor.g,
b: portalColor.b,
ignitionType: "FLUID",
ignitionSource: portal.fluid,
}),
);
}
});
}
});
//////////////
/// DIMINV ///
//////////////
// Setup Dimensional Inventories
PlayerEvents.loggedIn((event) => {
if (config.dimensions) {
config.dimensions.forEach((dimension) => {
@ -71,22 +55,38 @@ PlayerEvents.loggedIn((event) => {
const data = event.server.persistentData;
if (!data.getBoolean(`${dimId}Initialized`)) {
data.putBoolean(`${dimId}Initialized`, true);
event.server.scheduleInTicks(20, () => {
event.server.runCommandSilent(`diminv pool ${dimId} create`);
event.server.runCommandSilent(
`diminv pool ${dimId} dimension ${dimension.id} assign`,
);
event.server.runCommandSilent(
`diminv pool ${dimId} gameMode ${dimension.gamemode}`,
);
event.server.runCommandSilent(
`diminv pool ${dimId} progressAdvancements false`,
);
event.server.runCommandSilent(
`diminv pool ${dimId} incrementStatistics false`,
);
});
event.server.scheduleInTicks(
20,
/** @type {any} */ (
() => {
event.server.runCommandSilent(`diminv pool ${dimId} create`);
event.server.runCommandSilent(
`diminv pool ${dimId} dimension ${dimension.id} assign`,
);
event.server.runCommandSilent(
`diminv pool ${dimId} gameMode ${dimension.gamemode}`,
);
event.server.runCommandSilent(
`diminv pool ${dimId} progressAdvancements false`,
);
event.server.runCommandSilent(
`diminv pool ${dimId} incrementStatistics false`,
);
}
),
);
}
});
}
});
// Disable entity spawning
EntityEvents.checkSpawn((event) => {
if (!event.level) return;
config.dimensions.forEach((dimension) => {
if (event.level.dimension.toString() === dimension.id) {
event.cancel();
}
});
});