Example #1
0
  @Override
  /** Cycles locked state. */
  protected boolean onHammerRightClick(TEBase TE, EntityPlayer entityPlayer) {
    if (entityPlayer.isSneaking()) {

      boolean locked = !Safe.isLocked(TE);

      Safe.setLocked(TE, locked);

      if (locked) {
        Safe.setAutoPerm(TE, Safe.AUTOMATION_DISABLED);
      } else {
        Safe.setAutoPerm(TE, Safe.AUTOMATION_ALL);
      }

      if (locked) {
        ChatHandler.sendMessageToPlayer("message.safe_lock.name", entityPlayer);
      } else {
        ChatHandler.sendMessageToPlayer("message.safe_unlock.name", entityPlayer);
      }

      return true;
    } else {
      int autoPerm = Safe.getAutoPerm(TE);

      if (++autoPerm > 3) {
        autoPerm = 0;
      }

      Safe.setAutoPerm(TE, autoPerm);

      switch (autoPerm) {
        case Safe.AUTOMATION_ALL:
          ChatHandler.sendMessageToPlayer("message.automation_all.name", entityPlayer);
          break;
        case Safe.AUTOMATION_DISABLED:
          ChatHandler.sendMessageToPlayer("message.automation_disabled.name", entityPlayer);
          break;
        case Safe.AUTOMATION_RECEIVE:
          ChatHandler.sendMessageToPlayer("message.automation_insert.name", entityPlayer);
          break;
        case Safe.AUTOMATION_SEND:
          ChatHandler.sendMessageToPlayer("message.automation_extract.name", entityPlayer);
          break;
      }
    }

    return true;
  }
Example #2
0
  @Override
  /** Called upon block activation (right click on the block.) */
  protected void postOnBlockActivated(
      TEBase TE,
      EntityPlayer entityPlayer,
      int side,
      float hitX,
      float hitY,
      float hitZ,
      List<Boolean> altered,
      List<Boolean> decInv) {
    if (!Safe.isOpen(TE) && canPlayerActivate(TE, entityPlayer)) {

      TECarpentersSafe TE_safe = (TECarpentersSafe) TE;
      ItemStack itemStack = entityPlayer.getHeldItem();

      if (itemStack != null && itemStack.getItem().equals(Items.gold_ingot)) {
        if (!TE_safe.hasUpgrade()) {
          if (TE_safe.incSizeInventory()) {
            TE.getWorldObj().markBlockForUpdate(TE.xCoord, TE.yCoord, TE.zCoord);
            decInv.add(true);
            return;
          }
        }
      }

      if (!decInv.contains(true)) {
        entityPlayer.displayGUIChest((TECarpentersSafe) TE);
      }
    } else {
      ChatHandler.sendMessageToPlayer("message.block_lock.name", entityPlayer);
    }

    /*
     * Safe should always return true because it either warns the player
     * that it is locked, or it returns the GUI.
     */
    altered.add(true);
  }