Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello.

I started to make a plant which works like Reed. Everything works fine, except that i cannot place the block on itself like reed.

 

public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    {
        Block block = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
        return (block != null && block.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
    }

 

I think this is the problem. But when I add || blockID == myblock.blockID, then i can also place it on sand or when i place them on itself more times

and break the first block, the other blocks doesn't drop as a item.

 

I hope someone can help me.

Haven't really looked into reeds, but I think you should be looking at this method instead.

 

block.canSustainPlant

Kain

  • Author

I also looked at it. I copied the method and added this to it:

if(plantid == myblocks.bcorn.blockID && blockID == myblocks.bcorn.blockID) {
return true;
}

 

Now the problem is, that i can place my block everywhere. I defindet the EnumPlantType as Corn, but can place it also on sand or grass.

 

So the code looks like this. I'll remove unused things later.

 

    public boolean canSustainPlant2(World world, int x, int y, int z, ForgeDirection direction, IPlantable plant)
    {
        int plantID = plant.getPlantID(world, x, y + 1, z);
        EnumPlantType plantType = plant.getPlantType(world, x, y + 1, z);

        if (plantID == myblocks.bcorn.blockID && blockID == myblocks.bcorn.blockID)
        {
            return true;
        }

        if (plant instanceof BlockFlower && canThisPlantGrowOnThisBlockID2(blockID))
        {
            return true;
        }

        switch (plantType)
        {
            case Desert: return blockID == sand.blockID;
            case Nether: return blockID == slowSand.blockID;
            case Crop:   return blockID == tilledField.blockID;
            case Cave:   return isBlockSolidOnSide(world, x, y, z, UP);
            case Plains: return blockID == grass.blockID || blockID == dirt.blockID;
            case Water:  return world.getBlockMaterial(x, y, z) == Material.water && world.getBlockMetadata(x, y, z) == 0;
            case Beach:
                boolean isBeach = (blockID == Block.grass.blockID || blockID == Block.dirt.blockID || blockID == Block.sand.blockID);
                boolean hasWater = (world.getBlockMaterial(x - 1, y, z    ) == Material.water ||
                                    world.getBlockMaterial(x + 1, y, z    ) == Material.water ||
                                    world.getBlockMaterial(x,     y, z - 1) == Material.water ||
                                    world.getBlockMaterial(x,     y, z + 1) == Material.water);
                return isBeach && hasWater;
        }

        return false;
    }
    
    protected boolean canThisPlantGrowOnThisBlockID2(int par1)
    {
        return par1 == Block.grass.blockID || par1 == Block.dirt.blockID || par1 == Block.tilledField.blockID;
    }

The only step you needed was extends BlockFlower and override canThisPlantGrowOnThisBlockID(int).

  • Author

Thank you. Now, I'm extending BlockFlower. But what do you mean with override canThisPlantGrowOnThisBlockID(int).

Well...return true when the given block id (the method only argument) is a good block to plant on, return false otherwise ?

Isn't that already explained in the method javadoc ?

  • Author

I added this, but i still can place the block everywhere.

 

@Override
    protected boolean canThisPlantGrowOnThisBlockID(int par1)
    {
        if(par1 == Block.tilledField.blockID || par1 == myblocks.BCorn.blockID) return true;
        
        return false;
    }

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.