#make ALL variations of an item generate within a worldborder

11 messages · Page 1 of 1 (latest)

tulip rover
#

Let’s say there are 200 variations of a “magic gem” block that each fufill a specific ftb quest or something.

Is it possible to force all 200 unique gems to spawn with a given area (like a 1000x1000 world border) so that players can find all of them?

visual glacierBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

golden nymph
#

There are multiple Problems with this making the Code relaitvely complicated, though Not impossible.

Firstly, limiting the Count of something means you will need to use Math.random to generate the coordinates beforehand. So you can't use a worldgen Event.
This you will need to Store in persistentData.

Secondly you need to get If a chunk is loaded, then get the persistentData for this chunks and place the Blocks.

Last you need to modify the persistentData to say this chunks was already gened (Just remove this chunks entry from the object)

golden nymph
#

Will give you a rundown of Important Things to Note for each step.

  1. Use ServerEvent.loaded Event. Check that event.server.persistentData.gemData is undefined, If it is, use Math.floor(Math.random() * 2000) - 1000 to get the x and z coordinates and Change the values a little for y. Then Store this inside theevent.server.persistendData.gemData by using the chunk coordinates those can be calculated by biteshifting the coords (x and z) 4 times. Store it something Like this: {x3z6: [{x: 50, y: 32, z: 57}]} this is then assigned to event.server.persistendData.gemData then do this 200 times using a for Loop and modifying the gemData object accordingly.
#
  1. Is a little more complicated cause you need to get If a chunk is loaded / and then also get the chunk coordinates. I'm Sure Somebody else will have an Idea in how to do this. Then Just Look it Up in the gemData object by using .get("x3z6") then you can Loop over the object with .forEach(gem => {}), then use event.level.getBlock(new BlockPos(gem.x, gem.y, gem.z)).set("yourgemblockidhere")
#
  1. This is a little easier again, in the Same event as for 2nd. and then try delete event.server.persistentData.gemData["x3z6"]
tulip rover
#

Yikes okay that is all incredibly helpful but may be a touch out of my league
I assume it would be impossible or at least much worse to then put a condition in to make it so these blocks only spawn on the surface or in caves

golden nymph
#
let i
ServerEvents.loaded(event => {
  if(event.server.persistentData.gemData != undefined) return
  event.server.persistentData.gemData = true
  gemData = []
  for(i = 0; i < 200; i++){
    let x = Math.floor(Math.random() * 124) - 62
    let z = Math.floor(Math.random() * 124) - 62
    gemData.push({x: x, z: z})
  }
  
  for(i = 0; i < 200; i++){
    event.server.scheduleInTicks(i, e => {
      e.server.runCommandSilent("forceload add ${gemData[i].x * 16 +1} ${gemData[i].z * 16 +1}")
    })
    event.server.scheduleInTicks(i + 1, e => {
      for(let j = 0; j < 10000; j++){
        let x = Math.floor(Math.random() * 16)
        let y = Math.floor(Math.random() * 120) - 63
        let z = Math.floor(Math.random() * 16)
        if(e.server.getLevel("overworld").getBlock(new BlockPos(x, y, z)).id == "minecraft:air"){
          e.server.getLevel("overworld").getBlock(new BlockPos(x, y, z)).set("yourgemblockhere")
          break
        }
      }
      e.server.runCommandSilent("forceload remove ${gemData[i].x * 16 +1} ${gemData[i].z * 16 +1}")
    })
  }
})

try this

golden nymph
#

It uses a different system as described above, because it's easier (a lot actually, sorry for first thinking that the stuff described at the top was needed) and basically does the Same thing

tulip rover
#

Awesome thank you!