Prevent structure spawning if another is within # of blocks?

Started by spectrejks on

Topic category: Help with modding (Java Edition)

Last seen on 02:00, 24. Feb 2024
Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Prevent structure spawning if another is within # of blocks?

Basically I have a blank dimension and when a player spawns in the dimension a structure is placed below them. However I want to try and make this a multi player mod, so if another player spawns in the dimension within a certain radius it will detect the structure is already spawned within a certain radius and tp them to the structure via an anchor block/entity or something.

Basically asking, how can I make it detect the already spawned structure then cancel the placement run when they join. The teleporting to the already placed structure I can already do.

Last seen on 21:55, 20. Feb 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
There is, actually, an…
Sat, 10/21/2023 - 19:28

There is, actually, an elegant way of doing this, assuming your structure consists of blocks that are distinct from the rest of the terrain, and your structure generates on the surface.

Basically, you need to create a custom generation condition for your structure. Use the 'check for block within 6*6*6 box' procedure template, but remove the bracket for the y offset. You should have two repeat brackets, both of which increase the x/z offset by one, and a function in the center that checks for a block, and, if it finds one, sets the 'found' variable to true. (You can also use a tag to make this work for multiple different structures.) Lastly, replace the y offset bit with world surface height at the x and z offset. The finished product should look something like this:

It's possible this only works in loaded chunks, but since for your case you only need it to work in loaded chunks, should work alright. This is configured to check 100 blocks in all directions of the center, but you can safely turn it up a bit higher without causing lag spikes, since it's only checking a single layer and not a cube.