Jump to content

[1.7.2] Generate Trees


Guest Abrynos

Recommended Posts

Guest Abrynos

Hey guys! :D I got a problem. I managed it to register my biome and let it spawn into the world. But the problem is I have no idea how to generate my custom trees in that biome.  :-\ I got my custom Saplings to work and I got my log and my leaves to work. Here is what I got:

 

 

My Log class:

public class AbrBlockLog extends BlockLog {
public static final String[] logs = new String[]{"Cherry"};

@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs tabs, List list){
	for(int i = 0; i < logs.length; i++){
		list.add(new ItemStack(item, 1, i));
	}
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister){
	this.field_150167_a = new IIcon[logs.length];
	this.field_150166_b = new IIcon[logs.length];

	for(int i = 0; i < this.field_150167_a.length; i++){
		this.field_150167_a[i] = iconRegister.registerIcon("Abrynos:Log" + logs[i] + "Side");
		this.field_150166_b[i] = iconRegister.registerIcon("Abrynos:Log" + logs[i] + "Top");
	}
}
}

 

My ItemLog class:

public class ItemLogBlocks extends ItemBlock {
public static final String[] logs = new String[] {"Cherry"};

public ItemLogBlocks(Block block){
	super(block);
	this.setHasSubtypes(true);
}

public String getUnlocalizedName(ItemStack itemStack) {
	int i = itemStack.getItemDamage();
	if(i < 0 || i >= logs.length){
		i = 0;
	}
	return super.getUnlocalizedName() + "." + logs[i];
}

public int getMetadata(int meta){
	return meta;
}
}

 

My Leaf class:

public class BlockLeaf extends BlockLeaves {
public static final String[][] leaftypes = new String[][] {{"leaves_whitecherry", "leaves_pinkcherry"}, {"leaves_whitecherry_opaque", "leaves_pinkcherry_opaque"}};
public static final String[] leaves = new String[] {"WhiteCherry", "PinkCherry"};

protected void func_150124_c(World world, int x, int y, int z, int side, int meta)
    {
        if ((side & 3) == 1 && world.rand.nextInt(meta) == 0)
        {
            this.dropBlockAsItem(world, x, y, z, new ItemStack(Items.apple, 1, 0));
        }
    }

    public int damageDropped(int i)
    {
        return super.damageDropped(i) + 4;
    }

    public int getDamageValue(World world, int x, int y, int z)
    {
        return world.getBlockMetadata(x, y, z) & 3;
    }

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list)
    {
    	for(int i = 0; i < leaves.length; i++){
		list.add(new ItemStack(item, 1, i));
	}
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister iconRegister)
    {
        for (int i = 0; i < leaftypes.length; ++i)
        {
            this.field_150129_M[i] = new IIcon[leaftypes[i].length];

            for (int j = 0; j < leaftypes[i].length; ++j)
            {
                this.field_150129_M[i][j] = iconRegister.registerIcon("Abrynos:" + leaftypes[i][j]);
            }
        }
    }

@Override
public IIcon getIcon(int side, int meta){
	return (meta & 3) == 1 ? this.field_150129_M[this.field_150127_b][1] : this.field_150129_M[this.field_150127_b][0];
}

@Override
public String[] func_150125_e() {
	return leaves;
}

@Override
public int getRenderColor(int p_149741_1_)
    {
        return -2;
    }

@Override
public boolean isOpaqueCube()
{
	return false;
}

@Override
public int colorMultiplier(IBlockAccess iBlockAccess, int x, int y, int z) {
	return 0xf6cbec;
    }

@Override
public boolean renderAsNormalBlock(){
	return false;
}

@Override
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side){
	return true;
}
}

My ItemLeaf class:

public class ItemLeafBlocks extends ItemBlock {
public static final String[] leaves = new String[] {"Whitecherry", "Pinkcherry"};

public ItemLeafBlocks(Block block){
	super(block);
	this.setHasSubtypes(true);
}

public String getUnlocalizedName(ItemStack itemStack) {
	int i = itemStack.getItemDamage();
	if(i < 0 || i >= leaves.length){
		i = 0;
	}
	return super.getUnlocalizedName() + "." + leaves[i];
}

public int getMetadata(int meta){
	return meta;
}
}

 

My Sapling class:

public class AbrBlockSapling extends BlockSapling {
public static final String[] saplings = new String[] {"Whitecherry", "Pinkcherry"};
    private static final IIcon[] saplingicon = new IIcon[saplings.length];

    protected AbrBlockSapling()
    {
        float f = 0.4F;
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
        this.setCreativeTab(CreativeTabRegistry.Abrynosplants);
    }

    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World world, int x, int y, int z, Random random)
    {
        if (!world.isRemote)
        {
            super.updateTick(world, x, y, z, random);

            if (world.getBlockLightValue(x, y + 1, z) >= 9 && random.nextInt(7) == 0)
            {
                this.func_149879_c(world, x, y, z, random);
            }
        }
    }

    /**
     * Gets the block's texture. Args: side, meta
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int meta)
    {
        meta &= 7;
        return saplingicon[meta];
    }

    //markOreGrowMarked
    public void func_149879_c(World world, int x, int y, int z, Random random)
    {
        int l = world.getBlockMetadata(x, y, z);

        if ((l &  == 0)
        {
            world.setBlockMetadataWithNotify(x, y, z, l | 8, 4);
        }
        else
        {
            this.func_149878_d(world, x, y, z, random);
        }
    }

    //growTree
    public void func_149878_d(World world, int x, int y, int z, Random random)
    {
        if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(world, random, x, y, z)) return;
        int l = world.getBlockMetadata(x, y, z) & 7;
        Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
        int i1 = 0;
        int j1 = 0;
        boolean flag = false;

        switch (l) {
            case 0: //Whitecherry... 									   ID's of log & leaf = 0, 0
            	object = new AbrWorldGenTrees(TreeRegistry.blockLog, TreeRegistry.blockLeaf, 0, 0, false, 5, 6, false);
            	break;
            case 1: //Pinkcherry... 									   ID's of log & leaf = 1, 1
            	object = new AbrWorldGenTrees(TreeRegistry.blockLog, TreeRegistry.blockLeaf, 0, 1, false, 5, 6, false);
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
            case 5:
            	break;
            default:
            	break;
        }

        Block block = Blocks.air;

        if (flag)
        {
            world.setBlock(x + i1, y, z + j1, block, 0, 4);
            world.setBlock(x + i1 + 1, y, z + j1, block, 0, 4);
            world.setBlock(x + i1, y, z + j1 + 1, block, 0, 4);
            world.setBlock(x + i1 + 1, y, z + j1 + 1, block, 0, 4);
        }
        else
        {
            world.setBlock(x, y, z, block, 0, 4);
        }

        if (!((WorldGenerator)object).generate(world, random, x + i1, y, z + j1))
        {
            if (flag)
            {
                world.setBlock(x + i1, y, z + j1, this, l, 4);
                world.setBlock(x + i1 + 1, y, z + j1, this, l, 4);
                world.setBlock(x + i1, y, z + j1 + 1, this, l, 4);
                world.setBlock(x + i1 + 1, y, z + j1 + 1, this, l, 4);
            }
            else
            {
                world.setBlock(x, y, z, this, l, 4);
            }
        }
    }

//isSameSapling
    public boolean func_149880_a(World world, int x, int y, int z, int par1)
    {
        return world.getBlock(x, y, z) == this && (world.getBlockMetadata(x, y, z) & 7) == par1;
    }

    /**
     * Determines the damage on the item the block drops. Used in cloth and wood.
     */
    public int damageDropped(int par1)
    {
        return MathHelper.clamp_int(par1 & 7, 0, 5);
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    @Override
    public void getSubBlocks(Item item, CreativeTabs tabs, List list)
    {
    	for(int i = 0; i < saplings.length; i++){
		list.add(new ItemStack(item, 1, i));
	}
    }

    //RegisterIcons
    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister iconRegister)
    {
        for (int i = 0; i < saplingicon.length; ++i)
        {
        	saplingicon[i] = iconRegister.registerIcon("Abrynos:Sapling" + saplings[i]);
        }
    }


    public boolean func_149851_a(World world, int x, int y, int z, boolean par1)
    {
        return true;
    }

    public boolean func_149852_a(World world, Random random, int x, int y, int z)
    {
        return (double)world.rand.nextFloat() < 0.45D;
    }

    public void func_149853_b(World world, Random random, int x, int y, int z)
    {
        this.func_149879_c(world, x, y, z, random);
    }
}

 

My ItemSapling class:

public class ItemSaplingBlocks extends ItemBlock {
public static final String[] saplings = new String[] {"Whitecherry", "Pinkcherry"};

public ItemSaplingBlocks(Block block){
	super(block);
	this.setHasSubtypes(true);
}

public String getUnlocalizedName(ItemStack itemStack) {
	int i = itemStack.getItemDamage();
	if(i < 0 || i >= saplings.length){
		i = 0;
	}
	return super.getUnlocalizedName() + "." + saplings[i];
}

public int getMetadata(int meta){
	return meta;
}
}

 

The AbrWorldGenTrees.class needed for the sapling:

public class AbrWorldGenTrees extends WorldGenAbstractTree
{
    private final int minTreeHeight;
    private final int randomTreeHeight;
    
    private final boolean vinesGrow;
    
    private final Block wood;
    private final Block leaves;
    
    private final int metaWood;
    private final int metaLeaves;

    public AbrWorldGenTrees(Block wood, Block leaves, int metaWood, int metaLeaves)
    {
        this(wood, leaves, metaWood, metaLeaves, false, 4, 3, false);
    }

    public AbrWorldGenTrees(Block wood, Block leaves, int metaWood, int metaLeaves, boolean doBlockNotify, int minTreeHeight, int randomTreeHeight, boolean vinesGrow)
    {
        super(doBlockNotify);
        
        this.wood = wood;
        this.leaves = leaves;
        
        this.minTreeHeight = minTreeHeight;
        this.randomTreeHeight = randomTreeHeight;
        
        this.metaWood = metaWood;
        this.metaLeaves = metaLeaves;
        this.vinesGrow = vinesGrow;
    }

    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    {
        int l = par2Random.nextInt(3) + this.minTreeHeight;
        boolean flag = true;

        if (par4 >= 1 && par4 + l + 1 <= 256)
        {
            byte b0;
            int k1;
            Block block;

            for (int i1 = par4; i1 <= par4 + 1 + l; ++i1)
            {
                b0 = 1;

                if (i1 == par4)
                {
                    b0 = 0;
                }

                if (i1 >= par4 + 1 + l - 2)
                {
                    b0 = 2;
                }

                for (int j1 = par3 - b0; j1 <= par3 + b0 && flag; ++j1)
                {
                    for (k1 = par5 - b0; k1 <= par5 + b0 && flag; ++k1)
                    {
                        if (i1 >= 0 && i1 < 256)
                        {
                            block = par1World.getBlock(j1, i1, k1);

                            if (!this.isReplaceable(par1World, j1, i1, k1))
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
            }

            if (!flag)
            {
                return false;
            }
            else
            {
                Block block2 = par1World.getBlock(par3, par4 - 1, par5);

                boolean isSoil = block2.canSustainPlant(par1World, par3, par4 - 1, par5, ForgeDirection.UP, (BlockSapling)TreeRegistry.blockSapling);
                if (isSoil && par4 < 256 - l - 1)
                {
                    block2.onPlantGrow(par1World, par3, par4 - 1, par5, par3, par4, par5);
                    b0 = 3;
                    byte b1 = 0;
                    int l1;
                    int i2;
                    int j2;
                    int i3;

                    for (k1 = par4 - b0 + l; k1 <= par4 + l; ++k1)
                    {
                        i3 = k1 - (par4 + l);
                        l1 = b1 + 1 - i3 / 2;

                        for (i2 = par3 - l1; i2 <= par3 + l1; ++i2)
                        {
                            j2 = i2 - par3;

                            for (int k2 = par5 - l1; k2 <= par5 + l1; ++k2)
                            {
                                int l2 = k2 - par5;

                                if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || par2Random.nextInt(2) != 0 && i3 != 0)
                                {
                                    Block block1 = par1World.getBlock(i2, k1, k2);

                                    if (block1.isAir(par1World, i2, k1, k2) || block1.isLeaves(par1World, i2, k1, k2))
                                    {
                                        this.setBlockAndNotifyAdequately(par1World, i2, k1, k2, TreeRegistry.blockLeaf, this.metaLeaves);
                                    }
                                }
                            }
                        }
                    }

                    for (k1 = 0; k1 < l; ++k1)
                    {
                        block = par1World.getBlock(par3, par4 + k1, par5);

                        if (block.isAir(par1World, par3, par4 + k1, par5) || block.isLeaves(par1World, par3, par4 + k1, par5))
                        {
                            this.setBlockAndNotifyAdequately(par1World, par3, par4 + k1, par5, TreeRegistry.blockLog, this.metaWood);

                            if (this.vinesGrow && k1 > 0)
                            {
                                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 - 1, par4 + k1, par5))
                                {
                                    this.setBlockAndNotifyAdequately(par1World, par3 - 1, par4 + k1, par5, Blocks.vine, ;
                                }

                                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 + 1, par4 + k1, par5))
                                {
                                    this.setBlockAndNotifyAdequately(par1World, par3 + 1, par4 + k1, par5, Blocks.vine, 2);
                                }

                                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3, par4 + k1, par5 - 1))
                                {
                                    this.setBlockAndNotifyAdequately(par1World, par3, par4 + k1, par5 - 1, Blocks.vine, 1);
                                }

                                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3, par4 + k1, par5 + 1))
                                {
                                    this.setBlockAndNotifyAdequately(par1World, par3, par4 + k1, par5 + 1, Blocks.vine, 4);
                                }
                            }
                        }
                    }

                    if (this.vinesGrow)
                    {
                        for (k1 = par4 - 3 + l; k1 <= par4 + l; ++k1)
                        {
                            i3 = k1 - (par4 + l);
                            l1 = 2 - i3 / 2;

                            for (i2 = par3 - l1; i2 <= par3 + l1; ++i2)
                            {
                                for (j2 = par5 - l1; j2 <= par5 + l1; ++j2)
                                {
                                    if (par1World.getBlock(i2, k1, j2).isLeaves(par1World, i2, k1, j2))
                                    {
                                        if (par2Random.nextInt(4) == 0 && par1World.getBlock(i2 - 1, k1, j2).isAir(par1World, i2 - 1, k1, j2))
                                        {
                                            this.growVines(par1World, i2 - 1, k1, j2, ;
                                        }

                                        if (par2Random.nextInt(4) == 0 && par1World.getBlock(i2 + 1, k1, j2).isAir(par1World, i2 + 1, k1, j2))
                                        {
                                            this.growVines(par1World, i2 + 1, k1, j2, 2);
                                        }

                                        if (par2Random.nextInt(4) == 0 && par1World.getBlock(i2, k1, j2 - 1).isAir(par1World, i2, k1, j2 - 1))
                                        {
                                            this.growVines(par1World, i2, k1, j2 - 1, 1);
                                        }

                                        if (par2Random.nextInt(4) == 0 && par1World.getBlock(i2, k1, j2 + 1).isAir(par1World, i2, k1, j2 + 1))
                                        {
                                            this.growVines(par1World, i2, k1, j2 + 1, 4);
                                        }
                                    }
                                }
                            }
                        }

                        if (par2Random.nextInt(5) == 0 && l > 5)
                        {
                            for (k1 = 0; k1 < 2; ++k1)
                            {
                                for (i3 = 0; i3 < 4; ++i3)
                                {
                                    if (par2Random.nextInt(4 - k1) == 0)
                                    {
                                        l1 = par2Random.nextInt(3);
                                        this.setBlockAndNotifyAdequately(par1World, par3 + Direction.offsetX[Direction.rotateOpposite[i3]], par4 + l - 5 + k1, par5 + Direction.offsetZ[Direction.rotateOpposite[i3]], Blocks.cocoa, l1 << 2 | i3);
                                    }
                                }
                            }
                        }
                    }

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        else
        {
            return false;
        }
    }

    /**
     * Grows vines downward from the given block for a given length. Args: World, x, starty, z, vine-length
     */
    private void growVines(World par1World, int par2, int par3, int par4, int par5)
    {
        this.setBlockAndNotifyAdequately(par1World, par2, par3, par4, Blocks.vine, par5);
        int i1 = 4;

        while (true)
        {
            --par3;

            if (par1World.getBlock(par2, par3, par4).isAir(par1World, par2, par3, par4) || i1 <= 0)
            {
                return;
            }

            this.setBlockAndNotifyAdequately(par1World, par2, par3, par4, Blocks.vine, par5);
            --i1;
        }
    }
}

 

All registered with:

public static Block blockLog;
public static Block blockLeaf;
public static Block blockSapling;

                blockLog = new AbrBlockLog().setBlockName("Log").setCreativeTab(CreativeTabRegistry.Abrynosplants);
	GameRegistry.registerBlock(blockLog, ItemLogBlocks.class, blockLog.getUnlocalizedName().substring(5));
	blockLeaf = new BlockLeaf().setBlockName("Leaf").setCreativeTab(CreativeTabRegistry.Abrynosplants);
	GameRegistry.registerBlock(blockLeaf, ItemLeafBlocks.class, blockLeaf.getUnlocalizedName().substring(5));
	blockSapling = new AbrBlockSapling().setBlockName("Sapling").setCreativeTab(CreativeTabRegistry.Abrynosplants);
	GameRegistry.registerBlock(blockSapling, ItemSaplingBlocks.class, blockSapling.getUnlocalizedName().substring(5));

 

My Custom Biome:

public class BiomeGenCherryWood extends BiomeGenBase {
public BiomeGenCherryWood(int id){
	super(id);
	Object object;
	this.temperature = 0.5F;
	this.enableRain = true;
	this.topBlock = Blocks.grass;
	this.fillerBlock = Blocks.dirt;
}
}

registered with

public static BiomeGenBase cherryWood;

@EventHandler
public void preInit(FLMPreInitializationEvent event){
     cherryWood = new BiomeGenCherryWood(16).setBiomeName("CherryWoods");
     BiomeDictionary.registerBiomeType(cherryWood, Type.FOREST);
     BiomeManager.addSpawnBiome(cherryWood);

 

Now my question is how to bring in my trees into the CherryWoods.

 

Thanks in advance!

 

 

BTW: I've got 2 other problems:  :-\

1. The saplings got the same texture in the inventory, but when they are planted they got different ones like I want them to have.

2. The leaves drop a cherry sapling, but when I try to plant this one minecraft crashes and the world cannot be loaded again.

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.