public void tickEnd(EntityPlayer player) {
    ItemStack offhand = ((InventoryPlayerBattle) player.inventory).getCurrentOffhandWeapon();
    Battlegear.proxy.tryUseDynamicLight(player, offhand);
    // If we use a shield
    if (offhand != null && offhand.getItem() instanceof IShield) {
      if (mc.gameSettings.keyBindUseItem.isKeyDown() && !player.isSwingInProgress && blockBar > 0) {
        player.motionX = player.motionX / 5;
        player.motionZ = player.motionZ / 5;
      }
    }

    // If we JUST swung an Item
    if (player.swingProgressInt == 1 && !player.isSpectator()) {
      double extendedReach = BattlemodeHookContainerClass.INSTANCE.maxReachDistance(player);
      if (extendedReach
          > BattlemodeHookContainerClass.defaultReachDistance(player.capabilities.isCreativeMode)) {
        MovingObjectPosition mouseOver = Battlegear.proxy.getMouseOver(partialTick, extendedReach);
        if (mouseOver != null
            && mouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
          Entity target = mouseOver.entityHit;
          if (target instanceof EntityLivingBase
              && target != player
              && player.getDistanceToEntity(target) > mc.playerController.getBlockReachDistance()) {
            if (target.hurtResistantTime != ((EntityLivingBase) target).maxHurtResistantTime) {
              player.attackTargetEntityWithCurrentItem(target);
              // send packet
              Battlegear.packetHandler.sendPacketToServer(
                  new ReachTargetPacket(target).generatePacket());
            }
          }
        }
      }
    }
  }
 public void tryCheckUseItem(ItemStack offhand, EntityPlayer player) {
   MovingObjectPosition mouseOver = mc.objectMouseOver;
   boolean flag = true;
   if (mouseOver != null && mouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
     BlockPos pos = mouseOver.getBlockPos();
     if (!player.worldObj.getBlockState(pos).getBlock().isAir(player.worldObj, pos)) {
       final int size = offhand.stackSize;
       EnumFacing i1 = mouseOver.sideHit;
       PlayerEventChild.UseOffhandItemEvent useItemEvent =
           new PlayerEventChild.UseOffhandItemEvent(
               new PlayerInteractEvent(
                   player, PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK, pos, i1, player.worldObj),
               offhand);
       if (!MinecraftForge.EVENT_BUS.post(useItemEvent)) {
         BattlegearUtils.refreshAttributes(player, false);
         boolean result =
             onPlayerPlaceBlock(
                 mc.playerController, player, useItemEvent.offhand, pos, i1, mouseOver.hitVec);
         BattlegearUtils.refreshAttributes(player, true);
         if (result) {
           if (useItemEvent.swingOffhand)
             BattlegearUtils.sendOffSwingEvent(useItemEvent.event, useItemEvent.offhand);
           flag = false;
         }
       }
       if (useItemEvent.offhand.stackSize == 0) {
         BattlegearUtils.setPlayerOffhandItem(player, null);
       } else if (useItemEvent.offhand.stackSize != size
           || mc.playerController.isInCreativeMode()) {
         ((IOffhandRender) mc.entityRenderer.itemRenderer).setEquippedProgress(0.0F);
       }
     }
   }
   if (flag) {
     offhand = ((InventoryPlayerBattle) player.inventory).getCurrentOffhandWeapon();
     PlayerEventChild.UseOffhandItemEvent useItemEvent =
         new PlayerEventChild.UseOffhandItemEvent(
             new PlayerInteractEvent(
                 player,
                 PlayerInteractEvent.Action.RIGHT_CLICK_AIR,
                 new BlockPos(0, 0, 0),
                 null,
                 player.worldObj),
             offhand);
     if (offhand != null && !MinecraftForge.EVENT_BUS.post(useItemEvent)) {
       if (!mc.playerController.isSpectatorMode()) {
         BattlegearUtils.refreshAttributes(player, false);
         flag = BattlemodeHookContainerClass.tryUseItem(player, useItemEvent.offhand, Side.CLIENT);
         BattlegearUtils.refreshAttributes(player, true);
         if (flag) {
           if (useItemEvent.swingOffhand)
             BattlegearUtils.sendOffSwingEvent(useItemEvent.event, useItemEvent.offhand);
           ((IOffhandRender) mc.entityRenderer.itemRenderer).setEquippedProgress(0.0F);
         }
       }
     }
   }
 }