2015-11-11 10:45:46 -08:00
|
|
|
package WayofTime.bloodmagic.item.gear;
|
|
|
|
|
2016-03-17 13:00:44 -07:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
|
|
|
import WayofTime.bloodmagic.api.altar.IAltarManipulator;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
2016-03-16 01:10:33 -07:00
|
|
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
2016-03-17 13:00:44 -07:00
|
|
|
import WayofTime.bloodmagic.tile.TileAltar;
|
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
2015-11-11 10:45:46 -08:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-03-18 12:45:37 -07:00
|
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
2015-11-11 10:45:46 -08:00
|
|
|
import net.minecraft.item.ItemArmor;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-18 12:45:37 -07:00
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.EnumActionResult;
|
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2015-11-11 10:45:46 -08:00
|
|
|
import net.minecraft.world.World;
|
2016-03-16 01:10:33 -07:00
|
|
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
2015-11-11 10:45:46 -08:00
|
|
|
|
2016-03-17 13:00:44 -07:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-03-16 01:10:33 -07:00
|
|
|
public class ItemPackSacrifice extends ItemArmor implements IAltarManipulator, IVariantProvider
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2015-11-11 10:45:46 -08:00
|
|
|
public final int CAPACITY = 10000; // Max LP storage
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public ItemPackSacrifice()
|
|
|
|
{
|
2016-03-18 12:45:37 -07:00
|
|
|
super(ArmorMaterial.CHAIN, 0, EntityEquipmentSlot.CHEST);
|
2015-11-11 10:45:46 -08:00
|
|
|
|
2015-11-28 18:25:46 -08:00
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".pack.sacrifice");
|
2015-11-11 10:45:46 -08:00
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 12:45:37 -07:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2015-11-11 10:45:46 -08:00
|
|
|
if (world.isRemote)
|
2016-03-18 12:45:37 -07:00
|
|
|
return ActionResult.newResult(EnumActionResult.FAIL, stack);
|
2015-11-11 10:45:46 -08:00
|
|
|
|
2016-03-18 12:45:37 -07:00
|
|
|
RayTraceResult position = this.getMovingObjectPositionFromPlayer(world, player, false);
|
2015-11-11 10:45:46 -08:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (position == null)
|
|
|
|
{
|
2016-03-18 12:45:37 -07:00
|
|
|
return super.onItemRightClick(stack, world, player, EnumHand.MAIN_HAND);
|
2015-12-30 15:34:40 -05:00
|
|
|
} else
|
|
|
|
{
|
2016-03-18 12:45:37 -07:00
|
|
|
if (position.typeOfHit == RayTraceResult.Type.BLOCK)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2015-11-11 10:45:46 -08:00
|
|
|
TileEntity tile = world.getTileEntity(position.getBlockPos());
|
|
|
|
|
|
|
|
if (!(tile instanceof TileAltar))
|
2016-03-18 12:45:37 -07:00
|
|
|
return super.onItemRightClick(stack, world, player, EnumHand.MAIN_HAND);
|
2015-11-11 10:45:46 -08:00
|
|
|
|
|
|
|
TileAltar altar = (TileAltar) tile;
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (!altar.isActive())
|
|
|
|
{
|
2015-11-11 10:45:46 -08:00
|
|
|
int amount = this.getStoredLP(stack);
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (amount > 0)
|
|
|
|
{
|
2015-11-11 10:45:46 -08:00
|
|
|
int filledAmount = altar.fillMainTank(amount);
|
|
|
|
amount -= filledAmount;
|
|
|
|
setStoredLP(stack, amount);
|
2016-03-18 13:05:57 -07:00
|
|
|
world.notifyBlockUpdate(position.getBlockPos(), world.getBlockState(position.getBlockPos()), world.getBlockState(position.getBlockPos()), 3);
|
2015-11-11 10:45:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 12:45:37 -07:00
|
|
|
return ActionResult.newResult(EnumActionResult.FAIL, stack);
|
2015-11-11 10:45:46 -08:00
|
|
|
}
|
|
|
|
|
2016-01-22 02:21:10 -08:00
|
|
|
@Override
|
|
|
|
public void onArmorTick(World world, EntityPlayer player, ItemStack stack)
|
|
|
|
{
|
|
|
|
if (getStoredLP(stack) > CAPACITY)
|
|
|
|
setStoredLP(stack, CAPACITY);
|
|
|
|
}
|
|
|
|
|
2015-11-11 10:45:46 -08:00
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean advanced)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
2015-11-11 10:45:46 -08:00
|
|
|
list.add(TextHelper.localize("tooltip.BloodMagic.pack.sacrifice.desc"));
|
|
|
|
list.add(TextHelper.localize("tooltip.BloodMagic.pack.stored", getStoredLP(stack)));
|
|
|
|
}
|
|
|
|
|
2016-03-16 01:10:33 -07:00
|
|
|
@Override
|
2016-03-16 18:41:06 -04:00
|
|
|
public List<Pair<Integer, String>> getVariants()
|
|
|
|
{
|
2016-03-16 01:10:33 -07:00
|
|
|
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
|
|
|
|
ret.add(new ImmutablePair<Integer, String>(0, "type=normal"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public void addLP(ItemStack stack, int toAdd)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
2015-11-11 10:45:46 -08:00
|
|
|
|
|
|
|
if (toAdd < 0)
|
|
|
|
toAdd = 0;
|
|
|
|
|
|
|
|
if (toAdd > CAPACITY)
|
|
|
|
toAdd = CAPACITY;
|
|
|
|
|
2016-01-22 02:21:10 -08:00
|
|
|
setStoredLP(stack, Math.min(getStoredLP(stack) + toAdd, CAPACITY));
|
2015-11-11 10:45:46 -08:00
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public void setStoredLP(ItemStack stack, int lp)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
stack.getTagCompound().setInteger(Constants.NBT.STORED_LP, lp);
|
2015-11-11 10:45:46 -08:00
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public int getStoredLP(ItemStack stack)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
return stack.getTagCompound().getInteger(Constants.NBT.STORED_LP);
|
2015-11-11 10:45:46 -08:00
|
|
|
}
|
|
|
|
}
|