Jump to content

[1.8] How to generate mushrooms in the world?


JimiIT92

Recommended Posts

As by title, how can i generate my custom mushroom in the world the same way vanilla mushroom does? I have this code in my WorldGenMinable class

for(int i = 0; i < 1; i++)
	{
		int randPosX = x + random.nextInt(16) + 8;
		int randPosY = random.nextInt(55);
		int randPosZ = z + random.nextInt(16) + 8;
		new WorldGenBlockBlob(HLFlowers.mushroomGlow, 0).generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
	}

 

But the mushrooms are generated as ores (also not spawning only underground, they can spawn in overworld or underwater)

lYn1ILi.png

What should i change? :)

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Since my class is extending BlockMushroom i get this ClassCastError when using WorldGenFlowers :/

java.lang.ClassCastException: hl.blocks.BlockMushroomGlow cannot be cast to net.minecraft.block.BlockFlower

 

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

I've done this

for(int i = 0; i < 2; i++)
	{
		int randPosX = x + random.nextInt(16) + 8;
		int randPosY = random.nextInt(64);
		int randPosZ = z + random.nextInt(16) + 8;
		new GeneratorBushFeature((BlockBush) HLFlowers.mushroomGlow).generate(world, random, new BlockPos(randPosX, randPosY, randPosX));
	}

But it still spawns as an ore :(

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Vanilla uses this in the ChunkPoviderHell class. I've looked it and it does this

BlockPos pos = new BlockPos(x, 0, z);
	boolean doGen = TerrainGen.decorate(world, random, pos, SHROOM);
        if (doGen && random.nextBoolean())
        {
        	new GenMushrooms((BlockBush)HLFlowers.mushroomGlow).generate(world, random, pos.add(random.nextInt(16) + 8, random.nextInt(128), random.nextInt(16) + );
        }

So i've this in my WorldGenMinable class

package hl.world;

import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.SHROOM;

import java.util.Random;

import com.google.common.base.Predicate;

import hl.blocks.BlockHive;
import hl.core.HLBlocks;
import hl.core.HLFlowers;
import hl.core.HLSummons;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockHelper;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.GeneratorBushFeature;
import net.minecraft.world.gen.feature.WorldGenBlockBlob;
import net.minecraft.world.gen.feature.WorldGenFlowers;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraftforge.event.terraingen.TerrainGen;
import net.minecraftforge.fml.common.IWorldGenerator;
import sun.net.www.protocol.http.logging.HttpLogFormatter;

public class WorldGenMinableHL implements IWorldGenerator {

@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
		IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {

	switch(world.provider.getDimensionId()) {
	case 0:
		generateOverworld(random, world, chunkX*16, chunkZ*16);
		break;
	case -1:
		generateNether(random, world, chunkX*16, chunkZ*16);
		break;
	case 1:
		generateEnd(random, world, chunkX*16, chunkZ*16);
		break;
	default:
		generateOverworld(random, world, chunkX*16, chunkZ*16);
	}

}

private void generateOverworld(Random random, World world, int x, int z) {
	addOres(HLBlocks.limestone, world, random, x, z, 70, 20, 15, 252);
	addOres(HLBlocks.dirtDry, world, random, x, z, 70, 20, 15, 252);
	addOres(HLBlocks.lavastone, world, random, x, z, 15, 18, 15, 252);
	addMetaOres(HLBlocks.oreMythril.getStateFromMeta(0), world, random, x, z, 4, 10, 15, 20);

	for(int i = 0; i < 1; i++)
	{
		int randPosX = x + random.nextInt(16) + 8;
		int randPosY = random.nextInt(200);
		int randPosZ = z + random.nextInt(16) + 8;
		(new WorldGenFlowers((BlockFlower)HLFlowers.flowerPurple, BlockFlower.EnumFlowerType.DANDELION)).generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
	}

	for(int i = 0; i < 1; i++)
	{
		int randPosX = x + random.nextInt(16) + 8;
		int randPosY = random.nextInt(200);
		int randPosZ = z + random.nextInt(16) + 8;
		(new WorldGenFlowers((BlockFlower)HLFlowers.flowerWhite, BlockFlower.EnumFlowerType.DANDELION)).generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
	}

	BlockPos pos = new BlockPos(x, 0, z);
	boolean doGen = TerrainGen.decorate(world, random, pos, SHROOM);
        if (doGen && random.nextBoolean())
        {
        	new GenMushrooms((BlockBush)HLFlowers.mushroomGlow).generate(world, random, pos.add(random.nextInt(16) + 8, random.nextInt(128), random.nextInt(16) + );
        }
        

	for(int i = 0; i < 20; i++)
	{
		int randPosX = x + random.nextInt(16) + 8;
		int randPosY = random.nextInt(100) + 50;
		int randPosZ = z + random.nextInt(16) + 8;
		new WorldGenHive().generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
	}

	for (int j = 0; j < 15; j++)
	{
		int chance = random.nextInt(2);
		int randPosX = x + random.nextInt(16) + 8;
		int randPosZ = z + random.nextInt(16) + 8;
		int randPosY = random.nextInt(200);   	               
		if(chance == 1)
		{
			(new WorldGenBush(HLBlocks.bush, 1)).generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
		}
	}


	for(int i = 0; i < 15; i++)
	{
		int randPosX = x + random.nextInt(16); //DO NOT CHANGE THIS NUMBER
		int randPosY = random.nextInt(75); //ONLY CHANGE THIS ONE, IT SETS THE MAX HEIGHT AT WHICH IT GENERATES
		int randPosZ = z + random.nextInt(16); //DO NOT CHANGE THIS NUMBER
		BlockPos new_pos = new BlockPos(randPosX, randPosY, randPosZ);
		if(world.getBiomeGenForCoords(new_pos).equals(BiomeGenBase.beach))
		{
			new WorldGenPalmTree().generate(world, random, new_pos);
		}
	}

	}

	private void generateEnd(Random random, World world, int x, int z) {
		addEndOres(HLBlocks.oreMythril.getStateFromMeta(1), world, random, x, z, 50, 15, 0, 200);
	}

	private void generateNether(Random random, World world, int x, int z) {
		for(int i = 0; i < 250; i++)
		{
			int randPosX = x + random.nextInt(16) + 8;
			int randPosY = random.nextInt(255);
			int randPosZ = z + random.nextInt(16) + 8;
			new WorldGenFireLily().generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
		}

	}


	private void addOres(Block block, World world, Random random, int blockXpos, int blockZpos, int MaxVein, int spawnChance, int minY, int maxY) {

		WorldGenMinable minable = new WorldGenMinable(block.getDefaultState(), random.nextInt(MaxVein));
		for (int i = 0; i < spawnChance; i++) {
			int posX = blockXpos + random.nextInt(16);
			int posZ = blockZpos + random.nextInt(16);
			int posY = minY + random.nextInt(maxY - minY);
			minable.generate(world, random, new BlockPos(posX, posY, posZ));
		}

	}

	private void addEndOres(IBlockState block, World world, Random random, int blockXpos, int blockZpos, int MaxVein, int spawnChance, int minY, int maxY) {

		WorldGenMinable minable = new WorldGenMinable(block, random.nextInt(MaxVein), BlockHelper.forBlock(Blocks.end_stone));
		for (int i = 0; i < spawnChance; i++) {
			int posX = blockXpos + random.nextInt(16);
			int posZ = blockZpos + random.nextInt(16);
			int posY = minY + random.nextInt(maxY - minY);
			minable.generate(world, random, new BlockPos(posX, posY, posZ));
		}

	}

	private void addMetaOres(IBlockState block, World world, Random random, int blockXpos, int blockZpos, int MaxVein, int spawnChance, int minY, int maxY) {

		WorldGenMinable minable = new WorldGenMinable(block, random.nextInt(MaxVein));
		for (int i = 0; i < spawnChance; i++) {
			int posX = blockXpos + random.nextInt(16);
			int posZ = blockZpos + random.nextInt(16);
			int posY = minY + random.nextInt(maxY - minY);
			minable.generate(world, random, new BlockPos(posX, posY, posZ));
		}

	}
}

 

But nothing changed :/ Still spawning like this

CSGSrfv.png

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

This is my BlockMushroom class

package hl.blocks;

import java.util.Random;

import hl.core.HLBlocks;
import hl.core.HLFlowers;
import hl.core.HLTabs;
import net.minecraft.block.Block;
import net.minecraft.block.BlockMushroom;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenBigMushroom;

public class BlockMushroomGlow extends BlockMushroom {

public BlockMushroomGlow()
{
	super();
	this.setCreativeTab(HLTabs.tabDecorations);
	this.setStepSound(soundTypeGrass);
	this.setLightLevel(0.225F);
}

@Override
    protected boolean canPlaceBlockOn(Block ground)
    {
	return ground != HLFlowers.mushroomGlow;
    }

/**
 * Whether this IGrowable can grow
 */
@Override
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
	return false;
}

@Override
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
	return false;
}

@Override
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
    {
    }

@Override
public boolean generateBigMushroom(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
	return false;
    }
}

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Yep, and here is your problem:

@Override
protected boolean canPlaceBlockOn(Block ground)
{
return ground != HLFlowers.mushroomGlow;
}	

Look at BlockMushroom's implementation. You shouldn't even need to override this method unless your new mushroom is a full block, and then you should either call super or perform the same check.

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



×
×
  • Create New...

Important Information

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