package com.teamwizardry.refraction.common.item;

import com.teamwizardry.librarianlib.common.base.item.ItemMod;
import com.teamwizardry.refraction.api.beam.Beam;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.awt.*;

/**
 * Created by LordSaad.
 */
public class ItemPhotonCannon extends ItemMod {

    public ItemPhotonCannon() {
        super("photon_cannon");
        setMaxStackSize(1);
    }

    @Override
    public EnumAction getItemUseAction(ItemStack stack) {
        return EnumAction.BOW;
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
        playerIn.setActiveHand(hand);
        return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack) {
        return 1000;
    }

    @Override
    public void onUsingTick(ItemStack stack, EntityLivingBase playerIn, int count) {
        boolean handMod = playerIn.getHeldItemMainhand() == stack ^ playerIn.getPrimaryHand() == EnumHandSide.LEFT;
        Vec3d cross = playerIn.getLook(1).crossProduct(new Vec3d(0, playerIn.getEyeHeight(), 0)).normalize().scale(playerIn.width / 2);
        if (!handMod) cross = cross.scale(-1);
        Vec3d playerVec = new Vec3d(playerIn.posX + cross.xCoord, playerIn.posY + playerIn.getEyeHeight() + cross.yCoord - 0.2, playerIn.posZ + cross.zCoord);

        Beam beam = new Beam(playerIn.getEntityWorld(), playerVec, playerIn.getLook(1), new Color(0xFF0ADA))
                .setEnableEffect(true)
                .setUUIDToSkip(playerIn.getUniqueID())
                .enableParticleEnd();
        beam.spawn();

        playerIn.motionX = beam.slope.xCoord * -1 / 10.0;
        playerIn.motionZ = beam.slope.zCoord * -1 / 10.0;
        playerIn.velocityChanged = true;
    }
}

@@ -106,16 +106,66 @@
 temMod;%0A
+import com.teamwizardry.refraction.api.Constants;%0A
 import c
@@ -206,16 +206,16 @@
 m.Beam;%0A
-
 import n
@@ -406,140 +406,9 @@
 til.
-ActionResult;%0Aimport net.minecraft.util.EnumActionResult;%0Aimport net.minecraft.util.EnumHand;%0Aimport net.minecraft.util.EnumHandSide
+*
 ;%0Aim
@@ -643,16 +643,16 @@
 nnon%22);%0A
-
         
@@ -667,24 +667,250 @@
 ackSize(1);%0A
+        addPropertyOverride(new ResourceLocation(Constants.MOD_ID, %22firing%22),%0A                (stack, worldIn, entityIn) -%3E entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F);%0A
     %7D%0A%0A    @

prepare to have an override