BloodMagic/src/main/java/WayofTime/bloodmagic/item/gear/ItemPackSelfSacrifice.java

126 lines
4.3 KiB
Java
Raw Normal View History

2015-11-11 18:45:46 +00:00
package WayofTime.bloodmagic.item.gear;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.altar.IAltarManipulator;
import WayofTime.bloodmagic.altar.IBloodAltar;
2018-03-08 03:43:00 +00:00
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.iface.IItemLPContainer;
2018-03-08 03:43:00 +00:00
import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.util.helper.ItemHelper.LPContainer;
import WayofTime.bloodmagic.util.helper.NBTHelper;
import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.TextHelper;
2018-03-08 03:43:00 +00:00
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
2017-08-16 03:21:54 +00:00
import net.minecraft.client.util.ITooltipFlag;
2015-11-11 18:45:46 +00:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
2015-11-11 18:45:46 +00:00
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.RayTraceResult;
2015-11-11 18:45:46 +00:00
import net.minecraft.world.World;
2018-03-08 03:43:00 +00:00
import javax.annotation.Nonnull;
import java.util.List;
2017-08-16 04:30:48 +00:00
public class ItemPackSelfSacrifice extends ItemArmor implements IAltarManipulator, IItemLPContainer, IVariantProvider {
/**
* How much LP per half heart
*/
2016-01-01 09:34:17 +00:00
public final int CONVERSION = 100;
/**
* Max LP storage
*/
2016-01-01 09:34:17 +00:00
public final int CAPACITY = 10000;
/**
* How often the pack syphons
*/
2016-01-01 09:34:17 +00:00
public final int INTERVAL = 20;
/**
* How much health is required for the pack to syphon (0 - 1)
*/
2016-01-01 09:34:17 +00:00
public final float HEALTHREQ = 0.5f;
2015-11-11 18:45:46 +00:00
2017-08-16 04:30:48 +00:00
public ItemPackSelfSacrifice() {
super(ArmorMaterial.CHAIN, 0, EntityEquipmentSlot.CHEST);
2015-11-11 18:45:46 +00:00
2019-02-01 03:10:37 +00:00
setTranslationKey(BloodMagic.MODID + ".pack.selfSacrifice");
setCreativeTab(BloodMagic.TAB_BM);
2015-11-11 18:45:46 +00:00
}
@Override
2017-08-16 04:30:48 +00:00
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
2017-01-02 06:26:42 +00:00
ItemStack stack = player.getHeldItem(hand);
2015-11-11 18:45:46 +00:00
if (world.isRemote)
return ActionResult.newResult(EnumActionResult.FAIL, stack);
2015-11-11 18:45:46 +00:00
2016-04-24 17:06:28 +00:00
RayTraceResult position = this.rayTrace(world, player, false);
2015-11-11 18:45:46 +00:00
2017-08-16 04:30:48 +00:00
if (position == null) {
return super.onItemRightClick(world, player, hand);
2017-08-16 04:30:48 +00:00
} else {
if (position.typeOfHit == RayTraceResult.Type.BLOCK) {
2015-11-11 18:45:46 +00:00
TileEntity tile = world.getTileEntity(position.getBlockPos());
if (!(tile instanceof IBloodAltar))
return super.onItemRightClick(world, player, hand);
2015-11-11 18:45:46 +00:00
LPContainer.tryAndFillAltar((IBloodAltar) tile, stack, world, position.getBlockPos());
2015-11-11 18:45:46 +00:00
}
}
return ActionResult.newResult(EnumActionResult.FAIL, stack);
2015-11-11 18:45:46 +00:00
}
@Override
2017-08-16 04:30:48 +00:00
public void onArmorTick(World world, EntityPlayer player, ItemStack stack) {
2015-11-11 18:45:46 +00:00
if (world.isRemote || player.capabilities.isCreativeMode)
return;
boolean shouldSyphon = player.getHealth() / player.getMaxHealth() > HEALTHREQ && getStoredLP(stack) < CAPACITY;
2017-08-16 04:30:48 +00:00
if (shouldSyphon & world.getTotalWorldTime() % INTERVAL == 0) {
NetworkHelper.getSoulNetwork(player).hurtPlayer(player, 1.0F);
LPContainer.addLPToItem(stack, CONVERSION, CAPACITY);
2015-11-11 18:45:46 +00:00
}
if (getStoredLP(stack) > CAPACITY)
setStoredLP(stack, CAPACITY);
2015-11-11 18:45:46 +00:00
}
@Override
2017-08-16 04:30:48 +00:00
public void addInformation(ItemStack stack, World world, List<String> list, ITooltipFlag flag) {
if (!stack.hasTagCompound())
return;
2017-01-02 09:18:29 +00:00
list.add(TextHelper.localize("tooltip.bloodmagic.pack.selfSacrifice.desc"));
list.add(TextHelper.localize("tooltip.bloodmagic.pack.stored", getStoredLP(stack)));
2015-11-11 18:45:46 +00:00
}
2016-03-16 08:10:33 +00:00
@Override
2018-03-08 03:43:00 +00:00
public void gatherVariants(@Nonnull Int2ObjectMap<String> variants) {
variants.put(0, "type=normal");
2016-03-16 08:10:33 +00:00
}
// IFillable
2015-11-11 18:45:46 +00:00
@Override
2017-08-16 04:30:48 +00:00
public int getCapacity() {
return this.CAPACITY;
2015-11-11 18:45:46 +00:00
}
@Override
2017-08-16 04:30:48 +00:00
public int getStoredLP(ItemStack stack) {
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getInteger(Constants.NBT.STORED_LP) : 0;
2015-11-11 18:45:46 +00:00
}
@Override
2017-08-16 04:30:48 +00:00
public void setStoredLP(ItemStack stack, int lp) {
if (stack != null) {
NBTHelper.checkNBT(stack).getTagCompound().setInteger(Constants.NBT.STORED_LP, lp);
}
2015-11-11 18:45:46 +00:00
}
}