Added a lot of soul stuff.

This commit is contained in:
WayofTime 2016-01-07 12:59:46 -05:00
parent 45870812d4
commit 72ed003da1
13 changed files with 278 additions and 9 deletions

View file

@ -0,0 +1,30 @@
package WayofTime.bloodmagic.api.soul;
import net.minecraft.item.ItemStack;
public interface ISoul
{
public double getSouls(ItemStack soulStack);
public void setSouls(ItemStack soulStack, double souls);
/**
* Drains the souls from the soulStack. If all of the souls are drained, the
* soulStack will be removed.
*
* @param soulStack
* @param drainAmount
* @return The number of souls drained.
*/
public double drainSouls(ItemStack soulStack, double drainAmount);
/**
* Creates a new ItemStack with the specified number of souls.
* Implementation should respect the number requested.
*
* @param meta
* @param number
* @return
*/
public ItemStack createSoul(int meta, double number);
}

View file

@ -0,0 +1,30 @@
package WayofTime.bloodmagic.api.soul;
import net.minecraft.item.ItemStack;
public interface ISoulGem
{
/**
*
* @param soulGemStack
* - The ItemStack for this soul gem.
* @param soulStack
* - The ItemStack for the soul. Item should extend ISoul
* @return - The remainder soulStack after the souls have been absorbed into
* the gem. Return null if there are no souls left in the stack.
*/
public ItemStack fillSoulGem(ItemStack soulGemStack, ItemStack soulStack);
/**
* Returns the number of souls that are left in the soul gem. Returns a
* double because souls can be fractionally drained.
*
* @param soulGemStack
* @return
*/
public double getSouls(ItemStack soulGemStack);
public int getMaxSouls(ItemStack soulGemStack);
public double drainSouls(ItemStack stack, double drainAmount);
}

View file

@ -0,0 +1,11 @@
package WayofTime.bloodmagic.api.soul;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
public interface ISoulWeapon
{
public List<ItemStack> getRandomSoulDrop(EntityLivingBase killedEntity, EntityLivingBase attackingEntity, ItemStack stack, int looting);
}

View file

@ -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;
}
}