Guest User

BlockSapphireCrop

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