Jump to content

[1.7.2] [SOLVED] Custom Sapling won't grow on custom blocks


Recommended Posts

Posted

I thought I could figure this out by myself or by googling, but I've spent about a day and a half trying to figure this out. So here I go...

 

I've successfully made a custom sapling that grows a custom tree, and also works with vanilla bonemeal. Everything's working perfectly, however, I want this custom sapling to work with my custom dirt and grass just like it does with vanilla dirt and grass. I've tried copying the BlockBush file and modified this line of code.

 

/**
     * is the block grass, dirt or farmland
     */
    protected boolean canPlaceBlockOn(Block p_149854_1_)
    {
        return p_149854_1_ == Blocks.grass || p_149854_1_ == Blocks.dirt || p_149854_1_ == Blocks.farmland || p_149854_1_ == Mod1.NegativeGrass || p_149854_1_ == Mod1.NegativeDirt; 
    }

 

Then I made my custom sapling extend this file, but it still works on vanilla blocks, and not my custom blocks. Do I have to modify the blocks to sustain the custom sapling? Or is there something I have to add to the sapling to be sustained in the custom blocks?

 

Thanks in advance.

I may ask questions asking for help, but I know what I'm doing. If my post is helpful in any way, give a "Thank You" in return, I'd really appreciate it.

Posted

Override the method as in adding @Override to the line of code I showed earlier? Or override as in something else I don't know...?

 

I've added @Override and line of code returns with an error.

 

"The method canPlaceBlockOn(Block) of type ModBush must override or implement a supertype method"

 

And then tells me to remove @Override, is there something I'm doing wrong?

I may ask questions asking for help, but I know what I'm doing. If my post is helpful in any way, give a "Thank You" in return, I'd really appreciate it.

Posted

That message you get (with @Override) tells you exactly what the problem was. When you subclass another class (like Item, Block, etc.) you normally override methods that you need to change. Your method signature (that is name, return type, and types of arguments) does not have a method to override. Check you spelling and if you still can't figure it out, reread the class your subclassing.

 

By the way, if you copy the BlockBush class completely, then you obviously are not overriding the canPlaceBlockOn method; you are defining it. The class you copied works only with vanilla dirt. Of course a copy would do the same. Right?

 

The problem is this code in Block class:

        if (plantable instanceof BlockBush && ((BlockBush)plantable).canPlaceBlockOn(this))
        {
            return true;
        }

 

Since you have copied the class and renamed it, your method will never be called. As was suggested, you need to subclass BlockBush and override necessary methods like the one you changed.

Posted

Okay, so I've kinda fixed it, and now it can be placed on both vanilla dirt and my custom dirt...It just won't grow on the custom dirt.  ???

 

Here's my ModBush class if that helps.

 

public class ModBush extends BlockBush implements IPlantable
{

    protected ModBush(Material p_i45395_1_)
    {
        super(p_i45395_1_);
        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 ModBush()
    {
        this(Material.plants);
    }

    /**
     * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
     */
    public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
    {
        return super.canPlaceBlockAt(p_149742_1_, p_149742_2_, p_149742_3_, p_149742_4_) && this.canBlockStay(p_149742_1_, p_149742_2_, p_149742_3_, p_149742_4_);
    }

    /**
     * is the block grass, dirt or farmland
     */
    @Override
    protected boolean canPlaceBlockOn(Block p_149854_1_)
    {
        return p_149854_1_ == Blocks.grass || p_149854_1_ == Blocks.dirt || p_149854_1_ == Blocks.farmland || p_149854_1_ == Mod1.NegativeGrass || p_149854_1_ == Mod1.NegativeDirt; 
    }

    /**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor Block
     */
    public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
    {
        super.onNeighborBlockChange(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, p_149695_5_);
        this.checkAndDropBlock(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_);
    }

    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)
    {
        this.checkAndDropBlock(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_);
    }

    /**
     * checks if the block can stay, if not drop as item
     */
    protected void checkAndDropBlock(World p_149855_1_, int p_149855_2_, int p_149855_3_, int p_149855_4_)
    {
        if (!this.canBlockStay(p_149855_1_, p_149855_2_, p_149855_3_, p_149855_4_))
        {
            this.dropBlockAsItem(p_149855_1_, p_149855_2_, p_149855_3_, p_149855_4_, p_149855_1_.getBlockMetadata(p_149855_2_, p_149855_3_, p_149855_4_), 0);
            p_149855_1_.setBlock(p_149855_2_, p_149855_3_, p_149855_4_, getBlockById(0), 0, 2);
        }
    }

    /**
     * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
     */
    public boolean canBlockStay(World p_149718_1_, int p_149718_2_, int p_149718_3_, int p_149718_4_)
    {
        return  p_149718_1_.getBlock(p_149718_2_, p_149718_3_ - 1, p_149718_4_).canSustainPlant(p_149718_1_, p_149718_2_, p_149718_3_ - 1, p_149718_4_, ForgeDirection.UP, this);
    }

    /**
     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
     * cleared to be reused)
     */
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
    {
        return null;
    }

    /**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube()
    {
        return false;
    }

    /**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    public boolean renderAsNormalBlock()
    {
        return false;
    }

    /**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return 1;
    }

    @Override
    public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z)
    {
        if (this == Blocks.wheat)          return Crop;
        if (this == Blocks.carrots)        return Crop;
        if (this == Blocks.potatoes)       return Crop;
        if (this == Blocks.melon_stem)     return Crop;
        if (this == Blocks.pumpkin_stem)   return Crop;
        if (this == Blocks.waterlily)      return Water;
        if (this == Blocks.red_mushroom)   return Cave;
        if (this == Blocks.brown_mushroom) return Cave;
        if (this == Blocks.nether_wart)    return Nether;
        if (this == Blocks.sapling)        return Plains;     
        return Plains;
    }

    @Override
    public Block getPlant(IBlockAccess world, int x, int y, int z)
    {
        return this;
    }

    @Override
    public int getPlantMetadata(IBlockAccess world, int x, int y, int z)
    {
        return world.getBlockMetadata(x, y, z);
    }
}

I may ask questions asking for help, but I know what I'm doing. If my post is helpful in any way, give a "Thank You" in return, I'd really appreciate it.

Posted

(Not sure if okay to bump, so I apologize if I've done something wrong by bumping.)

 

I've been screwing around with the code, and still no luck with my custom sapling growing on my custom blocks. I can place them on the custom blocks now, but they won't grow, I've been spamming bonemeal on it every time I make a change. xD

I may ask questions asking for help, but I know what I'm doing. If my post is helpful in any way, give a "Thank You" in return, I'd really appreciate it.

Posted

The Plants normally check and decide it it's time to grow or full-grown in UpdateTick. You did nothing (except for checking to see if the plant can stay), so your plant will not "grow".

 

Check out the BlockSapling class for some ideas.

Posted

So I fixed the problem, except with the fact vanilla saplings also grow on my custom dirt/grass. Though it doesn't really matter much to me. Thanks for helping out. ;D

 

I may ask questions asking for help, but I know what I'm doing. If my post is helpful in any way, give a "Thank You" in return, I'd really appreciate it.

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.