@SubscribeEvent
  public void keyDown(TickEvent.ClientTickEvent event) {
    if (Battlegear.battlegearEnabled) {
      // null checks to prevent any crash outside the world (and to make sure we have no screen
      // open)
      if (mc.thePlayer != null && mc.theWorld != null && mc.currentScreen == null) {
        EntityPlayer player = mc.thePlayer;
        if (event.phase == TickEvent.Phase.START) {
          if (!specialDone
              && special.isKeyDown()
              && ((IBattlePlayer) player).getSpecialActionTimer() == 0) {
            ItemStack quiver = QuiverArrowRegistry.getArrowContainer(player);

            if (quiver != null) {
              FMLProxyPacket p =
                  new BattlegearAnimationPacket(EnumBGAnimations.SpecialAction, player)
                      .generatePacket();
              Battlegear.packetHandler.sendPacketToServer(p);
              ((IBattlePlayer) player).setSpecialActionTimer(2);
            } else if (((IBattlePlayer) player).isBattlemode()) {
              ItemStack offhand =
                  ((InventoryPlayerBattle) player.inventory).getCurrentOffhandWeapon();

              if (offhand != null && offhand.getItem() instanceof IShield) {
                float shieldBashPenalty =
                    0.33F
                        - 0.06F
                            * EnchantmentHelper.getEnchantmentLevel(
                                BaseEnchantment.bashWeight, offhand);

                if (blockBar >= shieldBashPenalty) {
                  FMLProxyPacket p =
                      new BattlegearAnimationPacket(EnumBGAnimations.SpecialAction, player)
                          .generatePacket();
                  Battlegear.packetHandler.sendPacketToServer(p);
                  ((IBattlePlayer) player)
                      .setSpecialActionTimer(((IShield) offhand.getItem()).getBashTimer(offhand));

                  blockBar -= shieldBashPenalty;
                }
              }
            }
            specialDone = true;
          } else if (specialDone && !special.isKeyDown()) {
            specialDone = false;
          }
          if (!drawDone && drawWeapons.isKeyDown()) {
            if (((IBattlePlayer) player).isBattlemode()) {
              previousBattlemode = player.inventory.currentItem;
              player.inventory.currentItem = previousNormal;
            } else {
              previousNormal = player.inventory.currentItem;
              player.inventory.currentItem = previousBattlemode;
            }
            mc.playerController.syncCurrentPlayItem();
            drawDone = true;
          } else if (drawDone && !drawWeapons.isKeyDown()) {
            drawDone = false;
          }
          inBattle = ((IBattlePlayer) player).isBattlemode();
        } else {
          if (inBattle && !((IBattlePlayer) player).isBattlemode()) {
            for (int i = 0; i < InventoryPlayerBattle.WEAPON_SETS; ++i) {
              if (mc.gameSettings.keyBindsHotbar[i].isKeyDown()) {
                previousBattlemode = InventoryPlayerBattle.OFFSET + i;
              }
            }
            player.inventory.currentItem = previousBattlemode;
            mc.playerController.syncCurrentPlayItem();
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 /**
  * Could be abstracted, but using the registry is easier
  *
  * @return the stack to be picked up, if any
  */
 public ItemStack getPickedUpItem() {
   return QuiverArrowRegistry.getItem(this.getClass());
 }