package me.hammerle.supersnuvi.entity.components;

import me.hammerle.supersnuvi.entity.Entity;

public class DefaultEnergy extends Energy
{
    private final double maxEnergy;
    private double energy;
    
    public DefaultEnergy(Entity ent, double maxEnergy) 
    {
        super(ent);
        this.maxEnergy = maxEnergy;
        this.energy = maxEnergy;
    }

    @Override
    public void tick() 
    {
        if(!ent.isMoving())
        {
            addEnergy(0.1);
        }
    }

    @Override
    public double getMaxEnergy() 
    {
        return maxEnergy;
    }

    @Override
    public double getEnergy() 
    {
        return energy;
    }

    @Override
    public void addEnergy(double h) 
    {
        energy += h;
        if(energy > maxEnergy)
        {
            energy = maxEnergy;
        }
        else if(energy < 0.0)
        {
            energy = 0.0;
        }
    }
}
