Using World Seed in Recipe
OriginalNovember 10, 2024Less than 1 minute
Using World Seed in Recipe
Summary
Get the Accurate World Seed
const seed = NBT.l(server.worldData.worldGenOptions().seed());
Tips
The seed can only be stored as a String or NBT. If stored as a Number, it may result in inaccuracies due to Java Double floating-point precision errors.
ServerEvents.loaded((event) => {
const { server } = event;
const seed = server.worldData.worldGenOptions().seed();
server.persistentData.putLong("seed", seed);
server.scheduleInTicks(10, () => server.runCommandSilent("reload"));
});
ServerEvents.recipes((event) => {
const { server } = Utils;
if (!server) return;
const seed = server.persistentData.getLong("seed");
// do_something(seed);
});