Example #1
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();
    }
  }