Jump to content

Custom sapling not growing on custom dirt and a quick question about dimensions.


Recommended Posts

Posted

 

This is most likely pretty simple.

I have been trying to get my custom sapling to grow on my custom dirt block but I can't seem to find anything that I could edit to allow that to happen. I can place the sapling on my dirt just fine (but it will not grow), it also will grow just fine if placed on normal dirt or grass

and will grow just fine. Below is my code for my sapling and block bush (they are most likely pretty bad as this is my first time using forge/minecraft again in a few years).

 

BlockAmboynaSap

package epicarno.mystical.common.block;
import java.util.List;
import java.util.Random;








import net.minecraft.block.Block;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.IGrowable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenBigTree;
import net.minecraft.world.gen.feature.WorldGenCanopyTree;
import net.minecraft.world.gen.feature.WorldGenForest;
import net.minecraft.world.gen.feature.WorldGenMegaJungle;
import net.minecraft.world.gen.feature.WorldGenMegaPineTree;
import net.minecraft.world.gen.feature.WorldGenSavannaTree;
import net.minecraft.world.gen.feature.WorldGenTaiga2;
import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import epicarno.mystical.common.di.GenAmboynaTree;


public class BlockAmboynaSap  extends BlockEpicarnoBush implements IGrowable
{

private final String name = "AmboynaSap";
public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockPlanks.EnumType.class);
    public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 1);
  

    public BlockAmboynaSap()
    {
        this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, BlockPlanks.EnumType.OAK).withProperty(STAGE, Integer.valueOf(0)));
        float f = 0.4F;
    	GameRegistry.registerBlock(this, name);
    	setUnlocalizedName(name);
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
        this.setCreativeTab(CreativeTabs.tabDecorations);
    }
    


    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (!worldIn.isRemote)
        {
            super.updateTick(worldIn, pos, state, rand);
            this.generateTree(worldIn, pos, state, rand);

            if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0)
            {
                this.grow(worldIn, pos, state, rand);
            }
        }
    }

    public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (((Integer)state.getValue(STAGE)).intValue() == 0)
        {
            worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4);
        }
        else
        {
            this.generateTree(worldIn, pos, state, rand);
        }
    }

    public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        Object object = rand.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
        int i = 0;
        int j = 0;
        boolean flag = false;
        
        j = 0;
        i = 0;
        object = new GenAmboynaTree(true);


        IBlockState iblockstate1 = Blocks.air.getDefaultState();

        if (flag)
        {
            worldIn.setBlockState(pos.add(i, 0, j), iblockstate1, 4);
            worldIn.setBlockState(pos.add(i + 1, 0, j), iblockstate1, 4);
            worldIn.setBlockState(pos.add(i, 0, j + 1), iblockstate1, 4);
            worldIn.setBlockState(pos.add(i + 1, 0, j + 1), iblockstate1, 4);
        }
        else
        {
            worldIn.setBlockState(pos, iblockstate1, 4);
        }

        if (!((WorldGenerator)object).generate(worldIn, rand, pos.add(i, 0, j)))
        {
            if (flag)
            {
                worldIn.setBlockState(pos.add(i, 0, j), state, 4);
                worldIn.setBlockState(pos.add(i + 1, 0, j), state, 4);
                worldIn.setBlockState(pos.add(i, 0, j + 1), state, 4);
                worldIn.setBlockState(pos.add(i + 1, 0, j + 1), state, 4);
            }
            else
            {
                worldIn.setBlockState(pos, state, 4);
            }
        }
    }

    public boolean isTypeAt(World worldIn, BlockPos pos, BlockPlanks.EnumType type)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        return iblockstate.getBlock() == this && iblockstate.getValue(TYPE) == type;
    }

    public int damageDropped(IBlockState state)
    {
        return ((BlockPlanks.EnumType)state.getValue(TYPE)).getMetadata();
    }

    public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
    {
        return true;
    }

    public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
    {
        return (double)worldIn.rand.nextFloat() < 0.45D;
    }

    public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
    {
        this.grow(worldIn, pos, state, rand);
    }

    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(TYPE, BlockPlanks.EnumType.byMetadata(meta & 7)).withProperty(STAGE, Integer.valueOf((meta &  >> 3));
    }

    public int getMetaFromState(IBlockState state)
    {
        byte b0 = 0;
        int i = b0 | ((BlockPlanks.EnumType)state.getValue(TYPE)).getMetadata();
        i |= ((Integer)state.getValue(STAGE)).intValue() << 3;
        return i;
    }

    protected BlockState createBlockState()
    {
        return new BlockState(this, new IProperty[] {TYPE, STAGE});
    }

public String getName() {
	return name;
}

}

 

Bush

package epicarno.mystical.common.block;

import java.util.Random;

import epicarno.mystical.common.mystical_epicarno_mod;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockEpicarnoBush extends BlockBush implements net.minecraftforge.common.IPlantable
{

    protected BlockEpicarnoBush(Material materialIn)
    {
        super(materialIn);
        this.setTickRandomly(true);
        float f = 0.2F;
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 3.0F, 0.5F + f);
        this.setCreativeTab(CreativeTabs.tabDecorations);
    }

    protected BlockEpicarnoBush()
    {
        this(Material.plants);
    }

    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        return super.canPlaceBlockAt(worldIn, pos) && worldIn.getBlockState(pos.down()).getBlock().canSustainPlant(worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
    }

    @Override
    protected boolean canPlaceBlockOn(Block ground)
    {
        return ground == mystical_epicarno_mod.EpicarnoGrass || ground == mystical_epicarno_mod.EpicarnoDirt;
    }

    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
    {
        super.onNeighborBlockChange(worldIn, pos, state, neighborBlock);
        this.checkAndDropBlock(worldIn, pos, state);
    }

    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        this.checkAndDropBlock(worldIn, pos, state);
    }

    protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
    {
        if (!this.canBlockStay(worldIn, pos, state))
        {
            this.dropBlockAsItem(worldIn, pos, state, 0);
            worldIn.setBlockState(pos, Blocks.air.getDefaultState(), 3);
        }
    }

    public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
    {
        return this.canPlaceBlockOn(worldIn.getBlockState(pos.down()).getBlock());
    }

    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
    {
        return null;
    }
    
    @Override
    public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos)
    {

        return net.minecraftforge.common.EnumPlantType.Plains;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean isFullCube()
    {
        return false;
    }

    @SideOnly(Side.CLIENT)
    public EnumWorldBlockLayer getBlockLayer()
    {
        return EnumWorldBlockLayer.CUTOUT;
    }



    @Override
    public IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos)
    {
        IBlockState state = world.getBlockState(pos);
        if (state.getBlock() != this) return getDefaultState();
        return state;
    }


}

 

Also how different is making a custom dimension in 1.8 to 1.7 as there does not seem to be any information on dimensions for 1.8 as far as I have looked.

 

Thanks.

 

 

 

Posted

Hmm... Do you have a SaplingGrowEvent? I think that's what it's called. Correct me if I'm wrong.

Posted

Where would that be? I see a file (one of the default minecraft ones) called SaplingGrowTreeEvent but I don't know if that would be the problem since the sapling does grow on normal dirt, it just does not grow on my mods dirt.

Posted

Where would that be? I see a file (one of the default minecraft ones) called SaplingGrowTreeEvent but I don't know if that would be the problem since the sapling does grow on normal dirt, it just does not grow on my mods dirt.

 

Oh, ok. If that isn't the problem then maybe you could try a Bonemeal Event? I can't remember what the exact name for the class, but it's something like BonemealEvent. Anyway, you could perform a check for whether the sapling is on custom dirt, if it is, grow the tree. Hope this helps. :)

Posted

I don't know if it is a problem with the sapling/Bush block it's self. After messing around a little and seeing if the generateTree fuction was being called, I found it was being called when on custom dirt the tree just was not generating.  So I think it may (not sure) be something with my tree gen, that right now is just ripped from the minecraft files for testing the sapling.

 

package epicarno.mystical.common.di;

import java.util.Random;

import epicarno.mystical.common.mystical_epicarno_mod;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;

public class GenAmboynaTree extends WorldGenAbstractTree
{
    private static final String __OBFID = "CL_00000430";

    public GenAmboynaTree(boolean p_i45461_1_)
    {
        super(p_i45461_1_);
    }

    public boolean generate(World worldIn, Random p_180709_2_, BlockPos p_180709_3_)
    {
        int i = p_180709_2_.nextInt(3) + p_180709_2_.nextInt(2) + 6;
        boolean flag = true;

        if (p_180709_3_.getY() >= 1 && p_180709_3_.getY() + i + 1 <= 256)
        {
            int k;
            int l;

            for (int j = p_180709_3_.getY(); j <= p_180709_3_.getY() + 1 + i; ++j)
            {
                byte b0 = 1;

                if (j == p_180709_3_.getY())
                {
                    b0 = 0;
                }

                if (j >= p_180709_3_.getY() + 1 + i - 2)
                {
                    b0 = 2;
                }

                for (k = p_180709_3_.getX() - b0; k <= p_180709_3_.getX() + b0 && flag; ++k)
                {
                    for (l = p_180709_3_.getZ() - b0; l <= p_180709_3_.getZ() + b0 && flag; ++l)
                    {
                        if (j >= 0 && j < 256)
                        {
                            if (!this.isReplaceable(worldIn, new BlockPos(k, j, l)))
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
            }

            if (!flag)
            {
                return false;
            }
            else
            {
                BlockPos down = p_180709_3_.down();
                net.minecraft.block.state.IBlockState state = worldIn.getBlockState(down);
                boolean isSoil = state.getBlock().canSustainPlant(worldIn, down, net.minecraft.util.EnumFacing.UP, ((net.minecraft.block.BlockSapling)Blocks.sapling));

                if (isSoil && p_180709_3_.getY() < 256 - i - 1)
                {
                    this.onPlantGrow(worldIn, p_180709_3_.down(), p_180709_3_);
                    this.onPlantGrow(worldIn, p_180709_3_.add(1, -1, 0), p_180709_3_);
                    this.onPlantGrow(worldIn, p_180709_3_.add(1, -1, 1), p_180709_3_);
                    this.onPlantGrow(worldIn, p_180709_3_.add(0, -1, 1), p_180709_3_);
                    EnumFacing enumfacing = EnumFacing.Plane.HORIZONTAL.random(p_180709_2_);
                    k = i - p_180709_2_.nextInt(4);
                    l = 2 - p_180709_2_.nextInt(3);
                    int i1 = p_180709_3_.getX();
                    int j1 = p_180709_3_.getZ();
                    int k1 = 0;
                    int l1;
                    int i2;

                    for (l1 = 0; l1 < i; ++l1)
                    {
                        i2 = p_180709_3_.getY() + l1;

                        if (l1 >= k && l > 0)
                        {
                            i1 += enumfacing.getFrontOffsetX();
                            j1 += enumfacing.getFrontOffsetZ();
                            --l;
                        }

                        BlockPos blockpos1 = new BlockPos(i1, i2, j1);
                        state = worldIn.getBlockState(blockpos1);

                        if (state.getBlock().isAir(worldIn, blockpos1) || state.getBlock().isLeaves(worldIn, blockpos1))
                        {
                            this.func_175905_a(worldIn, blockpos1, mystical_epicarno_mod.AmboynaLog, BlockPlanks.EnumType.DARK_OAK.getMetadata() - 4);
                            this.func_175905_a(worldIn, blockpos1.east(), mystical_epicarno_mod.AmboynaLog, BlockPlanks.EnumType.DARK_OAK.getMetadata() - 4);
                            this.func_175905_a(worldIn, blockpos1.south(), mystical_epicarno_mod.AmboynaLog, BlockPlanks.EnumType.DARK_OAK.getMetadata() - 4);
                            this.func_175905_a(worldIn, blockpos1.east().south(), mystical_epicarno_mod.AmboynaLog, BlockPlanks.EnumType.DARK_OAK.getMetadata() - 4);
                            k1 = i2;
                        }
                    }

                    for (l1 = -2; l1 <= 0; ++l1)
                    {
                        for (i2 = -2; i2 <= 0; ++i2)
                        {
                            byte b1 = -1;
                            this.func_150526_a(worldIn, i1 + l1, k1 + b1, j1 + i2);
                            this.func_150526_a(worldIn, 1 + i1 - l1, k1 + b1, j1 + i2);
                            this.func_150526_a(worldIn, i1 + l1, k1 + b1, 1 + j1 - i2);
                            this.func_150526_a(worldIn, 1 + i1 - l1, k1 + b1, 1 + j1 - i2);

                            if ((l1 > -2 || i2 > -1) && (l1 != -1 || i2 != -2))
                            {
                                byte b2 = 1;
                                this.func_150526_a(worldIn, i1 + l1, k1 + b2, j1 + i2);
                                this.func_150526_a(worldIn, 1 + i1 - l1, k1 + b2, j1 + i2);
                                this.func_150526_a(worldIn, i1 + l1, k1 + b2, 1 + j1 - i2);
                                this.func_150526_a(worldIn, 1 + i1 - l1, k1 + b2, 1 + j1 - i2);
                            }
                        }
                    }

                    if (p_180709_2_.nextBoolean())
                    {
                        this.func_150526_a(worldIn, i1, k1 + 2, j1);
                        this.func_150526_a(worldIn, i1 + 1, k1 + 2, j1);
                        this.func_150526_a(worldIn, i1 + 1, k1 + 2, j1 + 1);
                        this.func_150526_a(worldIn, i1, k1 + 2, j1 + 1);
                    }

                    for (l1 = -3; l1 <= 4; ++l1)
                    {
                        for (i2 = -3; i2 <= 4; ++i2)
                        {
                            if ((l1 != -3 || i2 != -3) && (l1 != -3 || i2 != 4) && (l1 != 4 || i2 != -3) && (l1 != 4 || i2 != 4) && (Math.abs(l1) < 3 || Math.abs(i2) < 3))
                            {
                                this.func_150526_a(worldIn, i1 + l1, k1, j1 + i2);
                            }
                        }
                    }

                    for (l1 = -1; l1 <= 2; ++l1)
                    {
                        for (i2 = -1; i2 <= 2; ++i2)
                        {
                            if ((l1 < 0 || l1 > 1 || i2 < 0 || i2 > 1) && p_180709_2_.nextInt(3) <= 0)
                            {
                                int k2 = p_180709_2_.nextInt(3) + 2;
                                int l2;

                                for (l2 = 0; l2 < k2; ++l2)
                                {
                                    this.func_175905_a(worldIn, new BlockPos(p_180709_3_.getX() + l1, k1 - l2 - 1, p_180709_3_.getZ() + i2), mystical_epicarno_mod.AmboynaLog, BlockPlanks.EnumType.DARK_OAK.getMetadata() - 4);
                                }

                                int j2;

                                for (l2 = -1; l2 <= 1; ++l2)
                                {
                                    for (j2 = -1; j2 <= 1; ++j2)
                                    {
                                        this.func_150526_a(worldIn, i1 + l1 + l2, k1 - 0, j1 + i2 + j2);
                                    }
                                }

                                for (l2 = -2; l2 <= 2; ++l2)
                                {
                                    for (j2 = -2; j2 <= 2; ++j2)
                                    {
                                        if (Math.abs(l2) != 2 || Math.abs(j2) != 2)
                                        {
                                            this.func_150526_a(worldIn, i1 + l1 + l2, k1 - 1, j1 + i2 + j2);
                                        }
                                    }
                                }
                            }
                        }
                    }

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

    private void func_150526_a(World worldIn, int p_150526_2_, int p_150526_3_, int p_150526_4_)
    {
        BlockPos pos = new BlockPos(p_150526_2_, p_150526_3_, p_150526_4_);
        net.minecraft.block.state.IBlockState state = worldIn.getBlockState(pos);

        if (state.getBlock().isAir(worldIn, pos))
        {
            this.func_175905_a(worldIn, new BlockPos(p_150526_2_, p_150526_3_, p_150526_4_), mystical_epicarno_mod.AmboynaLeave, 1);
        }
    }

    //Just a helper macro
    private void onPlantGrow(World world, BlockPos pos, BlockPos source)
    {
        world.getBlockState(pos).getBlock().onPlantGrow(world, pos, source);
    }
}

Posted

I think it might be a check in WorldGenAbstractTree.

But it still does not work on custom dirt  :-\

 

Edit: This is the problem line

 

boolean isSoil = state.getBlock().canSustainPlant(worldIn, down, net.minecraft.util.EnumFacing.UP, ((net.minecraft.block.BlockSapling)Blocks.sapling));

Posted

Just wait until diesben07 gets back on (I don't think I spelled his name right. Did I?) he'll be able to help you better than I can. I'm stumped. :)

Posted

Oh, your quite welcome, I'm really helpful on this forum when I'm bored. lol :)

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.