Jump to content

Generating Block on Surface Not Working


Justin_Perry

Recommended Posts

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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();
	}
	

ย 

Link to comment
Share on other sites

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 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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. ๐Ÿ“ˆ Skills: RPG-style skill system that enhances your gaming experience! ๐ŸŽฎ Leaderboards: Compete and shine! Top players are rewarded weekly! ๐Ÿ† Random Teleporter: Travel instantly across different worlds with a click! ๐ŸŒ Custom World Generation: Beautifully generated world. ๐ŸŒ Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. ๐Ÿฐ Kits: Unlock ranks and gain access to various kits. ๐Ÿ› ๏ธ Fishing Tournament: Compete in a friendly fishing tournament! ๐ŸŽฃ Chat Games: Enjoy games right within the chat! ๐ŸŽฒ Minions: Get some help from your loyal minions. ๐Ÿ‘ฅ Piรฑata Party: Enjoy a festive party with Piรฑatas! ๐ŸŽ‰ Quests: Over 1000 quests that you can complete! ๐Ÿ“œ Bounty Hunter: Set a bounty on a player's head. ๐Ÿ’ฐ Tags: Displayed on nametags, in the tab list, and in chat. ๐Ÿท๏ธ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! ๐ŸŸข Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. ๐Ÿ”ฒโœจ[ Player Warp: Set your own warp points for other players to teleport to. ๐ŸŒŸ Display Shop: Create your own shop and sell to other players! ๐Ÿ›’ Item Skins: Customize your items with unique skins. ๐ŸŽจ Pets: Your cute loyal companion to follow you wherever you go! ๐Ÿพ Cosmetics: Enhance the look of your character with beautiful cosmetics! ๐Ÿ’„ XP-Bottle: Store your exp safely in a bottle for later use! ๐Ÿถ Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! ๐Ÿ“ฆ Glowing: Stand out from other players with a colorful glow! โœจ Player Particles: Over 100 unique particle effects to show off. ๐ŸŽ‡ Portable Inventories: Over virtual inventories with ease. ๐Ÿงณ And a lot more! Become part of our growing community today! Discord:ย https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working ย  I am not familiar with Linux - check for similar/related issues ย 
  • Topics

×
×
  • Create New...

Important Information

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