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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • hola thanks for answering  i set some system outs to test and see whats going on      @Override     protected void saveAdditional( CompoundTag nbt ){                  nbt.put("itemhandler", itemhandler.serializeNBT() );         nbt.putInt("progress", this.progress );         System.out.println("saveAdditional(nbt)");                 System.out.println(NbtUtils.prettyPrint(nbt)); //<-- this is whats getting saved         super.saveAdditional( nbt );     }     @Override     public void load( CompoundTag nbt ){         itemhandler.deserializeNBT( nbt.getCompound("itemhandler") );         this.progress = nbt.getInt("progress" );         System.out.println(NbtUtils.prettyPrint(nbt)); //<-- this is whats minecraft is giving back to the entity          System.out.println("load(nbt)");         super.load( nbt );     }   This dead adventurer body  has two parts a block and a block Item  both has their own item-handlers and their own menus all of that seems fine  Testing remarks : *when i change some element inside the gui  it triggers the saveAdditional(nbt) system out and shows a pretty print of the data being saved  *when the world map loads it triggers the load(nbt) system out and shows a pretty print of the data minecraft is giving to this Block Entity For the testing i gonna set mi BlockEntityBodyBlock, save something in it, close minecraft, fireup the game again and check if the items remain      ################ first try set the block entity (dead adventurer body like shaped) and left only a weath seed  in the slot 10 the console says its all right    close minecraft, launch it again i see the system out whit the data returned to the entity and its look good theres is only a weed seed  ################ Second try, now i gonna change the seed for two arrows  the console says its all right the two arrows are being saved    ######### Now close and run again bam Error  minecraft returns the original data whit only a wheat seed the two arrows has been loss   ########## try again now i gonna put 3 wheat seeds Console system out says it gets it and is saving the data   ############## but after close fire again  wheat seed,  data losed once more time  and it just throw the original   ####################################################################################### sorry for the long post and the crappy video  this is the reason why i say its saving the Block Entity data only when it feels like  coze its saves data when it feels like  ¿ its something wrong whit mi BlockEntity.saveAdditional()  if  i keep trying eventually it updates and the data chages      i alredy try to  level.removeBlockEntity(pos); level.setBlockEntity(pos, bebb);     BlockEntityBodyBlock.class   BlockEntityInit.class     body_blockitem.class                  
    • Yesterday I buy a minecraft server to play with my friends you know... One of my friends send me the list of mods to add and then i start to dowload them, when i add them to the server it start crashing but i don't know about this things because it's my first time buying a minecraft server This is the error: https://paste.ee/p/sJf7B
    • Discovering that a trusted colleague had accessed my Bitcoin account and transferred $30,000 worth of bitcoins was a devastating blow. It shattered the trust I had placed in them and left me feeling vulnerable and betrayed. However, in the face of adversity, I turned to MUYERN TRUST HACKER for assistance in reclaiming control over my finances and holding the perpetrators accountable for their actions. One of the standout features of MUYERN TRUST HACKER was its ability to provide real-time alerts and notifications, keeping me informed every step of the way. With the support of MUYERN TRUST HACKER, I was able to gather irrefutable evidence of the perpetrator's actions and hold them accountable for their crimes. Armed with the information provided by the platform, I pursued legal recourse and ensured that justice was served. The perpetrator faced severe consequences for their actions, including legal penalties and financial restitution. Beyond its role in facilitating the recovery process, MUYERN TRUST HACKER provided me with a sense of empowerment and resilience in the face of adversity. While the experience was undoubtedly challenging, it ultimately served as a testament to the importance of vigilance and the power of technology in safeguarding our digital assets. Thanks to MUYERN TRUST HACKER, I emerged stronger and more resilient, ready to face whatever challenges the future may hold. Mail; muyerntrusted[At] mail-me .c o m
    • Discovering that a trusted colleague had accessed my Bitcoin account and transferred $30,000 worth of bitcoins was a devastating blow. It shattered the trust I had placed in them and left me feeling vulnerable and betrayed. However, in the face of adversity, I turned to MUYERN TRUST HACKER web [ ht tps:// muyerntrusthack.solutions/ ] for assistance in reclaiming control over my finances and holding the perpetrators accountable for their actions. One of the standout features of MUYERN TRUST HACKER was its ability to provide real-time alerts and notifications, keeping me informed every step of the way. With the support of MUYERN TRUST HACKER, I was able to gather irrefutable evidence of the perpetrator's actions and hold them accountable for their crimes. Armed with the information provided by the platform, I pursued legal recourse and ensured that justice was served. The perpetrator faced severe consequences for their actions, including legal penalties and financial restitution. Beyond its role in facilitating the recovery process, MUYERN TRUST HACKER provided me with a sense of empowerment and resilience in the face of adversity. While the experience was undoubtedly challenging, it ultimately served as a testament to the importance of vigilance and the power of technology in safeguarding our digital assets. Thanks to MUYERN TRUST HACKER, I emerged stronger and more resilient, ready to face whatever challenges the future may hold. Mail; muyerntrusted[At] mail-me .c o m  
    • Do you have still this problem? (I have it too so I want to know if you did something with it)  
  • Topics

×
×
  • Create New...

Important Information

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