/** Inserts one item from the hopper into the inventory the hopper is pointing at. */
  private boolean insertItemToInventory() {
    IInventory iinventory = this.getOutputInventory();

    if (iinventory == null) {
      return false;
    } else {
      for (int i = 0; i < this.getSizeInventory(); ++i) {
        if (this.getStackInSlot(i) != null) {
          ItemStack itemstack = this.getStackInSlot(i).copy();
          ItemStack itemstack1 =
              insertStack(
                  iinventory,
                  this.decrStackSize(i, 1),
                  Facing.oppositeSide[
                      BlockHopper.getDirectionFromMetadata(this.getBlockMetadata())]);

          if (itemstack1 == null || itemstack1.stackSize == 0) {
            iinventory.onInventoryChanged();
            return true;
          }

          this.setInventorySlotContents(i, itemstack);
        }
      }

      return false;
    }
  }
Example #2
0
 private TileEntity getHopperFacing(int x, int y, int z, int meta) {
   int i = BlockHopper.getDirectionFromMetadata(meta);
   return worldObj.getBlockTileEntity(
       x + Facing.offsetsXForSide[i],
       y + Facing.offsetsYForSide[i],
       z + Facing.offsetsZForSide[i]);
 }
 /** Gets the inventory the hopper is pointing at. */
 private IInventory getOutputInventory() {
   int i = BlockHopper.getDirectionFromMetadata(this.getBlockMetadata());
   return getInventoryAtLocation(
       this.getWorldObj(),
       (double) (this.xCoord + Facing.offsetsXForSide[i]),
       (double) (this.yCoord + Facing.offsetsYForSide[i]),
       (double) (this.zCoord + Facing.offsetsZForSide[i]));
 }
  public boolean updateHopper() {
    if (this.worldObj != null && !this.worldObj.isRemote) {
      if (!this.isCoolingDown()
          && BlockHopper.getIsBlockNotPoweredFromMetadata(this.getBlockMetadata())) {
        boolean flag = this.insertItemToInventory();
        flag = suckItemsIntoHopper(this) || flag;

        if (flag) {
          this.setTransferCooldown(8);
          this.onInventoryChanged();
          return true;
        }
      }

      return false;
    } else {
      return false;
    }
  }