Posted April 10, 201411 yr I'm not sure if it's a problem with minecraft saplings coding (I can't find anything in the sapling that specifies where it can be placed and grow on), or if it's a problem with my grass coding, but I can't seem to place normal saplings on my custom grass. My grass is designed so that it doesn't need the color coding (not sure if that's part of the problem?) because I wanted it similar to Mycelium in that it can be picked up from one biome and moved to another. Anyone think they can help? I'm not getting any errors or anything, it just won't let me put the sapling down. package craftygirls.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class CGGrass extends Block { @SideOnly(Side.CLIENT) private IIcon IconGrassTop; @SideOnly(Side.CLIENT) private IIcon IconGrassSideSnowed; public CGGrass() { super(Material.grass); this.setTickRandomly(true); } /** * Gets the block's texture. Args: side, meta */ @SideOnly(Side.CLIENT) public IIcon getIcon(int par1, int par2) { return par1 == 1 ? this.IconGrassTop : (par1 == 0 ? Blocks.dirt.getBlockTextureFromSide(par1) : this.blockIcon); } /** * Ticks the block if it's been scheduled */ public void updateTick(World par1, int par2, int par3, int par4, Random par5) { if (!par1.isRemote) { if (par1.getBlockLightValue(par2, par3 + 1, par4) < 4 && par1.getBlockLightOpacity(par2, par3 + 1, par4) > 2) { par1.setBlock(par2, par3, par4, Blocks.dirt); } else if (par1.getBlockLightValue(par2, par3 + 1, par4) >= 9) { for (int l = 0; l < 4; ++l) { int i1 = par2 + par5.nextInt(3) - 1; int j1 = par3 + par5.nextInt(5) - 3; int k1 = par4 + par5.nextInt(3) - 1; Block block = par1.getBlock(i1, j1 + 1, k1); if (par1.getBlock(i1, j1, k1) == Blocks.dirt && par1.getBlockMetadata(i1, j1, k1) == 0 && par1.getBlockLightValue(i1, j1 + 1, k1) >= 4 && par1.getBlockLightOpacity(i1, j1 + 1, k1) <= 2) { par1.setBlock(i1, j1, k1, this); } } } } } public Item getItemDropped(int par1, Random par2, int par3) { return Blocks.dirt.getItemDropped(0, par2, par3); } @SideOnly(Side.CLIENT) public IIcon getIcon(IBlockAccess par1, int par2, int par3, int par4, int par5) { if (par5 == 1) { return this.IconGrassTop; } else if (par5 == 0) { return Blocks.dirt.getBlockTextureFromSide(par5); } else { Material material = par1.getBlock(par2, par3 + 1, par4).getMaterial(); return material != Material.snow && material != Material.craftedSnow ? this.blockIcon : this.IconGrassSideSnowed; } } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister par1) { this.blockIcon = par1.registerIcon(this.getTextureName() + "_side"); this.IconGrassTop = par1.registerIcon(this.getTextureName() + "_top"); this.IconGrassSideSnowed = par1.registerIcon("grass_side_snowed"); } /** * A randomly called display update to be able to add particles or other items for display */ @SideOnly(Side.CLIENT) public void randomDisplayTick(World par1, int par2, int par3, int par4, Random par5) { super.randomDisplayTick(par1, par2, par3, par4, par5); if (par5.nextInt(10) == 0) { par1.spawnParticle("townaura", (double)((float)par2 + par5.nextFloat()), (double)((float)par3 + 1.1F), (double)((float)par4 + par5.nextFloat()), 0.0D, 0.0D, 0.0D); } } }
April 10, 201411 yr Actually there is: BlockSapling extends BlockFlower, which checks for the correct soil within the canBlockStay method. There's a piece where it checks if the block below can sustain the plant by calling canSustainPlant on the soil block. To make it easier: override canSustainPlant and return true in your block class Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
April 10, 201411 yr Couldn't he also acheive this by just extending a soil block similar to what he made instead of just Block? Long time Bukkit & Forge Programmer Happy to try and help
April 10, 201411 yr Couldn't he also acheive this by just extending a soil block similar to what he made instead of just Block? No, because neither soil block which already exists are overriding the method, which is called by the BlockFlower under the canBlockStay method. Also the pre-existing canSustainPlant method within the Block class only checksfor certain blocks (like grass, sand, tilledField, soulSand, etc.) or a BlockFlower which returns true within its canThisPlantGrowOnThisBlockID method. Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
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.