private void handleLeftoverItems(IInventory items) {
    for (int i = 0; i < items.getSizeInventory(); i++) {
      if (items.getStackInSlot(i) != null) {
        ItemStack output = items.getStackInSlot(i);

        if (output.stackSize <= 0) {
          items.setInventorySlotContents(i, null);
          continue;
        }

        boolean inserted = false;

        for (int j = 2; j <= 4; j++) {
          ItemStack target = getStackInSlot(j);

          if (target == null || target.stackSize <= 0) {
            setInventorySlotContents(j, output);
            inserted = true;
            break;
          } else {
            output.stackSize -= StackHelper.mergeStacks(output, target, true);
            if (output.stackSize == 0) {
              inserted = true;
              break;
            }
          }
        }

        if (!inserted) {
          if (output.stackSize > 0) {
            output.stackSize -=
                Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, output);

            if (output.stackSize > 0) {
              InvUtils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord);
            }
          }
        }

        items.setInventorySlotContents(i, null);
      }
    }
  }
Beispiel #2
0
  public void iterateBpt(boolean forceIterate) {
    if (getStackInSlot(0) == null || !(getStackInSlot(0).getItem() instanceof ItemBlueprint)) {
      if (box.isInitialized()) {
        if (currentBuilder != null) {
          currentBuilder = null;
        }

        if (box.isInitialized()) {
          box.reset();
        }

        if (currentPathIterator != null) {
          currentPathIterator = null;
        }

        updateRequirements();

        sendNetworkUpdate();

        return;
      }
    }

    if (currentBuilder == null || (currentBuilder.isDone(this) || forceIterate)) {
      if (path != null && path.size() > 1) {
        if (currentPathIterator == null) {
          Iterator<BlockIndex> it = path.iterator();
          BlockIndex start = it.next();
          currentPathIterator =
              new PathIterator(
                  start,
                  it,
                  ForgeDirection.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)]
                      .getOpposite());
        }

        if (currentBuilder != null && currentBuilder.isDone(this)) {
          currentBuilder.postProcessing(worldObj);
        }

        currentBuilder = currentPathIterator.next();

        if (currentBuilder != null) {
          box.reset();
          box.initialize(currentBuilder);
          sendNetworkUpdate();
        }

        if (currentBuilder == null) {
          currentPathIterator = currentPathIterator.iterate();
        }

        if (currentPathIterator == null) {
          done = true;
        } else {
          done = false;
        }

        updateRequirements();
      } else {
        if (currentBuilder != null && currentBuilder.isDone(this)) {
          currentBuilder.postProcessing(worldObj);
          currentBuilder = recursiveBuilder.nextBuilder();

          updateRequirements();
        } else {
          BlueprintBase bpt = instanciateBlueprint();

          if (bpt != null) {
            recursiveBuilder =
                new RecursiveBlueprintBuilder(
                    bpt,
                    worldObj,
                    xCoord,
                    yCoord,
                    zCoord,
                    ForgeDirection.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)]
                        .getOpposite());

            currentBuilder = recursiveBuilder.nextBuilder();

            updateRequirements();
          }
        }

        if (currentBuilder == null) {
          done = true;
        } else {
          box.initialize(currentBuilder);
          sendNetworkUpdate();
          done = false;
        }
      }
    }

    if (done && getStackInSlot(0) != null) {
      boolean dropBlueprint = true;
      for (int i = 1; i < getSizeInventory(); ++i) {
        if (getStackInSlot(i) == null) {
          setInventorySlotContents(i, getStackInSlot(0));
          dropBlueprint = false;
          break;
        }
      }
      if (dropBlueprint) {
        InvUtils.dropItems(getWorldObj(), getStackInSlot(0), xCoord, yCoord, zCoord);
      }

      setInventorySlotContents(0, null);
      box.reset();
    }
  }