BloodMagic/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientArmourGem.java

108 lines
3.5 KiB
Java
Raw Normal View History

2016-01-09 15:05:41 -05:00
package WayofTime.bloodmagic.item.soul;
2016-03-18 14:54:31 -04:00
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
2016-01-09 15:05:41 -05:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2016-03-18 14:54:31 -04:00
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
2016-01-09 15:05:41 -05:00
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2016-03-18 14:54:31 -04:00
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.item.armour.ItemSentientArmour;
2016-01-09 15:05:41 -05:00
public class ItemSentientArmourGem extends Item
{
public static double[] willBracket = new double[] { 30, 200, 600, 1500, 4000, 6000, 8000, 16000 };
public static double[] consumptionPerHit = new double[] { 0.1, 0.12, 0.15, 0.2, 0.3, 0.35, 0.4, 0.5 };
public static double[] extraProtectionLevel = new double[] { 0, 0.25, 0.5, 0.6, 0.7, 0.75, 0.85, 0.9 };
2016-01-09 15:05:41 -05:00
public ItemSentientArmourGem()
{
super();
setCreativeTab(BloodMagic.tabBloodMagic);
2016-01-09 15:05:41 -05:00
setUnlocalizedName(Constants.Mod.MODID + ".sentientArmourGem");
setRegistryName(Constants.BloodMagicItem.SENTIENT_ARMOR_GEM.getRegName());
setMaxStackSize(1);
2016-01-09 15:05:41 -05:00
}
public EnumDemonWillType getCurrentType(ItemStack stack)
{
return EnumDemonWillType.DEFAULT;
}
2016-01-09 15:05:41 -05:00
@Override
2016-03-18 14:54:31 -04:00
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
2016-01-09 15:05:41 -05:00
{
boolean hasSentientArmour = false;
ItemStack[] armourInventory = player.inventory.armorInventory;
for (ItemStack armourStack : armourInventory)
{
if (armourStack != null && armourStack.getItem() instanceof ItemSentientArmour)
{
hasSentientArmour = true;
}
}
if (hasSentientArmour)
{
ItemSentientArmour.revertAllArmour(player);
} else
{
double will = PlayerDemonWillHandler.getTotalDemonWill(getCurrentType(stack), player);
2016-01-09 15:05:41 -05:00
int bracket = getWillBracket(will);
if (bracket >= 0)
{
// PlayerDemonWillHandler.consumeDemonWill(player, willBracket[bracket]);
2016-01-09 15:05:41 -05:00
ItemSentientArmour.convertPlayerArmour(player, consumptionPerHit[bracket], extraProtectionLevel[bracket]);
}
}
2016-03-18 14:54:31 -04:00
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
2016-01-09 15:05:41 -05:00
}
public int getWillBracket(double will)
{
int bracket = -1;
for (int i = 0; i < willBracket.length; i++)
{
if (will >= willBracket[i])
{
bracket = i;
}
}
return bracket;
}
@SideOnly(Side.CLIENT)
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining)
{
boolean hasSentientArmour = false;
ItemStack[] armourInventory = player.inventory.armorInventory;
for (ItemStack armourStack : armourInventory)
{
if (armourStack != null && armourStack.getItem() instanceof ItemSentientArmour)
{
hasSentientArmour = true;
}
}
if (hasSentientArmour)
{
return new ModelResourceLocation("bloodmagic:ItemSentientArmourGem1", "inventory");
}
return null;
}
}