Exemplo n.º 1
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);
  }
Exemplo n.º 2
0
  @Override
  /** ejects contained items into the world, and notifies neighbours of an update, as appropriate */
  public void breakBlock(World world, int x, int y, int z, Block block, int metadata) {
    TEBase TE = getTileEntityStrict(world, x, y, z);

    if (TE != null) {

      TECarpentersSafe TE_safe = (TECarpentersSafe) TE;

      if (TE_safe.hasUpgrade()) {
        BlockProperties.ejectEntity(TE, new ItemStack(Items.gold_ingot));
      }

      for (int slot = 0; slot < TE_safe.getSizeInventory(); ++slot) {
        ItemStack itemStack = TE_safe.getStackInSlot(slot);

        if (itemStack != null) {
          BlockProperties.ejectEntity(TE, itemStack);
        }
      }
    }
    super.breakBlock(world, x, y, z, block, metadata);
  }