BloodMagic/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientArmourGem.java
Nick fdfcb5c5b7 Change how blocks/items are registered (desc)
tterrag is a meany face and yelled at me for using class.getSimpleName(). So here's an API-friendly re-work of the registration system. This allows all our Items/Blocks to be obtained via the API. Just add a new enum.
2016-01-18 22:34:12 -08:00

99 lines
3.1 KiB
Java

package WayofTime.bloodmagic.item.soul;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.item.armour.ItemSentientArmour;
public class ItemSentientArmourGem extends Item
{
public static double[] willBracket = new double[] { 30, 200, 600, 1500, 4000, 6000, 8000 };
public static double[] consumptionPerHit = new double[] { 0.1, 0.12, 0.15, 0.2, 0.3, 0.35, 0.4 };
public static double[] extraProtectionLevel = new double[] { 0, 0.25, 0.5, 0.6, 0.7, 0.75, 0.85 };
public ItemSentientArmourGem()
{
super();
setCreativeTab(BloodMagic.tabBloodMagic);
setUnlocalizedName(Constants.Mod.MODID + ".sentientArmourGem");
setRegistryName(Constants.BloodMagicItem.SENTIENT_ARMOR_GEM.getRegName());
setMaxStackSize(1);
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
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(player);
int bracket = getWillBracket(will);
if (bracket >= 0)
{
PlayerDemonWillHandler.consumeDemonWill(player, willBracket[bracket]);
ItemSentientArmour.convertPlayerArmour(player, consumptionPerHit[bracket], extraProtectionLevel[bracket]);
}
}
return stack;
}
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;
}
}