Posted October 27, 201311 yr 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.
October 27, 201311 yr Haven't really looked into reeds, but I think you should be looking at this method instead. block.canSustainPlant Kain
October 27, 201311 yr 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; }
October 27, 201311 yr The only step you needed was extends BlockFlower and override canThisPlantGrowOnThisBlockID(int).
October 27, 201311 yr Author Thank you. Now, I'm extending BlockFlower. But what do you mean with override canThisPlantGrowOnThisBlockID(int).
October 27, 201311 yr 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 ?
October 29, 201311 yr 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.