mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-13 00:37:57 +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;
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -10,9 +10,12 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.equipment.armor.manasteel;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.mana.IManaDiscountArmor;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
public class ItemManasteelHelm extends ItemManasteelArmor {
|
||||
public class ItemManasteelHelm extends ItemManasteelArmor implements IManaDiscountArmor {
|
||||
|
||||
public ItemManasteelHelm() {
|
||||
this(LibItemNames.MANASTEEL_HELM);
|
||||
@@ -22,4 +25,9 @@ public class ItemManasteelHelm extends ItemManasteelArmor {
|
||||
super(0, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player) {
|
||||
return hasArmorSet(player) ? 0.1F : 0F;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public final class ToolCommons {
|
||||
|
||||
public static void damageItem(ItemStack stack, int dmg, EntityLivingBase entity, int manaPerDamage) {
|
||||
int manaToRequest = dmg * manaPerDamage;
|
||||
boolean manaRequested = entity instanceof EntityPlayer ? ManaItemHandler.requestManaExact(stack, (EntityPlayer) entity, manaToRequest, true) : false;
|
||||
boolean manaRequested = entity instanceof EntityPlayer ? ManaItemHandler.requestManaExactForTool(stack, (EntityPlayer) entity, manaToRequest, true) : false;
|
||||
|
||||
if(!manaRequested)
|
||||
stack.damageItem(dmg, entity);
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ public class ItemManasteelAxe extends ItemAxe implements IManaUsingItem {
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5) {
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExact(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExactForTool(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
stack.setItemDamage(stack.getItemDamage() - 1);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ public class ItemManasteelPick extends ItemPickaxe implements IManaUsingItem {
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5) {
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExact(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExactForTool(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
stack.setItemDamage(stack.getItemDamage() - 1);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ public class ItemManasteelShears extends ItemShears implements IManaUsingItem {
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5) {
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExact(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExactForTool(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
stack.setItemDamage(stack.getItemDamage() - 1);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ public class ItemManasteelShovel extends ItemSpade implements IManaUsingItem {
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5) {
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExact(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExactForTool(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
stack.setItemDamage(stack.getItemDamage() - 1);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ public class ItemManasteelSword extends ItemSword implements IManaUsingItem {
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5) {
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExact(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExactForTool(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
|
||||
stack.setItemDamage(stack.getItemDamage() - 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user