diff --git a/MODSRC/vazkii/botania/api/mana/IManaItem.java b/MODSRC/vazkii/botania/api/mana/IManaItem.java index 92a2ae295..a6dd9de2a 100644 --- a/MODSRC/vazkii/botania/api/mana/IManaItem.java +++ b/MODSRC/vazkii/botania/api/mana/IManaItem.java @@ -44,7 +44,6 @@ public interface IManaItem { /** * Can this item recieve mana from another item? - * The getItem() of both stacks can be casted to IManaItem. */ public boolean canReceiveManaFromItem(ItemStack stack, ItemStack otherStack); @@ -57,7 +56,6 @@ public interface IManaItem { /** * Can this item export mana to another item? - * The getItem() of both stacks can be casted to IManaItem. */ public boolean canExportManaToItem(ItemStack stack, ItemStack otherStack); diff --git a/MODSRC/vazkii/botania/api/mana/ManaItemHandler.java b/MODSRC/vazkii/botania/api/mana/ManaItemHandler.java index b6da089c2..b74401ba0 100644 --- a/MODSRC/vazkii/botania/api/mana/ManaItemHandler.java +++ b/MODSRC/vazkii/botania/api/mana/ManaItemHandler.java @@ -22,8 +22,7 @@ import vazkii.botania.api.BotaniaAPI; public final class ManaItemHandler { /** - * Requests mana from items in a given player's inventory. Note that stack.getItem() - * must be instanceof IManaItem. + * Requests mana from items in a given player's inventory. * @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. @@ -70,7 +69,6 @@ public final class ManaItemHandler { /** * Requests an exact amount of mana from items in a given player's inventory. - * Note that stack.getItem() must be instanceof IManaItem. * @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. @@ -82,7 +80,6 @@ public final class ManaItemHandler { IInventory mainInv = player.inventory; IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player); - System.out.println(baublesInv); List stacks = new ArrayList(); int invSize = mainInv.getSizeInventory(); @@ -113,5 +110,99 @@ public final class ManaItemHandler { return false; } + + /** + * Dispatches mana to items in a given player's inventory. Note that this method + * does not automatically remove mana from the item which is exporting. + * @param manaToSend How much mana is to be sent. + * @param remove If true, the mana will be added from the target item. Set to false to just check. + * @return The amount of mana actually sent. + */ + public static int dispatchMana(ItemStack stack, EntityPlayer player, int manaToSend, boolean add) { + if(stack == null) + return 0; + IInventory mainInv = player.inventory; + IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player); + + List stacks = new ArrayList(); + int invSize = mainInv.getSizeInventory(); + int size = invSize; + if(baublesInv != null) + size += baublesInv.getSizeInventory(); + + for(int i = 0; i < size; i++) { + boolean useBaubles = i >= invSize; + IInventory inv = useBaubles ? baublesInv : mainInv; + ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0)); + if(stackInSlot == stack) + continue; + + if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) { + IManaItem manaItemSlot = (IManaItem) stackInSlot.getItem(); + + if(manaItemSlot.canReceiveManaFromItem(stackInSlot, stack)) { + if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canExportManaToItem(stack, stackInSlot)) + continue; + + int received = 0; + if(manaItemSlot.getMana(stackInSlot) + manaToSend <= manaItemSlot.getMaxMana(stackInSlot)) + received = manaToSend; + else received = manaToSend - (manaItemSlot.getMana(stackInSlot) + manaToSend - manaItemSlot.getMaxMana(stackInSlot)); + + + if(add) + manaItemSlot.addMana(stackInSlot, manaToSend); + + return received; + } + } + } + + return 0; + } + + /** + * Dispatches an exact amount of mana to items in a given player's inventory. Note that this method + * does not automatically remove mana from the item which is exporting. + * @param manaToSend How much mana is to be sent. + * @param remove If true, the mana will be added from the target item. Set to false to just check. + * @return If an item received the mana sent. + */ + public static boolean dispatchManaExact(ItemStack stack, EntityPlayer player, int manaToSend, boolean add) { + if(stack == null) + return false; + + IInventory mainInv = player.inventory; + IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player); + + List stacks = new ArrayList(); + int invSize = mainInv.getSizeInventory(); + int size = invSize; + if(baublesInv != null) + size += baublesInv.getSizeInventory(); + + for(int i = 0; i < size; i++) { + boolean useBaubles = i >= invSize; + IInventory inv = useBaubles ? baublesInv : mainInv; + ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0)); + if(stackInSlot == stack) + continue; + + if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) { + IManaItem manaItemSlot = (IManaItem) stackInSlot.getItem(); + if(manaItemSlot.getMana(stackInSlot) + manaToSend <= manaItemSlot.getMaxMana(stackInSlot) && manaItemSlot.canReceiveManaFromItem(stackInSlot, stack)) { + if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canExportManaToItem(stack, stackInSlot)) + continue; + + if(add) + manaItemSlot.addMana(stackInSlot, manaToSend); + + return true; + } + } + } + + return false; + } } diff --git a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java index c7ddc8e66..68a8d35a4 100644 --- a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java +++ b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java @@ -90,6 +90,7 @@ public final class BotaniaCreativeTab extends CreativeTabs { addItem(ModItems.tinyPlanet); addItem(ModItems.manaRing); + addItem(ModItems.auraRing); addItem(ModItems.manaTablet); addItem(ModItems.manaMirror); diff --git a/MODSRC/vazkii/botania/common/item/ModItems.java b/MODSRC/vazkii/botania/common/item/ModItems.java index 857938a60..f40043a16 100644 --- a/MODSRC/vazkii/botania/common/item/ModItems.java +++ b/MODSRC/vazkii/botania/common/item/ModItems.java @@ -23,6 +23,7 @@ import vazkii.botania.common.item.equipment.armor.ItemTerrasteelBoots; import vazkii.botania.common.item.equipment.armor.ItemTerrasteelChest; import vazkii.botania.common.item.equipment.armor.ItemTerrasteelHelm; import vazkii.botania.common.item.equipment.armor.ItemTerrasteelLegs; +import vazkii.botania.common.item.equipment.bauble.ItemAuraRing; import vazkii.botania.common.item.equipment.bauble.ItemManaRing; import vazkii.botania.common.item.equipment.bauble.ItemTinyPlanet; import vazkii.botania.common.item.equipment.tool.ItemManasteelAxe; @@ -70,6 +71,7 @@ public final class ModItems { public static Item terraSword; public static Item tinyPlanet; public static Item manaRing; + public static Item auraRing; public static void init() { lexicon = new ItemLexicon(); @@ -107,6 +109,7 @@ public final class ModItems { terraSword = new ItemTerraSword(); tinyPlanet = new ItemTinyPlanet(); manaRing = new ItemManaRing(); + auraRing = new ItemAuraRing(); OreDictionary.registerOre(LibOreDict.LEXICON, lexicon); for(int i = 0; i < 16; i++) { diff --git a/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemAuraRing.java b/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemAuraRing.java new file mode 100644 index 000000000..1d94fad25 --- /dev/null +++ b/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemAuraRing.java @@ -0,0 +1,38 @@ +/** + * This class was created by . 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 a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Apr 24, 2014, 4:43:47 PM (GMT)] + */ +package vazkii.botania.common.item.equipment.bauble; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import vazkii.botania.api.mana.ManaItemHandler; +import vazkii.botania.common.lib.LibItemNames; +import baubles.api.BaubleType; + +public class ItemAuraRing extends ItemBauble { + + public ItemAuraRing() { + super(LibItemNames.AURA_RING); + } + + @Override + public void onWornTick(ItemStack stack, EntityLivingBase player) { + if(player instanceof EntityPlayer && player.worldObj.getTotalWorldTime() % 2 == 0) + ManaItemHandler.dispatchManaExact(stack, (EntityPlayer) player, 1, true); + } + + @Override + public BaubleType getBaubleType(ItemStack itemstack) { + return BaubleType.RING; + } + +} diff --git a/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemManaRing.java b/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemManaRing.java index 7fe03ed9c..41fba119a 100644 --- a/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemManaRing.java +++ b/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemManaRing.java @@ -24,7 +24,7 @@ import baubles.api.BaubleType; public class ItemManaRing extends ItemBauble implements IManaItem { - private static final int MAX_MANA = 50000; + private static final int MAX_MANA = 500000; private static final String TAG_MANA = "mana"; diff --git a/resources/assets/botania/lang/en_US.lang b/resources/assets/botania/lang/en_US.lang index 27633eb24..98580c19b 100644 --- a/resources/assets/botania/lang/en_US.lang +++ b/resources/assets/botania/lang/en_US.lang @@ -289,7 +289,8 @@ item.botania:terrasteelLegs.name=Terrasteel Leggings item.botania:terrasteelBoots.name=Terrasteel Boots item.botania:terraSword.name=Terra Blade item.botania:tinyPlanet.name=Tiny Planet -item.botnaia:manaRing.name=Band of Mana +item.botania:manaRing.name=Band of Mana +item.botania:auraRing.name=Band of Aura # GUI TEXT botania.gui.lexicon.header=Lexica Botania Index - Pick which category you would like to study: diff --git a/resources/assets/botania/textures/items/auraRing.png b/resources/assets/botania/textures/items/auraRing.png new file mode 100644 index 000000000..d42fe6d48 Binary files /dev/null and b/resources/assets/botania/textures/items/auraRing.png differ