Jump to content

Recommended Posts

Posted
package Justin_Perry.learningMod.gen;

import java.util.Random;

import Justin_Perry.learningMod.init.modBlocks;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraftforge.fml.common.IWorldGenerator;

public class nestGen implements IWorldGenerator{
	
	@Override
	public void generate(Random random, int ChunkX, int ChunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
		if (world.provider.getDimension() == 0 ) {
			generateSurface(random, ChunkX, ChunkZ, world, chunkGenerator, chunkProvider);
		}
	}
	private void generateSurface(Random random, int ChunkX, int ChunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
		generateOre(modBlocks.BEE_NEST_BLOCK.getDefaultState(), world, random, ChunkX*16, ChunkZ*16, 63, 80, 40, 50);
	}
	private void generateOre(IBlockState ore, World world, Random random, int x, int z, int minY, int maxY, int size, int chances) {
		
		int deltaY = maxY - minY;
		for(int i = 0; i < chances; i++) {
			BlockPos pos = new BlockPos (x + random.nextInt(16), minY + random.nextInt(deltaY), z + random.nextInt(16));
			
			
			WorldGenMinable generator = new WorldGenMinable(ore, size);
			generator.generate(world, random, pos);
			
		}
	}
}

 

I am attempting to generate a block, BEE_NEST_BLOCK on the surface of the overworld only. I have drastically increased the size and possibility of the block's generation just to make sure it is being generated. I discovered it is, in fact, being generated, However, my hypothesis, based on visual inspection, is that these blocks are only "replacing" stone blocks. If I could be lead in the right direction, I would appreciate it. I have spent a few hours on this situation as well as looking for a hint from previous posts, but I could not find any. Thank you very much for your time, patience, and effort to help me.

Posted
2 minutes ago, Justin_Perry said:

I can find no documentation on generating blocks on the surface of the overworld.

Yeah, that's it's tricky, you have to use a word gen subscriber and resolve where is the highest grass or surface block...at least that how I did it to gen some crop patches, I suggest looking into the code that handles grass placement it helped me...

Posted
27 minutes ago, Justin_Perry said:

I appreciate the help but by using WorldGenPumpkin I am only spawning in more pumpkins.

You use the WorldGenPumpkin class as a reference for your own worldgen class, but replace the pumpkins with the block that you want. Or, add a block to your constructor so you can use any block without creating a new class.

Posted
5 minutes ago, Dizzlepop12 said:

You use the WorldGenPumpkin class as a reference for your own worldgen class, but replace the pumpkins with the block that you want. Or, add a block to your constructor so you can use any block without creating a new class.

how do I locate the worldgenpumpkin class?

Posted

After today I will be educating myself in Java. I have one last request that someone look at my code and give me some final advice. Thanks.

 

package Justin_Perry.learningMod.gen;

import java.util.Random;

import Justin_Perry.learningMod.init.modBlocks;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenPumpkin;



public class nestGen extends WorldGenPumpkin{
	
	@Override
	public boolean generate(World worldIn, Random rand, BlockPos position) {
			for (int i = 0; i < 64; ++i)
	        {
	            BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(7), rand.nextInt(4) - rand.nextInt(3), rand.nextInt(8) - rand.nextInt(7));

	            if (worldIn.isAirBlock(blockpos) && worldIn.getBlockState(blockpos.down()).getBlock() == Blocks.GRASS && modBlocks.BEE_NEST_BLOCK.canPlaceBlockAt(worldIn, blockpos))
	            {
	                worldIn.setBlockState(blockpos, modBlocks.BEE_NEST_BLOCK.getDefaultState(), 2);
	            }
	        }
		
		  return true;
	}
	
}

 

I am calling it in PreInit as

 

@EventHandler
	public static void PreInit(FMLPreInitializationEvent event)
	{
		new nestGen();
	}
	

 

Posted

Advice: read this https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Your code looks fine, but your naming is horrible.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
8 minutes ago, Cadiboo said:

Advice: read this https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Your code looks fine, but your naming is horrible.

While I appreciate the feedback on my naming, that's not what I am asking help on. The code is not fine, it does not do what I intended. I am aware of my naming and misuse of convention, but I strictly kept it that way and made myself well aware of non-capitalization and wording. Take care.

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.