#make ALL variations of an item generate within a worldborder
11 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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)
Will give you a rundown of Important Things to Note for each step.
- Use
ServerEvent.loadedEvent. Check thatevent.server.persistentData.gemDatais undefined, If it is, useMath.floor(Math.random() * 2000) - 1000to get the x and z coordinates and Change the values a little for y. Then Store this inside theevent.server.persistendData.gemDataby 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 toevent.server.persistendData.gemDatathen do this 200 times using a for Loop and modifying the gemData object accordingly.
- 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 useevent.level.getBlock(new BlockPos(gem.x, gem.y, gem.z)).set("yourgemblockidhere")
- This is a little easier again, in the Same event as for 2nd. and then try
delete event.server.persistentData.gemData["x3z6"]
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
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
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
Awesome thank you!
Ticket closed!