Jump to content

Recommended Posts

Posted

The problem (as seen in the image below) is that on grow my custom tree the bottom block, where previously was the sapling, has a chance (i think), of appear rotated.

 

width=800 height=413https://dl.dropboxusercontent.com/u/184200482/img/tree_grow_bug.png[/img]

 

BlockSapling.java

package com.sackcastellon.treeoflife.block;

import java.util.Random;

import com.sackcastellon.treeoflife.TreeOfLife;
import com.sackcastellon.treeoflife.world.gen.WorldGenTree;

import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.IGrowable;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockSapling extends BlockBush implements IGrowable
{
    public static final String[] field_149882_a = new String[] {"life"};
    private static final IIcon[] IconArray = new IIcon[field_149882_a.length];
    
    public BlockSapling()
    {
        float f = 0.4F;
        
        this.setBlockName("tol_sapling");
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
        this.setCreativeTab(TreeOfLife.tabTol);
    }

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

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

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

    public void markOrGrowMarked(World world, int x, int y, int z, Random rand)
    {
        int l = world.getBlockMetadata(x, y, z);

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

    public void growTree(World world, int x, int y, int z, Random rand)
    {
        if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(world, rand, x, y, z)) return;
        int l = world.getBlockMetadata(x, y, z) & 7;
        Object object = new WorldGenTree(true);
        int i1 = 0;
        int j1 = 0;
        boolean flag = false;

        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, rand, 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);
            }
        }
    }

    public boolean isSameSapling(World p_149880_1_, int p_149880_2_, int p_149880_3_, int p_149880_4_, int p_149880_5_)
    {
        return p_149880_1_.getBlock(p_149880_2_, p_149880_3_, p_149880_4_) == this && (p_149880_1_.getBlockMetadata(p_149880_2_, p_149880_3_, p_149880_4_) & 7) == p_149880_5_;
    }

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

    @Override
    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister iconRegister)
    {
        IconArray[0] = iconRegister.registerIcon("treeoflife:sapling");
    }

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

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

    @Override
    public void func_149853_b(World world, Random rand, int x, int y, int z)
    {
        this.markOrGrowMarked(world, x, y, z, rand);
    }
}

 

WorldGenTree.java

package com.sackcastellon.treeoflife.world.gen;

import java.util.Random;

import com.sackcastellon.treeoflife.api.Blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSapling;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
import net.minecraftforge.common.util.ForgeDirection;

public class WorldGenTree extends WorldGenAbstractTree
{
    public WorldGenTree(boolean par1)
    {
        super(par1);
    }
    
@Override
public boolean generate(World world, Random rand, int x, int y, int z)
{
	for (int i = 0; i < 3; ++i)
	{
		this.setBlockAndNotifyAdequately(world, x, y + i, z, Blocks.ToLLog, 0);
	}
	return true;
}
}

 

Thanks for helping  :)

Posted

When I did my copy/paste mod, I had some blocks where they cared how they were placed and it changed the orientation such as droppers/hoppers.  I had to come back 1 tick later and set their meta data or they wouldn't obey the orientation I desired.

 

I just looked at the blockwood class and I do not see any evidence of that issue here.  It has to be how you are placing the block.

 

 

Is there any difference when the tree grows from worldgen versus you grow the block with the bonemeal in your hand?

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

When I did my copy/paste mod, I had some blocks where they cared how they were placed and it changed the orientation such as droppers/hoppers.  I had to come back 1 tick later and set their meta data or they wouldn't obey the orientation I desired.

 

I just looked at the blockwood class and I do not see any evidence of that issue here.  It has to be how you are placing the block.

 

 

Is there any difference when the tree grows from worldgen versus you grow the block with the bonemeal in your hand?

 

Yes, the trees from worldgen has no rotated logs (at least the ones i saw) and the treen grew by bonemeal, have a chance of generate with the bottom log rotated.

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.