2018-10-21 12:51:13 +02:00
|
|
|
package de.ellpeck.naturesaura.aura.container;
|
2018-10-20 21:19:08 +02:00
|
|
|
|
2018-11-07 23:42:13 +01:00
|
|
|
import de.ellpeck.naturesaura.aura.AuraType;
|
2018-10-20 21:19:08 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
|
|
|
public class ItemAuraContainer implements IAuraContainer {
|
|
|
|
|
|
|
|
protected final ItemStack stack;
|
2018-11-07 23:42:13 +01:00
|
|
|
protected final AuraType type;
|
2018-10-20 21:19:08 +02:00
|
|
|
protected final int maxAura;
|
|
|
|
|
2018-11-07 23:42:13 +01:00
|
|
|
public ItemAuraContainer(ItemStack stack, AuraType type, int maxAura) {
|
2018-10-20 21:19:08 +02:00
|
|
|
this.stack = stack;
|
2018-11-07 23:42:13 +01:00
|
|
|
this.type = type;
|
2018-10-20 21:19:08 +02:00
|
|
|
this.maxAura = maxAura;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int storeAura(int amountToStore, boolean simulate) {
|
|
|
|
int aura = this.getStoredAura();
|
|
|
|
int actual = Math.min(amountToStore, this.getMaxAura() - aura);
|
|
|
|
if (!simulate) {
|
|
|
|
this.setAura(aura + actual);
|
|
|
|
}
|
|
|
|
return actual;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int drainAura(int amountToDrain, boolean simulate) {
|
|
|
|
int aura = this.getStoredAura();
|
|
|
|
int actual = Math.min(amountToDrain, aura);
|
|
|
|
if (!simulate) {
|
|
|
|
this.setAura(aura - actual);
|
|
|
|
}
|
|
|
|
return actual;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setAura(int amount) {
|
|
|
|
if (!this.stack.hasTagCompound()) {
|
|
|
|
this.stack.setTagCompound(new NBTTagCompound());
|
|
|
|
}
|
|
|
|
this.stack.getTagCompound().setInteger("aura", amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getStoredAura() {
|
|
|
|
if (this.stack.hasTagCompound()) {
|
|
|
|
return this.stack.getTagCompound().getInteger("aura");
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxAura() {
|
|
|
|
return this.maxAura;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getAuraColor() {
|
|
|
|
return 0x42a6bc;
|
|
|
|
}
|
2018-11-07 23:42:13 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isAcceptableType(AuraType type) {
|
|
|
|
return this.type == null || this.type == type;
|
|
|
|
}
|
2018-10-20 21:19:08 +02:00
|
|
|
}
|