# How to spawn structures in underground caves

## Recommended Posts

I was using this method I found on the Internet yet it still doesn't work

public void generateNestUnderground(World world, Random random, int chunkX, int chunkZ, Random rand) {
int x = chunkX * 16 + random.nextInt(16);
int z = chunkZ * 16 + random.nextInt(16);
int xy = x >> 4;
int zy = z >> 4;
int height = world.getChunkFromChunkCoords(xy, zy).getHeight(new BlockPos(x & 15, 0, z & 15));
int y = height - 1;

if(world.getBiomeForCoordsBody(new BlockPos(x,y,z)).getBiomeClass().equals(BiomePlains.class)) {

if((random.nextInt(120) + 1) <= 1) {
boolean place = true;

for(int Y = 0; Y < 30; Y++) {
for(int Z = 0; Z < 9; Z++) {
for(int X = 0; X < 11; X++) {
if(world.getBlockState(new BlockPos(X + x, Y + y + 1, Z + z)).getBlock() != Blocks.AIR) {
place = false;
}
}
}
}

if(place) {
dragonNest.generate(world, random, new BlockPos(x,y,z));
}
}
}
}

All throughout the web I had been asking yet I always get the answer "you use ChunkProviderOverWorld" my question is how?

• Replies 57
• Created

#### Posted Images

generateNestUnderground

This does not generate underground due to these lines.

int height = world.getChunkFromChunkCoords(xy, zy).getHeight(new BlockPos(x & 15, 0, z & 15));
int y = height - 1;

dragonNest.generate(world, random, new BlockPos(x,y,z));

if((random.nextInt(120) + 1) <= 1) {

This line makes the chance of it spawning 1 in 120.

if(world.getBlockState(new BlockPos(X + x, Y + y + 1, Z + z)).getBlock() != Blocks.AIR) {

This line makes the chance harder if it was underground, but since it is above ground this works.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

This does not generate underground due to these lines.

This line makes the chance of it spawning 1 in 120.

This line makes the chance harder if it was underground, but since it is above ground this works.

got any examples, tutorials or exactly tell me how to do it?

##### Share on other sites

Basically everything is correct if you want it to generate above ground. And as rare as I said. With the variable "height" you get the height of the chunk, or the average height. To put it simply it is typically above ground. To make it generate underground subtract some from the "height" variable.

You might also want to remove the

for(int Y = 0; Y < 30; Y++) {
for(int Z = 0; Z < 9; Z++) {
for(int X = 0; X < 11; X++) {
if(world.getBlockState(new BlockPos(X + x, Y + y + 1, Z + z)).getBlock() != Blocks.AIR) {
place = false;
}
}
}
}

Because this serves only to make sure the Block is air and underground that is not very likely to happen.

The 1 in 120 chance is not that bad, but it does make it hard to debug and make sure that it is generating so i suggest lowering it to something like 1 in 25 while testing.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

Basically everything is correct if you want it to generate above ground. And as rare as I said. With the variable "height" you get the height of the chunk, or the average height. To put it simply it is typically above ground. To make it generate underground subtract some from the "height" variable.

You might also want to remove the

Because this serves only to make sure the Block is air and underground that is not very likely to happen.

The 1 in 120 chance is not that bad, but it does make it hard to debug and make sure that it is generating so i suggest lowering it to something like 1 in 25 while testing.

how about 1 and 15? or 1 and 10? My idea is to lower it to see if it does spawn.

##### Share on other sites

That will significantly increase your chances. I already tested it myself and unless dragonNest.generate doesn't work it should generate for you.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

1 minute ago, Animefan8888 said:

That will significantly increase your chances. I already tested it myself and unless dragonNest.generate doesn't work it should generate for you.

I really need an answer, I am not killing you to get one tho, but last time I posted the same problem, it got 4000 views so a lot of people other than me seriously needs an answer and I don't really fully know this game, I mean I know how a game works like you need a model an AI to program a living creature in a game but my problem is I don't know how it works in code.

##### Share on other sites

I really need an answer, I am not killing you to get one tho, but last time I posted the same problem, it got 4000 views so a lot of people other than me seriously needs an answer and I don't really fully know this game, I mean I know how a game works like you need a model an AI to program a living creature in a game but my problem is I don't know how it works in code.

When I said

7 minutes ago, Animefan8888 said:

That will significantly increase your chances.

I didn't mean that it would increase your chances of it working, but that it would increase the chance of you finding it.

Also where are you calling this method from? Because it needs to be called from an IWorldGenerator and that IWorldGenerator needs to be registered via GameRegistry.registerWorldGenerator

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

When I said

I didn't mean that it would increase your chances of it working, but that it would increase the chance of you finding it.

Also where are you calling this method from? Because it needs to be called from an IWorldGenerator and that IWorldGenerator needs to be registered via GameRegistry.registerWorldGenerator

I know! I understand the first sentence because it was explained in the tutorial! I am calling this in an IWorldGenerator, and registered it but the tutorial just explains spawning it above ground and I can't find one that spawns below ground.

##### Share on other sites

spawns below ground.

Simple it is a matter of changing the y variable.

19 minutes ago, Animefan8888 said:

To make it generate underground subtract some from the "height" variable.

...before you create the y variable.

Edited by Animefan8888

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

Simple it is a matter of changing the y variable.

...before you create the y variable.

already tried that but gonna try it with higher chances!

##### Share on other sites

already tried that but gonna try it with higher chances!

Post your new code, the whole class if it doesn't work.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

Post your new code, the whole class if it doesn't work.

I haven't tested it yet, because it's midnight in my country, and I can't even assure if i can do it tommorow because it's saturday and I'm banned using it on sunday to thursday because when it is sunday, it is monday tommorow! and I can't wake up early, I know necro posts are banned but can you give me a permission to allow it?

##### Share on other sites

It is your topic/thread and the problem hasn't been confirmed solved, I know I won't have a problem after a week and a couple days. And if you feel uncomfortable doing it you can always make a new topic/thread.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

It is your topic/thread and the problem hasn't been confirmed solved, I know I won't have a problem after a week and a couple days. And if you feel uncomfortable doing it you can always make a new topic/thread.

k gonna tag you!

##### Share on other sites

1 hour ago, Animefan8888 said:

It is your topic/thread and the problem hasn't been confirmed solved, I know I won't have a problem after a week and a couple days. And if you feel uncomfortable doing it you can always make a new topic/thread.

Ok it does spawn above ground,

##### Share on other sites

Ok it does spawn above ground,

Then problem solved, right?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

Then problem solved, right?

above ground solved underground not.

##### Share on other sites

above ground solved underground not.

To make it generate underground you just need to make the y variable smaller.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

To make it generate underground you just need to make the y variable smaller.

like

int y = height - 78;  // it used to be -1.

##### Share on other sites

like

int y = height - 78;  // it used to be -1.

Yes, now it will spawn 78 blocks below the top of the ground, which could be negative, which is out of bounds so you will want to check for that.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Just now, Animefan8888 said:

Yes, now it will spawn 78 blocks below the top of the ground, which could be negative, which is out of bounds so you will want to check for that.

so it only spawns only and exactly -78 right? How do I make it like 65 to 78?

##### Share on other sites

so it only spawns only and exactly -78 right? How do I make it like 65 to 78?

Random#nextInt(78 - 65) + 65 Will give you a random number between 65 and 78.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

Note that 65 is "above ground" for most biomes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

Just now, Draco18s said:

Note that 65 is "above ground" for most biomes.

like what biomes? so I can make and exception?

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• ### Posts

• One of the mods has an invalid animation json - but this mod is not mentioned Start with GeckoLib and AzureLib and the mods requiring it If this works, add the rest of your mods one by one or in groups until you find the one, causing this issue
• Your new LanguageManager() is not the language manager that is being used when you call Minecraft.getInstant().getLocale(). Minecraft.getLanguageManager().setSelected(code);  should work.  Can you show that code?
• My game keeps crashing due to rendering overlay and blames either geckolib 4 or azurelib, does anyone know a fix? This is the error: https://paste.ee/p/X3tZ8
• Hello, I got some code that won't register in Forge (MC=1.20.4), (FML=49.0.30) (It basically iterates through an array all supported Minecraft languages and picks at random one and reloads ResourceManager with it:     List<String> languageCountryCodes = new ArrayList<>(); Collections.addAll(languageCountryCodes, "af_za", "ara_sa", "ast_es", "aze_az", "bak_ru", "bar_de", "bel_by", "bul_bg", "bre_fr", "qbr_nl", "bos_ba", "cat_es", "ces_cz", "cym_gb", "dan_dk", "bar_at", "gsw_ch", "deu_de", "ell_gr", "eng_au", "eng_ca", "eng_gb", "eng_nz", "qpe", "eng_qabs_gb", "en_ud", "epo", "spa_ar", "spa_cl", "spa_ec", "spa_es", "spa_mx", "spa_uy", "spa_ve", "spa_es_an", "est_ee", "eus_es", "fas_ir", "fin_fi", "fil_ph", "fao_fo", "fra_ca", "fra_fr", "fra_de", "fur_it", "fry_nl", "gle_ie", "gla_gb", "glg_es", "haw_us", "heb_il", "hin_in", "hrv_hr", "hun_hu", "hye_am", "id_id", "ibo_ng", "is_is", "qis", "ita_it", "jpn_jp", "jbo", "kat_ge", "kaz_kz", "kan_in", "kor_kr", "ksh_de", "kw_gb", "lat_va", "ltz_lu", "lim_nl", "lmo_it", "lao_la", "qll", "lit_lt", "lav_lv", "lzh", "mkd_mk", "mon_mn", "zlm_my", "mlt_mt", "nhe_mx", "vmf_de", "msa_my", "mlg_mg", "mar_in", "nld_be", "nld_nl", "nno_no", "nob_no", "quc_latn_gt", "pol_pl", "por_br", "por_pt", "qya", "ro_ro", "qpr", "rus_ru", "srp_latn_rs", "srp_cyrl_rs", "swe_se", "slk_sk", "slv_si", "som_so", "sqi_al", "ckb_ir", "sr_sp", "swa_ke", "swh_tz", "tam_in", "tha_th", "tgk_tj", "uig_cn", "ukr_ua", "urd_pk", "uzb_uz", "ven_za", "cymr", "xho_za", "yor_ng", "yue_hk", "zho_hans_cn", "zho_hant_hk", "zho_hant_tw"); // Shuffle the list Collections.shuffle(languageCountryCodes); // Print one code at a time for (String code : languageCountryCodes) { LanguageManager languageManager = new LanguageManager(code); languageManager.onResourceManagerReload(TroubleshootingMod.getResourceManager()); System.out.println(Minecraft.getInstance().getLocale()); System.out.println(code); break; // Exit the loop after printing one code } Minecraft.getInstance().getLanguageManager().setSelected("bar_de"); also does not appear to be functional..   Kind regards, Ensamisten

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...