This commit is contained in:
gamma-delta 2022-05-19 20:41:17 -05:00
parent eb72622008
commit c77d2d96ea
2 changed files with 31 additions and 26 deletions

View file

@ -17,10 +17,13 @@ public interface ManaHolder {
boolean canConstructBattery();
default int withdrawMana(int cost, boolean simulate) {
if (!canProvide()) {
return 0;
}
var manaHere = getMana();
if (cost < 0) {
cost = manaHere;
}
if (cost < 0) {
cost = manaHere;
}
if (!simulate) {
var manaLeft = manaHere - cost;
setMana(manaLeft);

View file

@ -2,32 +2,34 @@ package at.petrak.hexcasting.api.item;
import net.minecraft.world.item.ItemStack;
/**
* Don't use this interface's methods directly. Instead, use an IManaReservoir capability.
*/
public interface ManaHolderItem {
int getMana(ItemStack stack);
int getMaxMana(ItemStack stack);
void setMana(ItemStack stack, int mana);
int getMana(ItemStack stack);
boolean manaProvider(ItemStack stack);
boolean canRecharge(ItemStack stack);
int getMaxMana(ItemStack stack);
default float getManaFullness(ItemStack stack) {
int max = getMaxMana(stack);
if (max == 0)
void setMana(ItemStack stack, int mana);
boolean manaProvider(ItemStack stack);
boolean canRecharge(ItemStack stack);
default float getManaFullness(ItemStack stack) {
int max = getMaxMana(stack);
if (max == 0) {
return 0;
return (float) getMana(stack) / (float) max;
}
default int withdrawMana(ItemStack stack, int cost, boolean simulate) {
var manaHere = getMana(stack);
if (cost < 0)
cost = manaHere;
if (!simulate) {
var manaLeft = manaHere - cost;
setMana(stack, manaLeft);
}
return Math.min(cost, manaHere);
}
return (float) getMana(stack) / (float) max;
}
default int withdrawMana(ItemStack stack, int cost, boolean simulate) {
var manaHere = getMana(stack);
if (cost < 0) {
cost = manaHere;
}
if (!simulate) {
var manaLeft = manaHere - cost;
setMana(stack, manaLeft);
}
return Math.min(cost, manaHere);
}
}