2015-11-11 18:45:46 +00:00
|
|
|
package WayofTime.bloodmagic.item.gear;
|
|
|
|
|
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
2015-11-29 02:25:46 +00:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2015-11-11 18:45:46 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.IAltarManipulator;
|
2015-11-29 02:25:46 +00:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
2015-11-11 18:45:46 +00:00
|
|
|
import WayofTime.bloodmagic.tile.TileAltar;
|
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemArmor;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class ItemPackSacrifice extends ItemArmor implements IAltarManipulator
|
|
|
|
{
|
2016-01-08 02:15:23 +00:00
|
|
|
public final int CONVERSION = 20; // How much LP per heart
|
2015-11-11 18:45:46 +00:00
|
|
|
public final int CAPACITY = 10000; // Max LP storage
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public ItemPackSacrifice()
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
super(ArmorMaterial.CHAIN, 0, 1);
|
|
|
|
|
2015-11-29 02:25:46 +00:00
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".pack.sacrifice");
|
2015-11-11 18:45:46 +00:00
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 20:34:40 +00:00
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
if (world.isRemote)
|
|
|
|
return stack;
|
|
|
|
|
|
|
|
MovingObjectPosition position = this.getMovingObjectPositionFromPlayer(world, player, false);
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (position == null)
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
return super.onItemRightClick(stack, world, player);
|
2015-12-30 20:34:40 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (position.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
TileEntity tile = world.getTileEntity(position.getBlockPos());
|
|
|
|
|
|
|
|
if (!(tile instanceof TileAltar))
|
|
|
|
return super.onItemRightClick(stack, world, player);
|
|
|
|
|
|
|
|
TileAltar altar = (TileAltar) tile;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (!altar.isActive())
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
int amount = this.getStoredLP(stack);
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (amount > 0)
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
int filledAmount = altar.fillMainTank(amount);
|
|
|
|
amount -= filledAmount;
|
|
|
|
setStoredLP(stack, amount);
|
|
|
|
world.markBlockForUpdate(position.getBlockPos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 20:34:40 +00:00
|
|
|
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type)
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
return Constants.Mod.DOMAIN + "models/armor/bloodPack_layer_1.png";
|
2015-11-11 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 20:34:40 +00:00
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean advanced)
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
2015-11-11 18:45:46 +00:00
|
|
|
list.add(TextHelper.localize("tooltip.BloodMagic.pack.sacrifice.desc"));
|
|
|
|
list.add(TextHelper.localize("tooltip.BloodMagic.pack.stored", getStoredLP(stack)));
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public void addLP(ItemStack stack, int toAdd)
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
2015-11-11 18:45:46 +00:00
|
|
|
|
|
|
|
if (toAdd < 0)
|
|
|
|
toAdd = 0;
|
|
|
|
|
|
|
|
if (toAdd > CAPACITY)
|
|
|
|
toAdd = CAPACITY;
|
|
|
|
|
|
|
|
setStoredLP(stack, getStoredLP(stack) + toAdd);
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public void setStoredLP(ItemStack stack, int lp)
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
stack.getTagCompound().setInteger(Constants.NBT.STORED_LP, lp);
|
2015-11-11 18:45:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public int getStoredLP(ItemStack stack)
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
return stack.getTagCompound().getInteger(Constants.NBT.STORED_LP);
|
2015-11-11 18:45:46 +00:00
|
|
|
}
|
|
|
|
}
|