Guest User

Untitled

a guest
Aug 15th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.58 KB | None | 0 0
  1. package net.secknv.nkmod.item;
  2.  
  3. import javax.annotation.Nullable;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.EntityLivingBase;
  8. import net.minecraft.entity.item.EntityItemFrame;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.item.IItemPropertyGetter;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.tileentity.TileEntity;
  13. import net.minecraft.util.math.BlockPos;
  14. import net.minecraft.util.math.MathHelper;
  15. import net.minecraft.world.World;
  16. import net.minecraftforge.fml.relauncher.Side;
  17. import net.minecraftforge.fml.relauncher.SideOnly;
  18. import net.secknv.nkmod.tileentity.TileEntityCoil;
  19.  
  20. public class NkCompass implements IItemPropertyGetter{
  21.  
  22.  
  23.     @SideOnly(Side.CLIENT)
  24.     double rotation;
  25.     @SideOnly(Side.CLIENT)
  26.     double rota;
  27.     @SideOnly(Side.CLIENT)
  28.     long lastUpdateTick;
  29.     @SideOnly(Side.CLIENT)
  30.     public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
  31.     {
  32.         if (entityIn == null && !stack.isOnItemFrame())
  33.         {
  34.             return 0.0F;
  35.         }
  36.         else
  37.         {
  38.             boolean flag = entityIn != null;
  39.             Entity entity = (Entity)(flag ? entityIn : stack.getItemFrame());
  40.  
  41.             if (worldIn == null)
  42.             {
  43.                 worldIn = entity.worldObj;
  44.             }
  45.  
  46.             double d0;
  47.  
  48.             if (worldIn.provider.isSurfaceWorld())
  49.             {
  50.                 double d1 = flag ? (double)entity.rotationYaw : this.getFrameRotation((EntityItemFrame)entity);
  51.                 d1 = d1 % 360.0D;
  52.                 double d2 = this.getSpawnToAngle(worldIn, entity);
  53.                 d0 = Math.PI - ((d1 - 90.0D) * 0.01745329238474369D - d2);
  54.             }
  55.             else
  56.             {
  57.                 d0 = Math.random() * (Math.PI * 2D);
  58.             }
  59.  
  60.             if (flag)
  61.             {
  62.                 d0 = this.wobble(worldIn, d0);
  63.             }
  64.  
  65.             float f = (float)(d0 / (Math.PI * 2D));
  66.             return MathHelper.positiveModulo(f, 1.0F);
  67.         }
  68.     }
  69.     @SideOnly(Side.CLIENT)
  70.     private double wobble(World p_185093_1_, double p_185093_2_)
  71.     {
  72.         if (p_185093_1_.getTotalWorldTime() != this.lastUpdateTick)
  73.         {
  74.             this.lastUpdateTick = p_185093_1_.getTotalWorldTime();
  75.             double d0 = p_185093_2_ - this.rotation;
  76.             d0 = d0 % (Math.PI * 2D);
  77.             d0 = MathHelper.clamp_double(d0, -1.0D, 1.0D);
  78.             this.rota += d0 * 0.1D;
  79.             this.rota *= 0.8D;
  80.             this.rotation += this.rota;
  81.         }
  82.  
  83.         return this.rotation;
  84.     }
  85.     @SideOnly(Side.CLIENT)
  86.     private double getFrameRotation(EntityItemFrame p_185094_1_)
  87.     {
  88.         return (double)MathHelper.clampAngle(180 + p_185094_1_.facingDirection.getHorizontalIndex() * 90);
  89.     }
  90.     @SideOnly(Side.CLIENT)
  91.     private double getSpawnToAngle(World worldIn, Entity ent)
  92.     {
  93.        
  94.         BlockPos blockpos = worldIn.getSpawnPoint();
  95.        
  96.         for(BlockPos pos:BlockPos.getAllInBox(ent.getPosition().add(-3.0D, -3.0D, -3.0D), ent.getPosition().add(3.0D, 3.0D, 3.0D))){
  97.             TileEntity nearbyTE = worldIn.getTileEntity(pos);
  98.            
  99.             if(nearbyTE instanceof TileEntityCoil){
  100.                 TileEntityCoil nearbyCoil = (TileEntityCoil) nearbyTE;
  101.                 if(nearbyCoil.messUpCompass){
  102.                     blockpos = nearbyCoil.getCoilPosition();
  103.                     System.out.println("compass triggered");
  104.                 }
  105.             }
  106.         }
  107.        
  108.         return Math.atan2((double)blockpos.getZ() - ent.posZ, (double)blockpos.getX() - ent.posX);
  109.     }
  110. }
Add Comment
Please, Sign In to add comment