NaturesAura/src/main/java/de/ellpeck/naturesaura/api/aura/container/BasicAuraContainer.java

63 lines
1.5 KiB
Java
Raw Normal View History

2018-11-11 13:26:19 +01:00
package de.ellpeck.naturesaura.api.aura.container;
2018-10-14 14:27:18 +02:00
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
2021-12-04 15:40:09 +01:00
import net.minecraft.nbt.CompoundTag;
2018-10-14 14:27:18 +02:00
public class BasicAuraContainer implements IAuraContainer {
protected final IAuraType type;
2018-10-14 14:27:18 +02:00
protected final int maxAura;
protected int aura;
public BasicAuraContainer(IAuraType type, int maxAura) {
this.type = type;
2018-10-14 14:27:18 +02:00
this.maxAura = maxAura;
}
@Override
public int storeAura(int amountToStore, boolean simulate) {
2021-12-15 16:30:22 +01:00
var actual = Math.min(amountToStore, this.maxAura - this.aura);
2018-10-14 14:27:18 +02:00
if (!simulate) {
this.aura += actual;
}
return actual;
}
@Override
public int drainAura(int amountToDrain, boolean simulate) {
2021-12-15 16:30:22 +01:00
var actual = Math.min(amountToDrain, this.aura);
2018-10-14 14:27:18 +02:00
if (!simulate) {
this.aura -= actual;
}
return actual;
}
@Override
public int getStoredAura() {
return this.aura;
}
@Override
public int getMaxAura() {
return this.maxAura;
}
@Override
public int getAuraColor() {
return 0x1E891E;
2018-10-14 14:27:18 +02:00
}
@Override
public boolean isAcceptableType(IAuraType type) {
2019-02-16 21:35:55 +01:00
return this.type == null || type.isSimilar(this.type);
}
2021-12-04 15:40:09 +01:00
public void writeNBT(CompoundTag compound) {
2020-01-21 21:04:44 +01:00
compound.putInt("aura", this.aura);
2018-10-14 14:27:18 +02:00
}
2021-12-04 15:40:09 +01:00
public void readNBT(CompoundTag compound) {
2020-01-21 21:04:44 +01:00
this.aura = compound.getInt("aura");
2018-10-14 14:27:18 +02:00
}
}