Advertisement
Abob78

TronBikeBlue.Java

Aug 21st, 2014
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.92 KB | None | 0 0
  1. package com.musicdude509.TronMod.TronBike;
  2.  
  3. import java.util.List;
  4. import com.musicdude509.TronMod.TronBike.entity.EntityTronBikeBlue;
  5. import cpw.mods.fml.common.registry.GameRegistry;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.util.AxisAlignedBB;
  15. import net.minecraft.util.MathHelper;
  16. import net.minecraft.util.MovingObjectPosition;
  17. import net.minecraft.util.Vec3;
  18. import net.minecraft.world.World;
  19.  
  20. public class TronBikeBlue extends Item{
  21.  
  22.     public static final Item tronBikeBlue = (Item)Item.itemRegistry.getObject("tronBikeBlue");
  23.     public static final Item tronBikeOrange = (Item)Item.itemRegistry.getObject("tronBikeOrange");
  24.    
  25.     public TronBikeBlue(){
  26.         this.maxStackSize = 1;
  27.         this.setCreativeTab(CreativeTabs.tabTransport);
  28.         this.setTextureName("TronBikeBlue");
  29.         this.setUnlocalizedName("tronBikeBlue");
  30.  
  31.     }
  32.     public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) {
  33.         float f = 1.0F;
  34.         float f1 = p_77659_3_.prevRotationPitch + (p_77659_3_.rotationPitch - p_77659_3_.prevRotationPitch) * f;
  35.         float f2 = p_77659_3_.prevRotationYaw + (p_77659_3_.rotationYaw - p_77659_3_.prevRotationYaw) * f;
  36.         double d0 = p_77659_3_.prevPosX + (p_77659_3_.posX - p_77659_3_.prevPosX) * (double)f;
  37.         double d1 = p_77659_3_.prevPosY + (p_77659_3_.posY - p_77659_3_.prevPosY) * (double)f + 1.62D - (double)p_77659_3_.yOffset;
  38.         double d2 = p_77659_3_.prevPosZ + (p_77659_3_.posZ - p_77659_3_.prevPosZ) * (double)f;
  39.         Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
  40.         float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
  41.         float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
  42.         float f5 = -MathHelper.cos(-f1 * 0.017453292F);
  43.         float f6 = MathHelper.sin(-f1 * 0.017453292F);
  44.         float f7 = f4 * f5;
  45.         float f8 = f3 * f5;
  46.         double d3 = 5.0D;
  47.         Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
  48.         MovingObjectPosition movingobjectposition = p_77659_2_.rayTraceBlocks(vec3, vec31, true);
  49.  
  50.         if (movingobjectposition == null)
  51.         {
  52.             return p_77659_1_;
  53.         }
  54.         else
  55.         {
  56.             Vec3 vec32 = p_77659_3_.getLook(f);
  57.             boolean flag = false;
  58.             float f9 = 1.0F;
  59.             List list = p_77659_2_.getEntitiesWithinAABBExcludingEntity(p_77659_3_, p_77659_3_.boundingBox.addCoord(vec32.xCoord * d3, vec32.yCoord * d3, vec32.zCoord * d3).expand((double)f9, (double)f9, (double)f9));
  60.             int i;
  61.  
  62.             for (i = 0; i < list.size(); ++i)
  63.             {
  64.                 Entity entity = (Entity)list.get(i);
  65.  
  66.                 if (entity.canBeCollidedWith())
  67.                 {
  68.                     float f10 = entity.getCollisionBorderSize();
  69.                     AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double)f10, (double)f10, (double)f10);
  70.  
  71.                     if (axisalignedbb.isVecInside(vec3))
  72.                     {
  73.                         flag = true;
  74.                     }
  75.                 }
  76.             }
  77.  
  78.             if (flag)
  79.             {
  80.                 return p_77659_1_;
  81.             }
  82.             else
  83.             {
  84.                 if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
  85.                 {
  86.                     i = movingobjectposition.blockX;
  87.                     int j = movingobjectposition.blockY;
  88.                     int k = movingobjectposition.blockZ;
  89.  
  90.                     if (p_77659_2_.getBlock(i, j, k) == Blocks.snow_layer)
  91.                     {
  92.                         --j;
  93.                     }
  94.  
  95.                     EntityTronBikeBlue entitytronbikeblue = new EntityTronBikeBlue(p_77659_2_, (double)((float)i + 0.5F), (double)((float)j + 1.0F), (double)((float)k + 0.5F));
  96.                     entitytronbikeblue.rotationYaw = (float)(((MathHelper.floor_double((double)(p_77659_3_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) - 1) * 90);
  97.  
  98.                     if (!p_77659_2_.getCollidingBoundingBoxes(entitytronbikeblue, entitytronbikeblue.boundingBox.expand(-0.1D, -0.1D, -0.1D)).isEmpty())
  99.                     {
  100.                         return p_77659_1_;
  101.                     }
  102.  
  103.                     if (!p_77659_2_.isRemote)
  104.                     {
  105.                         p_77659_2_.spawnEntityInWorld(entitytronbikeblue);
  106.                     }
  107.  
  108.                     if (!p_77659_3_.capabilities.isCreativeMode)
  109.                     {
  110.                         --p_77659_1_.stackSize;
  111.                     }
  112.                 }
  113.  
  114.                 return p_77659_1_;
  115.     }
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement