package common.entity.item;

import common.entity.Entity;
import common.entity.EntityType;
import common.model.ParticleType;
import common.tags.TagObject;
import common.world.World;

public class EntityNuke extends Entity
{
    public int fuse;

    public EntityNuke(World worldIn)
    {
        super(worldIn);
        this.preventSpawning = true;
        this.setSize(0.98F, 0.98F);
    }

    public EntityNuke(World worldIn, double x, double y, double z)
    {
        this(worldIn);
        this.setPosition(x, y, z);
        float f = (float)(Math.random() * Math.PI * 2.0D);
        this.motionX = (double)(-((float)Math.sin((double)f)) * 0.005F);
        this.motionY = 0.1D;
        this.motionZ = (double)(-((float)Math.cos((double)f)) * 0.005F);
        this.fuse = 300;
        this.prevX = x;
        this.prevY = y;
        this.prevZ = z;
    }

    protected void entityInit()
    {
    }
    
    protected boolean canTriggerWalking()
    {
        return false;
    }
    
    public boolean canBeCollidedWith()
    {
        return !this.dead;
    }
    
    public void onUpdate()
    {
        this.prevX = this.posX;
        this.prevY = this.posY;
        this.prevZ = this.posZ;
        this.motionY -= 0.03999999910593033D;
        if(this.fuse <= 0) {
        	this.motionX = this.motionY = this.motionZ = 0.0D;
        }
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.9800000190734863D;
        this.motionY *= 0.9800000190734863D;
        this.motionZ *= 0.9800000190734863D;

        if (this.onGround)
        {
            this.motionX *= 0.699999988079071D;
            this.motionZ *= 0.699999988079071D;
            this.motionY *= -0.5D;
        }

        if(this.fuse-- <= 0)
        {
//        	if(this.fuse < -70) {
        		this.setDead();
        		if(!this.worldObj.client)
        			this.worldObj.newExplosion(this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, 70);
//        	}
//        	else if(!this.worldObj.client) {
//        		this.setInvisible(true);
//                this.explode(this.fuse + 1);
//            }
        }
        else
        {
            this.handleWaterMovement();
//            if(!this.isInvisible()) {
            this.worldObj.spawnParticle(ParticleType.FLAME, this.posX, this.posY + 1.1D, this.posZ, 0.0D, 0.0D, 0.0D);
//            }
        }
    }

//    private void explode(int fuse)
//    {
//    		double min = ((double)((int)((fuse+1) / 1))) * -1.0d;
//			Explosion.doExplosionAlgo3(this.worldObj, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, this.rand, min + 6.0d, min);
//    }
    
    protected void writeEntity(TagObject tagCompound)
    {
        tagCompound.setInt("Fuse", this.fuse);
    }
    
    protected void readEntity(TagObject tagCompund)
    {
        this.fuse = tagCompund.getInt("Fuse");
    }

    public float getEyeHeight()
    {
        return 0.0F;
    }
    
    public int getTrackingRange() {
    	return 200;
    }
    
    public int getUpdateFrequency() {
    	return 10;
    }
    
    public boolean isSendingVeloUpdates() {
    	return true;
    }
    
    public EntityType getType() {
    	return EntityType.EXPLOSIVE;
    }
}
