Guest User

BlockSapphireCrop

a guest
Jul 2nd, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.47 KB | None | 0 0
  1. package sometimesHardcoreSometimes;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import cpw.mods.fml.relauncher.Side;
  7. import cpw.mods.fml.relauncher.SideOnly;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.BlockContainer;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.client.renderer.texture.IconRegister;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.item.EntityItem;
  14. import net.minecraft.entity.player.EntityPlayer;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.nbt.NBTTagCompound;
  18. import net.minecraft.tileentity.TileEntity;
  19. import net.minecraft.tileentity.TileEntitySkull;
  20. import net.minecraft.util.Icon;
  21. import net.minecraft.util.MathHelper;
  22. import net.minecraft.world.World;
  23. import net.minecraftforge.common.ForgeDirection;
  24.  
  25. public class BlockSapphireCrop extends BlockContainer
  26. {
  27.     @SideOnly(Side.CLIENT)
  28.     private Icon[] iconArray;
  29.    
  30.     static int bAmt = 14;
  31.    
  32.     public BlockSapphireCrop(int id)
  33.     {
  34.         super(id, Material.cactus);
  35.        
  36.         this.setHardness(3.0F);
  37.         this.setTickRandomly(true);
  38.         this.setUnlocalizedName("sapphireCrop");
  39.         this.setCreativeTab(Base.tabSometimes);
  40.        
  41.         //Block bounds -- What you collide with
  42.         this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
  43.     }
  44.    
  45.     //slows down growth speeds
  46.     public void updateTick(World world, int x, int y, int z, Random rand)
  47.     {
  48.             if(world.getBlockId(x, y - 1, z) != Block.slowSand.blockID)
  49.                 return;
  50.             if(world.getBlockLightValue(x, y + 1, z) < 9)
  51.                 return;
  52.             if(rand.nextInt() % 5 != 0)
  53.                 return;
  54.             if(bAmt < 7)
  55.                 bAmt += 2;
  56.        
  57.         //checks for staff and slows growth speed
  58. //      for(int i = 0; i < 3; i++)
  59. //      {
  60. //          if(world.getBlockId(x + (i + 3), y, z))
  61. //      }
  62.     }
  63.    
  64.     //Called when block is sheared
  65.     public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer player, int par6, float par7, float par8, float par9)
  66.     {
  67.         ItemStack itemStack = player.inventory.getCurrentItem();
  68.        
  69.         if(itemStack.itemID == Base.itemSapphireBerry.itemID)
  70.         {
  71.             if(bAmt < 14)
  72.             {
  73.                 for(int i = 0; i <= 0; i++)
  74.                     bAmt++;
  75.             }
  76.            
  77.             if(!player.capabilities.isCreativeMode)
  78.                 itemStack.stackSize--;
  79.            
  80.             return true;
  81.         }
  82.         else if(itemStack.itemID == Item.shears.itemID && isShearable())
  83.         {  
  84.             ItemStack stack = new ItemStack(Base.itemSapphireBerry);
  85.            
  86.             Random rand = new Random();
  87.             EntityItem item = player.entityDropItem(stack, 1.0F);
  88.             item.motionY += rand.nextFloat() * 0.05F;
  89.             item.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.2F;
  90.             item.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.2F;
  91.            
  92.             if(!player.capabilities.isCreativeMode)
  93.                 itemStack.damageItem(5, player);
  94.            
  95.             bAmt--;
  96.            
  97.             return true;
  98.         }
  99.         else
  100.             return true;
  101.     }
  102.    
  103.     public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
  104.     {
  105.         if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4))
  106.         {
  107.             this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
  108.             par1World.setBlockToAir(par2, par3, par4);
  109.         }
  110.     }
  111.    
  112.     //Given berry amount, checks to see if shear-able
  113.     public boolean isShearable()
  114.     {
  115.         if(bAmt > 0)
  116.             return true;
  117.         else
  118.             return false;
  119.     }
  120.    
  121.     public void onBlockAdded(World par1World, int par2, int par3, int par4)
  122.     {
  123.         super.onBlockAdded(par1World, par2, par3, par4);
  124.         this.setDefaultDirection(par1World, par2, par3, par4);
  125.     }
  126.  
  127.     private void setDefaultDirection(World par1World, int par2, int par3, int par4)
  128.     {
  129.         if (!par1World.isRemote)
  130.         {
  131.             int l = par1World.getBlockId(par2, par3, par4 - 1);
  132.             int i1 = par1World.getBlockId(par2, par3, par4 + 1);
  133.             int j1 = par1World.getBlockId(par2 - 1, par3, par4);
  134.             int k1 = par1World.getBlockId(par2 + 1, par3, par4);
  135.             byte b0 = 3;
  136.  
  137.             if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])
  138.             {
  139.                 b0 = 3;
  140.             }
  141.  
  142.             if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])
  143.             {
  144.                 b0 = 2;
  145.             }
  146.  
  147.             if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])
  148.             {
  149.                 b0 = 5;
  150.             }
  151.  
  152.             if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])
  153.             {
  154.                 b0 = 4;
  155.             }
  156.  
  157.             par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
  158.         }
  159.     }
  160.    
  161.     public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
  162.     {
  163.         int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  164.  
  165.         if (l == 0)
  166.         {
  167.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
  168.         }
  169.  
  170.         if (l == 1)
  171.         {
  172.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
  173.         }
  174.  
  175.         if (l == 2)
  176.         {
  177.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
  178.         }
  179.  
  180.         if (l == 3)
  181.         {
  182.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
  183.         }
  184.     }
  185.    
  186.     @Override
  187.     public TileEntity createNewTileEntity(World world)
  188.     {
  189.         return new TileEntitySapphireCrop();
  190.     }
  191.    
  192.     @Override
  193.     public int getRenderType()
  194.     {
  195.         return -1;
  196.     }
  197.    
  198.     @Override
  199.     public boolean isOpaqueCube()
  200.     {
  201.         return false;
  202.     }
  203.    
  204.     public boolean renderAsNormalBlock()
  205.     {
  206.         return false;
  207.     }
  208.    
  209.     public static int getBerryAmount()
  210.     {
  211.         return bAmt;
  212.     }
  213.    
  214.     @SideOnly(Side.CLIENT)
  215.     public Icon getIcon(int side, int meta)
  216.     {
  217.         if (meta < 0 || meta > 7)
  218.         {
  219.             meta = 7;
  220.         }
  221.  
  222.         return this.iconArray[meta];
  223.     }
  224.    
  225.     public void registerIcons(IconRegister icon)
  226.     {
  227.         this.iconArray = new Icon[8];
  228.  
  229.         for (int i = 0; i < this.iconArray.length; ++i)
  230.         {
  231.             this.iconArray[i] = icon.registerIcon(Base.modid + ":" + (this.getUnlocalizedName().substring(5)) + "_" + i);
  232.         }
  233.     }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment