Ejemplo n.º 1
0
  @Override
  public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer) {

    ItemStack current = entityplayer.inventory.getCurrentItem();
    if (current != null) {

      int liquidId = LiquidManager.getLiquidIDForFilledItem(current);

      TileTank tank = (TileTank) world.getBlockTileEntity(i, j, k);

      if (liquidId != 0) {
        int qty = tank.fill(Orientations.Unknown, BuildCraftAPI.BUCKET_VOLUME, liquidId, true);

        if (qty != 0 && !BuildCraftCore.debugMode) {
          entityplayer.inventory.setInventorySlotContents(
              entityplayer.inventory.currentItem, Utils.consumeItem(current));
        }

        return true;
      } else {
        ItemStack filled = LiquidManager.fillLiquidContainer(tank.getLiquidId(), current);

        int qty = tank.empty(BuildCraftAPI.BUCKET_VOLUME, false);

        if (filled != null && qty >= BuildCraftAPI.BUCKET_VOLUME) {
          if (current.stackSize > 1 && !entityplayer.inventory.addItemStackToInventory(filled)) {
            return false;
          }
          entityplayer.inventory.setInventorySlotContents(
              entityplayer.inventory.currentItem, Utils.consumeItem(current));
          tank.empty(BuildCraftAPI.BUCKET_VOLUME, true);
          return true;
        }
      }
    }

    return false;
  }
Ejemplo n.º 2
0
  @Override
  public void update() {
    super.update();

    ItemStack itemInInventory = tile.getStackInSlot(0);

    if (itemInInventory != null) {
      int liquidId = BuildCraftAPI.getLiquidForFilledItem(itemInInventory);

      if (liquidId != 0) {
        if (fill(Orientations.Unknown, BuildCraftAPI.BUCKET_VOLUME, liquidId, false)
            == BuildCraftAPI.BUCKET_VOLUME) {
          fill(Orientations.Unknown, BuildCraftAPI.BUCKET_VOLUME, liquidId, true);

          tile.setInventorySlotContents(0, Utils.consumeItem(itemInInventory));
        }
      }
    }

    if (heat > COOLANT_THRESHOLD) {
      int extraHeat = heat - COOLANT_THRESHOLD;

      if (coolantQty > extraHeat) {
        coolantQty -= extraHeat;
        heat = COOLANT_THRESHOLD;
      } else {
        heat -= coolantQty;
        coolantQty = 0;
      }
    }

    if (heat > 0 && (penatlyCooling > 0 || !tile.isRedstonePowered)) {
      heat -= 10;
    }

    if (heat <= 0 && penatlyCooling > 0) {
      penatlyCooling--;
    }
  }
Ejemplo n.º 3
0
  @Override
  public void throttledUpdateEntity() {

    if (!((CoreRoutedPipe) this.container.pipe).isEnabled()) {
      return;
    }

    if (APIProxy.isClient(worldObj)) return;
    if (pause) return;
    super.throttledUpdateEntity();
    WorldUtil worldUtil = new WorldUtil(worldObj, xCoord, yCoord, zCoord);
    for (AdjacentTile tile : worldUtil.getAdjacentTileEntities()) {
      if (tile.tile instanceof TileGenericPipe) continue;
      if (!(tile.tile instanceof IInventory)) continue;

      // Do not attempt to supply redstone engines
      if (tile.tile instanceof TileEngine && ((TileEngine) tile.tile).engine instanceof EngineWood)
        continue;

      IInventory inv = Utils.getInventory((IInventory) tile.tile);
      if (inv.getSizeInventory() < 1) continue;
      InventoryUtil invUtil = _invUtilFactory.getInventoryUtil(inv);

      // How many do I want?
      HashMap<ItemIdentifier, Integer> needed = _dummyInvUtil.getItemsAndCount();

      // How many do I have?
      HashMap<ItemIdentifier, Integer> have = invUtil.getItemsAndCount();

      // Reduce what I have
      for (ItemIdentifier item : needed.keySet()) {
        if (have.containsKey(item)) {
          needed.put(item, needed.get(item) - have.get(item));
        }
      }

      // Reduce what have been requested already
      for (ItemIdentifier item : needed.keySet()) {
        if (_requestedItems.containsKey(item)) {
          needed.put(item, needed.get(item) - _requestedItems.get(item));
        }
      }

      ((PipeItemsSupplierLogistics) this.container.pipe).setRequestFailed(false);

      // Make request
      for (ItemIdentifier need : needed.keySet()) {
        if (needed.get(need) < 1) continue;
        int neededCount = needed.get(need);
        boolean success = false;
        do {
          success =
              LogisticsManager.Request(
                  new LogisticsRequest(need, neededCount, (IRequestItems) container.pipe),
                  getRouter().getRoutersByCost(),
                  null);
          if (success || neededCount == 1) {
            break;
          }
          neededCount = neededCount / 2;
        } while (_requestPartials && !success);

        if (success) {
          if (!_requestedItems.containsKey(need)) {
            _requestedItems.put(need, neededCount);
          } else {
            _requestedItems.put(need, _requestedItems.get(need) + neededCount);
          }
        } else {
          ((PipeItemsSupplierLogistics) this.container.pipe).setRequestFailed(true);
        }
      }
    }
  }
Ejemplo n.º 4
0
 public boolean isInput(TileEntity tile) {
   return !(tile instanceof TileGenericPipe)
       && (tile instanceof IInventory || tile instanceof ILiquidContainer)
       && Utils.checkPipesConnections(container, tile);
 }