Justin_Perry Posted March 10, 2019 Posted March 10, 2019 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. Quote
Justin_Perry Posted March 10, 2019 Author Posted March 10, 2019 On 3/10/2019 at 9:00 PM, diesieben07 said: Yes. That's how WorldGenMinable works. It replaces stone blocks. Expand Thank you so much, I will look into that! Quote
Justin_Perry Posted March 11, 2019 Author Posted March 11, 2019 I can find no documentation on generating blocks on the surface of the overworld. Quote
JModder99 Posted March 11, 2019 Posted March 11, 2019 On 3/11/2019 at 12:38 AM, Justin_Perry said: I can find no documentation on generating blocks on the surface of the overworld. Expand 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... Quote
JModder99 Posted March 11, 2019 Posted March 11, 2019 Or better! Look at the one that places pumpkins after all you want to place a few blocks or one block in a chunk! I think it's called WorldGenPumpkin... Quote
Justin_Perry Posted March 11, 2019 Author Posted March 11, 2019 I appreciate the help but by using WorldGenPumpkin I am only spawning in more pumpkins. Quote
Dizzlepop12 Posted March 11, 2019 Posted March 11, 2019 On 3/11/2019 at 1:18 AM, Justin_Perry said: I appreciate the help but by using WorldGenPumpkin I am only spawning in more pumpkins. Expand 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. Quote
Justin_Perry Posted March 11, 2019 Author Posted March 11, 2019 On 3/11/2019 at 1:46 AM, 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. Expand how do I locate the worldgenpumpkin class? Quote
Justin_Perry Posted March 11, 2019 Author Posted March 11, 2019 On 3/11/2019 at 1:57 AM, Justin_Perry said: how do I locate the worldgenpumpkin class? Expand Nevermind, I found it, thank you! Quote
Justin_Perry Posted March 11, 2019 Author Posted March 11, 2019 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(); } Quote
Cadiboo Posted March 11, 2019 Posted March 11, 2019 Advice: read this https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Your code looks fine, but your naming is horrible. Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Justin_Perry Posted March 11, 2019 Author Posted March 11, 2019 On 3/11/2019 at 2:59 AM, Cadiboo said: Advice: read this https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Your code looks fine, but your naming is horrible. Expand 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. Quote
Recommended Posts
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.