BloodMagic/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleable.java

99 lines
3.5 KiB
Java
Raw Normal View History

2015-12-28 00:38:12 +00:00
package WayofTime.bloodmagic.item.sigil;
2016-03-18 18:54:31 +00:00
import java.util.ArrayList;
import java.util.List;
2015-12-28 00:38:12 +00:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
2016-03-18 18:54:31 +00:00
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
2015-12-28 00:38:12 +00:00
import net.minecraft.util.EnumFacing;
2016-03-18 18:54:31 +00:00
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
2015-12-28 00:38:12 +00:00
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2016-03-18 18:54:31 +00:00
2016-03-16 08:10:33 +00:00
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
2015-12-28 00:38:12 +00:00
2016-03-18 18:54:31 +00:00
import WayofTime.bloodmagic.item.ItemBindable;
import WayofTime.bloodmagic.util.helper.TextHelper;
public class ItemSigilToggleable extends ItemSigilBase
{
public ItemSigilToggleable(String name, int lpUsed)
{
2015-12-28 00:38:12 +00:00
super(name, lpUsed);
setToggleable();
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
{
2015-12-28 00:38:12 +00:00
super.addInformation(stack, player, tooltip, advanced);
2015-12-31 18:50:38 +00:00
if (getActivated(stack))
tooltip.add(TextHelper.localize("tooltip.BloodMagic.activated"));
else
tooltip.add(TextHelper.localize("tooltip.BloodMagic.deactivated"));
2015-12-28 00:38:12 +00:00
}
@Override
2016-03-18 18:54:31 +00:00
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
if (!world.isRemote && !isUnusable(stack))
{
2015-12-31 18:50:38 +00:00
if (player.isSneaking())
setActivated(stack, !getActivated(stack));
if (getActivated(stack) && ItemBindable.syphonNetwork(stack, player, getLPUsed()))
2016-03-18 18:54:31 +00:00
return super.onItemRightClick(stack, world, player, hand);
2015-12-28 00:38:12 +00:00
}
2016-03-18 18:54:31 +00:00
return super.onItemRightClick(stack, world, player, hand);
2015-12-28 00:38:12 +00:00
}
@Override
2016-03-18 18:54:31 +00:00
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
2016-03-18 18:54:31 +00:00
return (ItemBindable.syphonNetwork(stack, player, getLPUsed()) && onSigilUse(stack, player, world, pos, side, hitX, hitY, hitZ)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
2015-12-28 00:38:12 +00:00
}
public boolean onSigilUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
{
2015-12-28 00:38:12 +00:00
return false;
}
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
{
if (!worldIn.isRemote && entityIn instanceof EntityPlayerMP && getActivated(stack))
{
if (worldIn.getWorldTime() % 100 == 0)
{
2015-12-30 22:24:40 +00:00
if (!ItemBindable.syphonNetwork(stack, (EntityPlayer) entityIn, getLPUsed()))
{
2015-12-28 00:38:12 +00:00
setActivated(stack, false);
}
}
onSigilUpdate(stack, worldIn, (EntityPlayer) entityIn, itemSlot, isSelected);
}
}
public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected)
{
}
2016-03-16 08:10:33 +00:00
@Override
2016-03-16 22:41:06 +00:00
public List<Pair<Integer, String>> getVariants()
{
2016-03-16 08:10:33 +00:00
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
ret.add(new ImmutablePair<Integer, String>(0, "active=false"));
ret.add(new ImmutablePair<Integer, String>(1, "active=true"));
return ret;
}
2015-12-28 00:38:12 +00:00
}