Jump to content

Recommended Posts

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.

Posted

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;
    }

Posted

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 ?

Posted

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

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