How to make an entity spawn in a cave around the player?

Started by yesrebel on

Topic category: Help with Minecraft modding (Java Edition)

Joined Apr 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make an entity spawn in a cave around the player?

I need to make an entity spawn at a random block within a 20-block cube around the player, only if the block is air. Since I need it to spawn while you're in the caves or just underground in general. 

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Check sky light level = 0…
Mon, 05/25/2026 - 08:45

Check sky light level = 0 for underground, also check y level is below 64 or so.

Use on player tick update, use the procedure template check block in 6x6x6 area, change the values to be a 20x20x20 area. Then on the if block = block, change to block = air, AND sky light = 0, AND y<64, if all true spawn entity at that position. Also make a local logic variable, set it to true after spawning the entity so that oly one spawns. Also prior to the template you should add a random chance for this to occur.