spenk

BlockSeed

Aug 22nd, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.75 KB | None | 0 0
  1. package net.bplaced.spenk.drugmod.Blocks;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.Random;
  8.  
  9. import net.bplaced.spenk.drugmod.DrugsMod;
  10. import net.minecraft.block.Block;
  11. import net.minecraft.block.BlockCrops;
  12. import net.minecraft.block.BlockFlower;
  13. import net.minecraft.client.renderer.texture.IconRegister;
  14. import net.minecraft.creativetab.CreativeTabs;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.util.AxisAlignedBB;
  18. import net.minecraft.util.Icon;
  19. import net.minecraft.util.MathHelper;
  20. import net.minecraft.world.IBlockAccess;
  21. import net.minecraft.world.World;
  22.  
  23. import net.minecraftforge.common.ForgeDirection;
  24.  
  25. public class BlockPotCanabis extends BlockCrops
  26. {
  27.    
  28.     @SideOnly(Side.CLIENT)
  29.     private Icon[] iconArray;
  30.  
  31.     public BlockPotCanabis(int par1)
  32.     {
  33.         super(par1);
  34.         this.setTickRandomly(true);
  35.         float f = 0.125F;
  36.         this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
  37.         this.setCreativeTab(null);
  38.     }
  39.    
  40.     @Override
  41.     public AxisAlignedBB getCollisionBoundingBoxFromPool (World world, int x, int y, int z) {
  42.         return null;
  43.     }
  44.  
  45.     @Override
  46.     public boolean isOpaqueCube () {
  47.         return false;
  48.     }
  49.  
  50.     protected boolean canThisPlantGrowOnThisBlockID(int par1)
  51.     {
  52.         return par1 == DrugsMod.blockSeedpot.blockID;
  53.     }
  54.  
  55.     public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
  56.     {
  57.         super.updateTick(par1World, par2, par3, par4, par5Random);
  58.         System.out.println("===============SCHEDULED===============");
  59.         if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 12)
  60.         {
  61.             float f = this.getGrowthModifier(par1World, par2, par3, par4);
  62.  
  63.             if (par5Random.nextInt((int)(25.0F / f) + 1) == 0)
  64.             {
  65.                 int l = par1World.getBlockMetadata(par2, par3, par4);
  66.  
  67.                 if (l < 3)//TODO
  68.                 {
  69.                     ++l;
  70.                     par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
  71.                 }
  72.             }
  73.         }
  74.     }
  75.  
  76.     private float getGrowthModifier(World par1World, int par2, int par3, int par4)
  77.     {
  78.         float f = 1.0F;
  79.         int l = par1World.getBlockId(par2, par3, par4 - 1);
  80.         int i1 = par1World.getBlockId(par2, par3, par4 + 1);
  81.         int j1 = par1World.getBlockId(par2 - 1, par3, par4);
  82.         int k1 = par1World.getBlockId(par2 + 1, par3, par4);
  83.         int l1 = par1World.getBlockId(par2 - 1, par3, par4 - 1);
  84.         int i2 = par1World.getBlockId(par2 + 1, par3, par4 - 1);
  85.         int j2 = par1World.getBlockId(par2 + 1, par3, par4 + 1);
  86.         int k2 = par1World.getBlockId(par2 - 1, par3, par4 + 1);
  87.         boolean flag = j1 == this.blockID || k1 == this.blockID;
  88.         boolean flag1 = l == this.blockID || i1 == this.blockID;
  89.         boolean flag2 = l1 == this.blockID || i2 == this.blockID || j2 == this.blockID || k2 == this.blockID;
  90.  
  91.         for (int l2 = par2 - 1; l2 <= par2 + 1; ++l2)
  92.         {
  93.             for (int i3 = par4 - 1; i3 <= par4 + 1; ++i3)
  94.             {
  95.                 int j3 = par1World.getBlockId(l2, par3 - 1, i3);
  96.                 float f1 = 0.0F;
  97.  
  98.                 if (blocksList[j3] != null && blocksList[j3].canSustainPlant(par1World, l2, par3 - 1, i3, ForgeDirection.UP, this))
  99.                 {
  100.                     f1 = 1.0F;
  101.  
  102.                     if (blocksList[j3].isFertile(par1World, l2, par3 - 1, i3))
  103.                     {
  104.                         f1 = 3.0F;
  105.                     }
  106.                 }
  107.  
  108.                 if (l2 != par2 || i3 != par4)
  109.                 {
  110.                     f1 /= 4.0F;
  111.                 }
  112.  
  113.                 f += f1;
  114.             }
  115.         }
  116.  
  117.         if (flag2 || flag && flag1)
  118.         {
  119.             f /= 2.0F;
  120.         }
  121.  
  122.         return f;
  123.     }
  124.  
  125.    /* public void setBlockBoundsForItemRender()
  126.     {
  127.         float f = 0.125F;
  128.         this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
  129.     }
  130.  
  131.     public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
  132.     {
  133.         this.maxY = (double)((float)(par1IBlockAccess.getBlockMetadata(par2, par3, par4) * 2 + 2) / 16.0F);
  134.         float f = 0.125F;
  135.         this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, (float)this.maxY, 0.5F + f);
  136.     }*/
  137.  
  138.     public int getRenderType()
  139.     {
  140.         return 1;
  141.     }
  142.  
  143.     public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
  144.     {
  145.         super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7);
  146.     }
  147.  
  148.     public int idDropped(int par1, Random par2Random, int par3)
  149.     {
  150.         return par3 == 3 ? DrugsMod.itemCanabisPlant.itemID : -1;
  151.     }
  152.  
  153.     public int quantityDropped(Random par1Random)
  154.     {
  155.         return 1;
  156.     }
  157.  
  158.     @SideOnly(Side.CLIENT)
  159.     public int idPicked(World par1World, int par2, int par3, int par4)
  160.     {
  161.         return par1World.getBlockMetadata(par2, par3, par4) == 3 ?  DrugsMod.itemCanabisPlant.itemID : DrugsMod.itemCanabisPlant.itemID;
  162.     }
  163.  
  164.     public Icon getIcon(int par1, int par2)
  165.     {
  166.         if (par2 < 0 || par2 > 3)
  167.         {
  168.             par2 = 3;
  169.         }
  170.         System.out.println(par2);
  171.         return this.iconArray[par2];
  172.     }
  173.  
  174.     @SideOnly(Side.CLIENT)
  175.  
  176.     public void registerIcons(IconRegister par1IconRegister)
  177.     {
  178.         this.iconArray = new Icon[4];
  179.  
  180.         for (int i = 0; i < this.iconArray.length; i++)
  181.         {
  182.             this.iconArray[i] = par1IconRegister.registerIcon("drugmod:canabis" + i);
  183.         }
  184.     }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment