#Reload server automatically on first world load to make world seed accessible.

41 messages · Page 1 of 1 (latest)

uneven magnet
#
// priority: 1000

ServerEvents.recipes((e) => {
  // Perform this operation here to check if
  const server = Utils.getServer()
  global.WORLD_SEED =
    server === null ? -1 : server.worldData.worldGenOptions().seed()
})

ServerEvents.loaded((e) => {
  // Reloads the server on the first world load to ensure the world seed is
  // available for recipe registration.
  if (global.WORLD_SEED === -1) {
    e.server.runCommandSilent('reload')
  }
})

Pretty straightforward. This script tries to load the world seed into a global, in case you want to use it to seed a PRNG for recipe generation. It does a reload if the server was not loaded yet. This won't double reload when you do /reload though because the server is accessible from that point forward.

#

Found a couple support threads about this, and just made my own script for this to avoid double reloads during development.

bronze juniper
#

whats a use case you needed this for o.o

uneven magnet
#

Generating recipes that are different per world, it'll ensure that each playthrough is different for everyone. I seeded a PRNG to generate some of the recipe orderings/ingredients. Keeps some of the automation flows dynamic.

bronze juniper
#

:oo

uneven magnet
#

Create: Above and Beyond did something similar in their pack for the alchemical recipes.

#

This means a) replayability b) no formulaic way to solve the puzzle using create

#

I was sort of wondering about different ways to do this because of how weird this is. Is there a way to get a world specific UUID to seed a PRNG? I couldnt think of anything other than the world seed which seemed the most obvious.

#

I also thought about storing the world seed to the server.persistentData but that doesn't work either if the server isn't available on first load to read pdata from.

bronze juniper
#

i find it weird that theres no seed available without a reload
but you could also just make a random uuid yourself and assign it to a persistent variable using a recipe event or something, and only doing that if there is no value saved already

uneven magnet
#

I tried Utils.getServer().persistentData but that's not available in recipe event either for the same reason.

#

Generating my own UUID is also valid, I just don't know where to store it so I can retrieve it in the recipe event in subsequent reloads.

bronze juniper
uneven magnet
#

e.server is null on the first load in ServerEvents.recipe

bronze juniper
uneven magnet
#

It's the same problem essentially, since that's where I'm getting the seed from anyway

#

e.server.worldData.worldGenOptions().seed()

bronze juniper
#

i wonder if thats a bug or a weird limitation

#

sounds like a bug

uneven magnet
#

No idea, I don't think programmatically generated recipes were intended to be used in this way lo..

#

But in any case, it's the same problem, so this script just checks if server is null and reloads it if so.

bronze juniper
#

have you asked in #1047320998199955458

#

cuz that does not sound like normal behavior

uneven magnet
#

Yes, there are two examples in kubejs support that do something similar.

#

Uncandango does something even weirder by registering a ForgeEvent to reload the server

#

ℹ️ sources cited

uneven magnet
#

lol, imo it seems like a bug but there's so much weird shit with mc that i'm not really surprised at this point

bronze juniper
#

ive asked in one of our private channels for an explanation to see if its an actual bug hmmm

#

id be surprised if it wasnt a bug

uneven magnet
#

👍

scenic river
#

not a bug, unfortunately

#

minecraft preloads datapacks before the actual world loads

#

at least on world creation

#

you‘ll notice that if you open an existing world recipes will be fine

bronze juniper