package WayofTime.bloodmagic.item.sigil; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.api.util.helper.NetworkHelper; import WayofTime.bloodmagic.entity.projectile.EntityBloodLight; import WayofTime.bloodmagic.registry.ModBlocks; public class ItemSigilBloodLight extends ItemSigilBase { public ItemSigilBloodLight() { super("bloodLight", 10); setRegistryName(Constants.BloodMagicItem.SIGIL_BLOOD_LIGHT.getRegName()); } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (getCooldownRemainder(stack) > 0) reduceCooldown(stack); } @Override public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) { RayTraceResult mop = this.getMovingObjectPositionFromPlayer(world, player, false); if (getCooldownRemainder(stack) > 0) return super.onItemRightClick(stack, world, player, hand); if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos blockPos = mop.getBlockPos().offset(mop.sideHit); if (world.isAirBlock(blockPos)) { world.setBlockState(blockPos, ModBlocks.bloodLight.getDefaultState()); if (!world.isRemote) NetworkHelper.syphonAndDamage(NetworkHelper.getSoulNetwork(player), player, getLPUsed()); resetCooldown(stack); player.swingArm(hand); return super.onItemRightClick(stack, world, player, hand); } } else { if (!world.isRemote) { world.spawnEntityInWorld(new EntityBloodLight(world, player)); NetworkHelper.syphonAndDamage(NetworkHelper.getSoulNetwork(player), player, getLPUsed()); } resetCooldown(stack); } return super.onItemRightClick(stack, world, player, hand); } @Override public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { return oldStack.getItem() != newStack.getItem(); } public int getCooldownRemainder(ItemStack stack) { return NBTHelper.checkNBT(stack).getTagCompound().getInteger(Constants.NBT.TICKS_REMAINING); } public void reduceCooldown(ItemStack stack) { NBTHelper.checkNBT(stack).getTagCompound().setInteger(Constants.NBT.TICKS_REMAINING, getCooldownRemainder(stack) - 1); } public void resetCooldown(ItemStack stack) { NBTHelper.checkNBT(stack).getTagCompound().setInteger(Constants.NBT.TICKS_REMAINING, 10); } }