mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-25 14:34:36 +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
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [Jan 28, 2015, 9:22:53 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.mana;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* An armor item that implements this can provide a mana discount for mana tools.
|
||||
* Mana tools are the ones on the main toolset (Pick, Shovel, Axe, Sword and Shovel).
|
||||
*/
|
||||
public interface IManaDiscountArmor {
|
||||
|
||||
/**
|
||||
* Gets the mana discount that this piece of armor provides. This is added
|
||||
* together to create the full discount.
|
||||
* Value is to be from 0.0 to 1.0. 0.1 is 10% discount, as an example.
|
||||
* You can also return negative values to make tools cost more.
|
||||
*/
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player);
|
||||
|
||||
}
|
||||
@@ -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