mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-28 07:55:45 +00:00
Implemented mana discount.
This commit is contained in:
1 parent
e0e90b2ee4
commit
07836b1f3e
9 files changed
+88
-7
No files matched your search
@@ -197,4 +197,47 @@ public final class ManaItemHandler {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests mana from items in a given player's inventory. This version also
|
||||
* checks for IManaDiscountArmor items equipped to lower the cost.
|
||||
* @param manaToGet How much mana is to be requested, if less mana exists than this amount,
|
||||
* the amount of mana existent will be returned instead, if you want exact values use requestManaExact.
|
||||
* @param remove If true, the mana will be removed from the target item. Set to false to just check.
|
||||
* @return The amount of mana received from the request.
|
||||
*/
|
||||
public static int requestManaForTool(ItemStack stack, EntityPlayer player, int manaToGet, boolean remove) {
|
||||
float multiplier = 1F - getFullDiscountForTools(player);
|
||||
int cost = (int) ((float) manaToGet * multiplier);
|
||||
return (int) ((float) requestMana(stack, player, cost, remove) / multiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests an exact amount of mana from items in a given player's inventory. This version also
|
||||
* checks for IManaDiscountArmor items equipped to lower the cost.
|
||||
* @param manaToGet How much mana is to be requested, if less mana exists than this amount,
|
||||
* false will be returned instead, and nothing will happen.
|
||||
* @param remove If true, the mana will be removed from the target item. Set to false to just check.
|
||||
* @return If the request was succesful.
|
||||
*/
|
||||
public static boolean requestManaExactForTool(ItemStack stack, EntityPlayer player, int manaToGet, boolean remove) {
|
||||
float multiplier = 1F - getFullDiscountForTools(player);
|
||||
int cost = (int) ((float) manaToGet * multiplier);
|
||||
return requestManaExact(stack, player, cost, remove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sum of all the discounts on IManaDiscountArmor items equipped
|
||||
* on the player passed in.
|
||||
*/
|
||||
public static float getFullDiscountForTools(EntityPlayer player) {
|
||||
float discount = 0F;
|
||||
for(int i = 0; i < player.inventory.armorInventory.length; i++) {
|
||||
ItemStack armor = player.inventory.armorInventory[i];
|
||||
if(armor != null && armor.getItem() instanceof IManaDiscountArmor)
|
||||
discount += ((IManaDiscountArmor) armor.getItem()).getDiscount(armor, i, player);
|
||||
}
|
||||
|
||||
return discount;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user