Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package busti2000.technica.entity;
- import busti2000.technica.api.PipeAPI;
- import busti2000.technica.tileentity.TileEntitySoulContainer;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.client.renderer.entity.Render;
- import net.minecraft.client.renderer.entity.RenderEntity;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.item.EntityXPOrb;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.world.World;
- public class PipeXPOrb extends Entity {
- /**
- * A constantly increasing value that RenderXPOrb uses to control the color shifting (Green / yellow)
- */
- public int xpColor;
- /** This is how much XP this orb has. */
- private int xpValue;
- private double tx;
- private double ty;
- private double tz;
- public boolean hasReachedTarget;
- private double speed = Math.random() * (0.3 - 0.1) + 0.1;
- public PipeXPOrb(World par1World, double par2, double par4, double par6, int par8, double tx, double ty, double tz) {
- super(par1World);
- this.setSize(0.5F, 0.5F);
- this.setPosition(par2, par4, par6);
- this.rotationYaw = (float)(Math.random() * 360.0D);
- this.xpValue = par8;
- this.tx = tx;
- this.ty = ty;
- this.tz = tz;
- this.hasReachedTarget = false;
- this.noClip = true;
- }
- /**
- * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
- * prevent them from trampling crops
- */
- protected boolean canTriggerWalking() {
- return false;
- }
- public PipeXPOrb(World par1World) {
- super(par1World);
- this.setSize(0.5F, 0.5F);
- this.noClip = true;
- this.hasReachedTarget = false;
- }
- protected void entityInit() {}
- @SideOnly(Side.CLIENT)
- public int getBrightnessForRender(float par1)
- {
- float f1 = 0.5F;
- if (f1 < 0.0F)
- {
- f1 = 0.0F;
- }
- if (f1 > 1.0F)
- {
- f1 = 1.0F;
- }
- int i = super.getBrightnessForRender(par1);
- int j = i & 255;
- int k = i >> 16 & 255;
- j += (int)(f1 * 15.0F * 16.0F);
- if (j > 240)
- {
- j = 240;
- }
- return j | k << 16;
- }
- public void onUpdate() {
- super.onUpdate();
- if (!this.hasReachedTarget) {
- double d0 = 8.0D;
- double d1 = (this.tx - this.posX) / d0;
- double d2 = (this.ty - this.posY) / d0;
- double d3 = (this.tz - this.posZ) / d0;
- double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
- double d5 = 1.0D - d4;
- double d11 = (this.tx - this.posX);
- double d12 = (this.ty - this.posY);
- double d13 = (this.tz - this.posZ);
- double d14 = Math.sqrt(d11 * d11 + d12 * d12 + d13 * d13);
- if (d5 > 0.0D)
- {
- d5 *= d5;
- this.motionX = d1 / d4 * d5 * this.speed;
- this.motionY = d2 / d4 * d5 * this.speed;
- this.motionZ = d3 / d4 * d5 * this.speed;
- }
- if (d14 < 0.15D) {
- this.hasReachedTarget = true;
- this.motionX = 0;
- this.motionY = 0;
- this.motionZ = 0;
- }
- }
- //System.out.println(PipeAPI.getSuperContainer(this.worldObj.getBlockTileEntity((int) this.posX, (int) this.posY, (int)(this.posZ - 0.5))));
- this.moveEntity(this.motionX, this.motionY, this.motionZ);
- this.xpColor++;
- }
- /**
- * Returns the XP value of this XP orb.
- */
- public int getXpValue()
- {
- return this.xpValue;
- }
- @SideOnly(Side.CLIENT)
- /**
- * Returns a number from 1 to 10 based on how much XP this orb is worth. This is used by RenderXPOrb to determine
- * what texture to use.
- */
- public int getTextureByXP()
- {
- 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)))))))));
- }
- /**
- * If returns false, the item will not inflict any damage against entities.
- */
- public boolean canAttackWithItem()
- {
- return false;
- }
- /**
- * Sets the Target of the Orb
- */
- public void setTarget(double tx, double ty, double tz) {
- this.tx = tx;
- this.ty = ty;
- this.tz = tz;
- this.hasReachedTarget = false;
- }
- /**
- * (abstract) Protected helper method to read subclass entity data from NBT.
- */
- protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
- this.xpValue = nbttagcompound.getShort("Value");
- this.tx = nbttagcompound.getDouble("tx");
- this.ty = nbttagcompound.getDouble("ty");
- this.tz = nbttagcompound.getDouble("tz");
- this.setDead();
- }
- /**
- * (abstract) Protected helper method to write subclass entity data to NBT.
- */
- protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
- nbttagcompound.setShort("Value", (short)this.xpValue);
- nbttagcompound.setDouble("tx", this.tx);
- nbttagcompound.setDouble("ty", this.ty);
- nbttagcompound.setDouble("tz", this.tz);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment