Added a lot of soul stuff.
This commit is contained in:
parent
45870812d4
commit
72ed003da1
13 changed files with 278 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
package WayofTime.bloodmagic.api.iface;
|
||||
package WayofTime.bloodmagic.api.soul;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package WayofTime.bloodmagic.api.iface;
|
||||
package WayofTime.bloodmagic.api.soul;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
@ -25,4 +25,6 @@ public interface ISoulGem
|
|||
public double getSouls(ItemStack soulGemStack);
|
||||
|
||||
public int getMaxSouls(ItemStack soulGemStack);
|
||||
|
||||
public double drainSouls(ItemStack stack, double drainAmount);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package WayofTime.bloodmagic.api.iface;
|
||||
package WayofTime.bloodmagic.api.soul;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
package WayofTime.bloodmagic.api.soul;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This class provides several helper methods in order to handle soul
|
||||
* consumption and use for a player. This refers to the Soul System, meaning
|
||||
* Monster Souls and Soul Gems, etc. The Soul Network's helper methods are found
|
||||
* in WayofTime.bloodmagic.api.network
|
||||
*
|
||||
* @author WayofTime
|
||||
*
|
||||
*/
|
||||
public class PlayerSoulHandler
|
||||
{
|
||||
public static double getTotalSouls(EntityPlayer player)
|
||||
{
|
||||
ItemStack[] inventory = player.inventory.mainInventory;
|
||||
double souls = 0;
|
||||
|
||||
for (int i = 0; i < inventory.length; i++)
|
||||
{
|
||||
ItemStack stack = inventory[i];
|
||||
if (stack != null)
|
||||
{
|
||||
if (stack.getItem() instanceof ISoul)
|
||||
{
|
||||
souls += ((ISoul) stack.getItem()).getSouls(stack);
|
||||
} else if (stack.getItem() instanceof ISoulGem)
|
||||
{
|
||||
souls += ((ISoulGem) stack.getItem()).getSouls(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return souls;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param amount
|
||||
* @return - amount consumed
|
||||
*/
|
||||
public static double consumeSouls(EntityPlayer player, double amount)
|
||||
{
|
||||
double consumed = 0;
|
||||
|
||||
ItemStack[] inventory = player.inventory.mainInventory;
|
||||
|
||||
for (int i = 0; i < inventory.length; i++)
|
||||
{
|
||||
if (consumed >= amount)
|
||||
{
|
||||
return consumed;
|
||||
}
|
||||
|
||||
ItemStack stack = inventory[i];
|
||||
if (stack != null)
|
||||
{
|
||||
if (stack.getItem() instanceof ISoul)
|
||||
{
|
||||
consumed += ((ISoul) stack.getItem()).drainSouls(stack, amount - consumed);
|
||||
if (((ISoul) stack.getItem()).getSouls(stack) <= 0)
|
||||
{
|
||||
inventory[i] = null;
|
||||
}
|
||||
} else if (stack.getItem() instanceof ISoulGem)
|
||||
{
|
||||
consumed += ((ISoulGem) stack.getItem()).drainSouls(stack, amount - consumed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an ISoul contained in an ItemStack to one of the Soul Gems in the
|
||||
* player's inventory.
|
||||
*
|
||||
* @param player
|
||||
* @param soulStack
|
||||
* - ItemStack that contains an ISoul to be added
|
||||
* @return
|
||||
*/
|
||||
public static ItemStack addSouls(EntityPlayer player, ItemStack soulStack)
|
||||
{
|
||||
if (soulStack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack[] inventory = player.inventory.mainInventory;
|
||||
|
||||
for (int i = 0; i < inventory.length; i++)
|
||||
{
|
||||
ItemStack stack = inventory[i];
|
||||
if (stack != null)
|
||||
{
|
||||
if (stack.getItem() instanceof ISoulGem)
|
||||
{
|
||||
ItemStack newStack = ((ISoulGem) stack.getItem()).fillSoulGem(stack, soulStack);
|
||||
if (newStack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return soulStack;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue