Guest User

Untitled

a guest
Jan 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.55 KB | None | 0 0
  1. package SweetToothMod;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import net.minecraft.src.Block;
  7. import net.minecraft.src.BlockFlower;
  8. import net.minecraft.src.CreativeTabs;
  9. import net.minecraft.src.Item;
  10. import net.minecraft.src.ItemStack;
  11. import net.minecraft.src.World;
  12. import net.minecraftforge.common.ForgeDirection;
  13. import cpw.mods.fml.common.Side;
  14. import cpw.mods.fml.common.asm.SideOnly;
  15.  
  16. public class BlockPeanutCrop extends BlockFlower
  17. {
  18.     protected BlockPeanutCrop(int par1, int par2)
  19.     {
  20.         super(par1, par2);
  21.         this.blockIndexInTexture = par2;
  22.         this.setTickRandomly(true);
  23.         float var3 = 0.5F;
  24.         this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, 0.25F, 0.5F + var3);
  25.         this.setCreativeTab((CreativeTabs)null);
  26.     }
  27.    
  28.     public String getTextureFile(){
  29.         return "/Crops/SweetToothCrops";
  30.     }
  31.    
  32.     /**
  33.      * Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of
  34.      * blockID passed in. Args: blockID
  35.      */
  36.     protected boolean canThisPlantGrowOnThisBlockID(int par1)
  37.     {
  38.         return par1 == Block.tilledField.blockID;
  39.     }
  40.  
  41.     /**
  42.      * Ticks the block if it's been scheduled
  43.      */
  44.     public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
  45.     {
  46.         super.updateTick(par1World, par2, par3, par4, par5Random);
  47.  
  48.         if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9)
  49.         {
  50.             int var6 = par1World.getBlockMetadata(par2, par3, par4);
  51.  
  52.             if (var6 < 7)
  53.             {
  54.                 float var7 = this.getGrowthRate(par1World, par2, par3, par4);
  55.  
  56.                 if (par5Random.nextInt((int)(25.0F / var7) + 1) == 0)
  57.                 {
  58.                     ++var6;
  59.                     par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
  60.                 }
  61.             }
  62.         }
  63.     }
  64.  
  65.     /**
  66.      * Apply bonemeal to the crops.
  67.      */
  68.     public void fertilize(World par1World, int par2, int par3, int par4)
  69.     {
  70.         par1World.setBlockMetadataWithNotify(par2, par3, par4, 7);
  71.     }
  72.  
  73.     /**
  74.      * Gets the growth rate for the crop. Setup to encourage rows by halving growth rate if there is diagonals, crops on
  75.      * different sides that aren't opposing, and by adding growth for every crop next to this one (and for crop below
  76.      * this one). Args: x, y, z
  77.      */
  78.     private float getGrowthRate(World par1World, int par2, int par3, int par4)
  79.     {
  80.         float var5 = 1.0F;
  81.         int var6 = par1World.getBlockId(par2, par3, par4 - 1);
  82.         int var7 = par1World.getBlockId(par2, par3, par4 + 1);
  83.         int var8 = par1World.getBlockId(par2 - 1, par3, par4);
  84.         int var9 = par1World.getBlockId(par2 + 1, par3, par4);
  85.         int var10 = par1World.getBlockId(par2 - 1, par3, par4 - 1);
  86.         int var11 = par1World.getBlockId(par2 + 1, par3, par4 - 1);
  87.         int var12 = par1World.getBlockId(par2 + 1, par3, par4 + 1);
  88.         int var13 = par1World.getBlockId(par2 - 1, par3, par4 + 1);
  89.         boolean var14 = var8 == this.blockID || var9 == this.blockID;
  90.         boolean var15 = var6 == this.blockID || var7 == this.blockID;
  91.         boolean var16 = var10 == this.blockID || var11 == this.blockID || var12 == this.blockID || var13 == this.blockID;
  92.  
  93.         for (int var17 = par2 - 1; var17 <= par2 + 1; ++var17)
  94.         {
  95.             for (int var18 = par4 - 1; var18 <= par4 + 1; ++var18)
  96.             {
  97.                 int var19 = par1World.getBlockId(var17, par3 - 1, var18);
  98.                 float var20 = 0.0F;
  99.  
  100.                 if (blocksList[var19] != null && blocksList[var19].canSustainPlant(par1World, var17, par3 - 1, var18, ForgeDirection.UP, this))
  101.                 {
  102.                     var20 = 1.0F;
  103.  
  104.                     if (blocksList[var19].isFertile(par1World, var17, par3 - 1, var18))
  105.                     {
  106.                         var20 = 3.0F;
  107.                     }
  108.                 }
  109.  
  110.                 if (var17 != par2 || var18 != par4)
  111.                 {
  112.                     var20 /= 4.0F;
  113.                 }
  114.  
  115.                 var5 += var20;
  116.             }
  117.         }
  118.  
  119.         if (var16 || var14 && var15)
  120.         {
  121.             var5 /= 2.0F;
  122.         }
  123.  
  124.         return var5;
  125.     }
  126.  
  127.     /**
  128.      * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
  129.      */
  130.     public int getBlockTextureFromSideAndMetadata(int par1, int par2)
  131.     {
  132.         if (par2 == 0)
  133.         {
  134.             return CommonProxy.PeanutCrop.blockIndexInTexture;
  135.         }
  136.         if (par2 == 1)
  137.         {
  138.             return CommonProxy.PeanutCrop.blockIndexInTexture + 1;
  139.         }
  140.         if (par2 == 2)
  141.         {
  142.             return CommonProxy.PeanutCrop.blockIndexInTexture + 2;
  143.         }
  144.         if (par2 == 3)
  145.         {
  146.             return CommonProxy.PeanutCrop.blockIndexInTexture +3;
  147.         }
  148.         if (par2 == 4)
  149.         {
  150.             return CommonProxy.PeanutCrop.blockIndexInTexture + 4;
  151.         }
  152.         if (par2 == 5)
  153.         {
  154.             return CommonProxy.PeanutCrop.blockIndexInTexture + 5;
  155.         }
  156.         if (par2 == 6)
  157.         {
  158.             return CommonProxy.PeanutCrop.blockIndexInTexture + 6;
  159.         }
  160.         if (par2 == 7)
  161.         {
  162.             return CommonProxy.PeanutCrop.blockIndexInTexture + 7;
  163.         }
  164.  
  165.         return -1;
  166.     }
  167.  
  168.     /**
  169.      * The type of render function that is called for this block
  170.      */
  171.     public int getRenderType()
  172.     {
  173.         return 6;
  174.     }
  175.  
  176.     /**
  177.      * Drops the block items with a specified chance of dropping the specified items
  178.      */
  179.     public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
  180.     {
  181.         super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0);
  182.     }
  183.  
  184.     /**
  185.      * Returns the ID of the items to drop on destruction.
  186.      */
  187.     public int idDropped(int par1, Random par2Random, int par3)
  188.     {
  189.         return par1 == 7 ? CommonProxy.Peanut.shiftedIndex : -1;
  190.     }
  191.  
  192.     /**
  193.      * Returns the quantity of items to drop on block destruction.
  194.      */
  195.     public int quantityDropped(Random par1Random)
  196.     {
  197.         return 1;
  198.     }
  199.  
  200.     @SideOnly(Side.CLIENT)
  201.  
  202.     /**
  203.      * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
  204.      */
  205.     public int idPicked(World par1World, int par2, int par3, int par4)
  206.     {
  207.         return CommonProxy.PeanutSeeds.shiftedIndex;
  208.     }
  209. }
Add Comment
Please, Sign In to add comment