Guest User

PipeXPOrb.java

a guest
Jun 16th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.38 KB | None | 0 0
  1. package busti2000.technica.entity;
  2.  
  3. import busti2000.technica.api.PipeAPI;
  4. import busti2000.technica.tileentity.TileEntitySoulContainer;
  5. import cpw.mods.fml.relauncher.Side;
  6. import cpw.mods.fml.relauncher.SideOnly;
  7. import net.minecraft.client.renderer.entity.Render;
  8. import net.minecraft.client.renderer.entity.RenderEntity;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.item.EntityXPOrb;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.world.World;
  13.  
  14. public class PipeXPOrb extends Entity {
  15.  
  16.     /**
  17.      * A constantly increasing value that RenderXPOrb uses to control the color shifting (Green / yellow)
  18.      */
  19.     public int xpColor;
  20.    
  21.     /** This is how much XP this orb has. */
  22.     private int xpValue;
  23.    
  24.     private double tx;
  25.     private double ty;
  26.     private double tz;
  27.    
  28.     public boolean hasReachedTarget;
  29.    
  30.     private double speed = Math.random() * (0.3 - 0.1) + 0.1;
  31.    
  32.     public PipeXPOrb(World par1World, double par2, double par4, double par6, int par8, double tx, double ty, double tz) {
  33.         super(par1World);
  34.         this.setSize(0.5F, 0.5F);
  35.         this.setPosition(par2, par4, par6);
  36.         this.rotationYaw = (float)(Math.random() * 360.0D);
  37.         this.xpValue = par8;
  38.         this.tx = tx;
  39.         this.ty = ty;
  40.         this.tz = tz;
  41.         this.hasReachedTarget = false;
  42.         this.noClip = true;
  43.         }
  44.    
  45.     /**
  46.      * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
  47.      * prevent them from trampling crops
  48.      */
  49.     protected boolean canTriggerWalking() {
  50.         return false;
  51.     }
  52.    
  53.     public PipeXPOrb(World par1World) {
  54.         super(par1World);
  55.         this.setSize(0.5F, 0.5F);
  56.         this.noClip = true;
  57.         this.hasReachedTarget = false;
  58.     }
  59.    
  60.     protected void entityInit() {}
  61.    
  62.     @SideOnly(Side.CLIENT)
  63.     public int getBrightnessForRender(float par1)
  64.     {
  65.         float f1 = 0.5F;
  66.  
  67.         if (f1 < 0.0F)
  68.         {
  69.             f1 = 0.0F;
  70.         }
  71.  
  72.         if (f1 > 1.0F)
  73.         {
  74.             f1 = 1.0F;
  75.         }
  76.  
  77.         int i = super.getBrightnessForRender(par1);
  78.         int j = i & 255;
  79.         int k = i >> 16 & 255;
  80.         j += (int)(f1 * 15.0F * 16.0F);
  81.  
  82.         if (j > 240)
  83.         {
  84.             j = 240;
  85.         }
  86.  
  87.         return j | k << 16;
  88.     }
  89.    
  90.     public void onUpdate() {
  91.        
  92.         super.onUpdate();
  93.        
  94.         if (!this.hasReachedTarget) {
  95.            
  96.             double d0 = 8.0D;
  97.             double d1 = (this.tx - this.posX) / d0;
  98.             double d2 = (this.ty - this.posY) / d0;
  99.             double d3 = (this.tz - this.posZ) / d0;
  100.             double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
  101.             double d5 = 1.0D - d4;
  102.             double d11 = (this.tx - this.posX);
  103.             double d12 = (this.ty - this.posY);
  104.             double d13 = (this.tz - this.posZ);
  105.             double d14 = Math.sqrt(d11 * d11 + d12 * d12 + d13 * d13);
  106.            
  107.             if (d5 > 0.0D)
  108.             {
  109.                 d5 *= d5;
  110.                 this.motionX = d1 / d4 * d5 * this.speed;
  111.                 this.motionY = d2 / d4 * d5 * this.speed;
  112.                 this.motionZ = d3 / d4 * d5 * this.speed;
  113.             }
  114.             if (d14 < 0.15D)    {
  115.                 this.hasReachedTarget = true;
  116.                 this.motionX = 0;
  117.                 this.motionY = 0;
  118.                 this.motionZ = 0;
  119.             }
  120.            
  121.         }
  122.        
  123.         //System.out.println(PipeAPI.getSuperContainer(this.worldObj.getBlockTileEntity((int) this.posX, (int) this.posY, (int)(this.posZ - 0.5))));
  124.                
  125.         this.moveEntity(this.motionX, this.motionY, this.motionZ);
  126.        
  127.         this.xpColor++;
  128.        
  129.     }
  130.    
  131.     /**
  132.      * Returns the XP value of this XP orb.
  133.      */
  134.     public int getXpValue()
  135.     {
  136.         return this.xpValue;
  137.     }
  138.    
  139.     @SideOnly(Side.CLIENT)
  140.    
  141.     /**
  142.      * Returns a number from 1 to 10 based on how much XP this orb is worth. This is used by RenderXPOrb to determine
  143.      * what texture to use.
  144.      */
  145.     public int getTextureByXP()
  146.     {
  147.         return this.xpValue >= 2477 ? 10 : (this.xpValue >= 1237 ? 9 : (this.xpValue >= 617 ? 8 : (this.xpValue >= 307 ? 7 : (this.xpValue >= 149 ? 6 : (this.xpValue >= 73 ? 5 : (this.xpValue >= 37 ? 4 : (this.xpValue >= 17 ? 3 : (this.xpValue >= 7 ? 2 : (this.xpValue >= 3 ? 1 : 0)))))))));
  148.     }
  149.    
  150.     /**
  151.      * If returns false, the item will not inflict any damage against entities.
  152.      */
  153.     public boolean canAttackWithItem()
  154.     {
  155.         return false;
  156.     }
  157.    
  158.     /**
  159.      * Sets the Target of the Orb
  160.      */
  161.     public void setTarget(double tx, double ty, double tz) {
  162.         this.tx = tx;
  163.         this.ty = ty;
  164.         this.tz = tz;
  165.         this.hasReachedTarget = false;
  166.     }
  167.    
  168.     /**
  169.      * (abstract) Protected helper method to read subclass entity data from NBT.
  170.      */
  171.     protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
  172.         this.xpValue = nbttagcompound.getShort("Value");
  173.         this.tx = nbttagcompound.getDouble("tx");
  174.         this.ty = nbttagcompound.getDouble("ty");
  175.         this.tz = nbttagcompound.getDouble("tz");
  176.         this.setDead();
  177.     }
  178.    
  179.     /**
  180.      * (abstract) Protected helper method to write subclass entity data to NBT.
  181.      */
  182.     protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
  183.         nbttagcompound.setShort("Value", (short)this.xpValue);
  184.         nbttagcompound.setDouble("tx", this.tx);
  185.         nbttagcompound.setDouble("ty", this.ty);
  186.         nbttagcompound.setDouble("tz", this.tz);
  187.     }
  188.    
  189. }
Advertisement
Add Comment
Please, Sign In to add comment