001 package net.minecraft.block; 002 003 import java.util.Random; 004 import net.minecraft.block.material.Material; 005 import net.minecraft.creativetab.CreativeTabs; 006 import net.minecraft.util.AxisAlignedBB; 007 import net.minecraft.world.World; 008 009 import net.minecraftforge.common.EnumPlantType; 010 import net.minecraftforge.common.ForgeDirection; 011 import net.minecraftforge.common.IPlantable; 012 import static net.minecraftforge.common.EnumPlantType.*; 013 014 public class BlockFlower extends Block implements IPlantable 015 { 016 protected BlockFlower(int par1, int par2, Material par3Material) 017 { 018 super(par1, par3Material); 019 this.blockIndexInTexture = par2; 020 this.setTickRandomly(true); 021 float var4 = 0.2F; 022 this.setBlockBounds(0.5F - var4, 0.0F, 0.5F - var4, 0.5F + var4, var4 * 3.0F, 0.5F + var4); 023 this.setCreativeTab(CreativeTabs.tabDecorations); 024 } 025 026 protected BlockFlower(int par1, int par2) 027 { 028 this(par1, par2, Material.plants); 029 } 030 031 /** 032 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 033 */ 034 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 035 { 036 return super.canPlaceBlockAt(par1World, par2, par3, par4) && canBlockStay(par1World, par2, par3, par4); 037 } 038 039 /** 040 * Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of 041 * blockID passed in. Args: blockID 042 */ 043 protected boolean canThisPlantGrowOnThisBlockID(int par1) 044 { 045 return par1 == Block.grass.blockID || par1 == Block.dirt.blockID || par1 == Block.tilledField.blockID; 046 } 047 048 /** 049 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 050 * their own) Args: x, y, z, neighbor blockID 051 */ 052 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 053 { 054 super.onNeighborBlockChange(par1World, par2, par3, par4, par5); 055 this.checkFlowerChange(par1World, par2, par3, par4); 056 } 057 058 /** 059 * Ticks the block if it's been scheduled 060 */ 061 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 062 { 063 this.checkFlowerChange(par1World, par2, par3, par4); 064 } 065 066 protected final void checkFlowerChange(World par1World, int par2, int par3, int par4) 067 { 068 if (!this.canBlockStay(par1World, par2, par3, par4)) 069 { 070 this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0); 071 par1World.setBlockWithNotify(par2, par3, par4, 0); 072 } 073 } 074 075 /** 076 * Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants. 077 */ 078 public boolean canBlockStay(World par1World, int par2, int par3, int par4) 079 { 080 Block soil = blocksList[par1World.getBlockId(par2, par3 - 1, par4)]; 081 return (par1World.getFullBlockLightValue(par2, par3, par4) >= 8 || par1World.canBlockSeeTheSky(par2, par3, par4)) && 082 (soil != null && soil.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this)); 083 } 084 085 /** 086 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been 087 * cleared to be reused) 088 */ 089 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 090 { 091 return null; 092 } 093 094 /** 095 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 096 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 097 */ 098 public boolean isOpaqueCube() 099 { 100 return false; 101 } 102 103 /** 104 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 105 */ 106 public boolean renderAsNormalBlock() 107 { 108 return false; 109 } 110 111 /** 112 * The type of render function that is called for this block 113 */ 114 public int getRenderType() 115 { 116 return 1; 117 } 118 119 @Override 120 public EnumPlantType getPlantType(World world, int x, int y, int z) 121 { 122 if (blockID == crops.blockID ) return Crop; 123 if (blockID == deadBush.blockID ) return Desert; 124 if (blockID == waterlily.blockID ) return Water; 125 if (blockID == mushroomRed.blockID ) return Cave; 126 if (blockID == mushroomBrown.blockID) return Cave; 127 if (blockID == netherStalk.blockID ) return Nether; 128 if (blockID == sapling.blockID ) return Plains; 129 if (blockID == melonStem.blockID ) return Crop; 130 if (blockID == pumpkinStem.blockID ) return Crop; 131 if (blockID == tallGrass.blockID ) return Plains; 132 return Plains; 133 } 134 135 @Override 136 public int getPlantID(World world, int x, int y, int z) 137 { 138 return blockID; 139 } 140 141 @Override 142 public int getPlantMetadata(World world, int x, int y, int z) 143 { 144 return world.getBlockMetadata(x, y, z); 145 } 146 }