2015-12-27 19:38:12 -05:00
|
|
|
package WayofTime.bloodmagic.item.sigil;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2017-03-14 19:33:13 -07:00
|
|
|
import WayofTime.bloodmagic.api.iface.ISigil;
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
2016-11-11 16:57:50 -08:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
|
|
|
|
import WayofTime.bloodmagic.entity.projectile.EntityBloodLight;
|
2016-03-18 14:54:31 -04:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.ActionResult;
|
2016-11-11 16:57:50 -08:00
|
|
|
import net.minecraft.util.EnumActionResult;
|
2016-03-18 14:54:31 -04:00
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.world.World;
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class ItemSigilBloodLight extends ItemSigilBase {
|
|
|
|
public ItemSigilBloodLight() {
|
2015-12-27 19:38:12 -05:00
|
|
|
super("bloodLight", 10);
|
|
|
|
}
|
|
|
|
|
2016-03-14 20:18:54 -07:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
2016-03-14 20:18:54 -07:00
|
|
|
if (getCooldownRemainder(stack) > 0)
|
|
|
|
reduceCooldown(stack);
|
|
|
|
}
|
|
|
|
|
2015-12-27 19:38:12 -05:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
2017-01-02 00:10:28 -08:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2017-03-14 19:33:13 -07:00
|
|
|
if (stack.getItem() instanceof ISigil.Holding)
|
|
|
|
stack = ((Holding) stack.getItem()).getHeldItem(stack, player);
|
2016-11-11 16:57:50 -08:00
|
|
|
if (PlayerHelper.isFakePlayer(player))
|
|
|
|
return ActionResult.newResult(EnumActionResult.FAIL, stack);
|
|
|
|
|
2016-04-24 10:06:28 -07:00
|
|
|
RayTraceResult mop = this.rayTrace(world, player, false);
|
2016-01-31 14:31:16 -05:00
|
|
|
|
2016-03-14 20:18:54 -07:00
|
|
|
if (getCooldownRemainder(stack) > 0)
|
2017-01-02 00:10:28 -08:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2016-03-14 20:18:54 -07:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) {
|
2016-02-03 23:14:26 -08:00
|
|
|
BlockPos blockPos = mop.getBlockPos().offset(mop.sideHit);
|
2016-01-31 14:31:16 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (world.isAirBlock(blockPos)) {
|
2017-08-14 20:53:42 -07:00
|
|
|
world.setBlockState(blockPos, RegistrarBloodMagicBlocks.BLOOD_LIGHT.getDefaultState());
|
2016-03-14 20:18:54 -07:00
|
|
|
if (!world.isRemote)
|
2016-12-19 17:32:03 -08:00
|
|
|
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed());
|
2016-03-14 20:18:54 -07:00
|
|
|
resetCooldown(stack);
|
2016-03-18 14:54:31 -04:00
|
|
|
player.swingArm(hand);
|
2017-01-02 00:10:28 -08:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2016-03-14 20:18:54 -07:00
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
} else {
|
|
|
|
if (!world.isRemote) {
|
2017-01-02 00:10:28 -08:00
|
|
|
world.spawnEntity(new EntityBloodLight(world, player));
|
2016-12-19 17:32:03 -08:00
|
|
|
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed());
|
2016-03-14 20:18:54 -07:00
|
|
|
}
|
|
|
|
resetCooldown(stack);
|
2016-01-31 14:31:16 -05:00
|
|
|
}
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2017-01-02 00:10:28 -08:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
2016-03-14 20:18:54 -07:00
|
|
|
return oldStack.getItem() != newStack.getItem();
|
|
|
|
}
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public int getCooldownRemainder(ItemStack stack) {
|
2016-03-14 20:18:54 -07:00
|
|
|
return NBTHelper.checkNBT(stack).getTagCompound().getInteger(Constants.NBT.TICKS_REMAINING);
|
|
|
|
}
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public void reduceCooldown(ItemStack stack) {
|
2016-03-14 20:18:54 -07:00
|
|
|
NBTHelper.checkNBT(stack).getTagCompound().setInteger(Constants.NBT.TICKS_REMAINING, getCooldownRemainder(stack) - 1);
|
|
|
|
}
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public void resetCooldown(ItemStack stack) {
|
2016-03-14 20:18:54 -07:00
|
|
|
NBTHelper.checkNBT(stack).getTagCompound().setInteger(Constants.NBT.TICKS_REMAINING, 10);
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
}
|