From c77d2d96ea29deb24ba39700c0bf0ef345a233a4 Mon Sep 17 00:00:00 2001 From: gamma-delta <29877714+gamma-delta@users.noreply.github.com> Date: Thu, 19 May 2022 20:41:17 -0500 Subject: [PATCH] close #73 --- .../hexcasting/api/addldata/ManaHolder.java | 9 ++-- .../hexcasting/api/item/ManaHolderItem.java | 48 ++++++++++--------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/addldata/ManaHolder.java b/Common/src/main/java/at/petrak/hexcasting/api/addldata/ManaHolder.java index ee1792c3..01debb5a 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/addldata/ManaHolder.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/addldata/ManaHolder.java @@ -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); diff --git a/Common/src/main/java/at/petrak/hexcasting/api/item/ManaHolderItem.java b/Common/src/main/java/at/petrak/hexcasting/api/item/ManaHolderItem.java index 19d44d3f..4247bba9 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/item/ManaHolderItem.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/item/ManaHolderItem.java @@ -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); + } }