Пример #1
0
 public void build() {
   if (currentBuilder != null) {
     if (currentBuilder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord)) {
       updateRequirements();
     }
   }
 }
Пример #2
0
  public void updateRequirements(EntityPlayer caller) {
    List<RequirementItemStack> reqCopy = null;
    if (currentBuilder instanceof BptBuilderBlueprint) {
      currentBuilder.initialize();
      reqCopy = ((BptBuilderBlueprint) currentBuilder).neededItems;
    }

    BuildCraftCore.instance.sendToPlayer(caller, getItemRequirementsPacket(reqCopy));
  }
Пример #3
0
    /** Return false when reached the end of the iteration */
    public BptBuilderBase next() {
      while (true) {
        BptBuilderBase bpt;

        int newX = Math.round(ix);
        int newY = Math.round(iy);
        int newZ = Math.round(iz);

        bpt = instanciateBluePrint(newX, newY, newZ, o);

        if (bpt == null) {
          return null;
        }

        AxisAlignedBB boundingBox = bpt.getBoundingBox();

        if (oldBoundingBox == null || !collision(oldBoundingBox, boundingBox)) {

          oldBoundingBox = boundingBox;

          if (bpt != null) {
            return bpt;
          }
        }

        ix += cx;
        iy += cy;
        iz += cz;

        double distance =
            (ix - to.i) * (ix - to.i) + (iy - to.j) * (iy - to.j) + (iz - to.k) * (iz - to.k);

        if (distance > lastDistance) {
          return null;
        } else {
          lastDistance = distance;
        }
      }
    }
Пример #4
0
  @Override
  public void doWork() {
    if (CoreProxy.proxy.isRenderWorld(worldObj)) {
      return;
    }

    if (done) {
      return;
    }

    if (builderRobot != null && !builderRobot.readyToBuild()) {
      return;
    }

    if (powerProvider.useEnergy(25, 25, true) < 25) {
      return;
    }

    iterateBpt();

    if (bluePrintBuilder != null && !bluePrintBuilder.done) {
      if (!box.isInitialized()) {
        box.initialize(bluePrintBuilder);
      }

      if (builderRobot == null) {
        builderRobot = new EntityRobot(worldObj, box);
        worldObj.spawnEntityInWorld(builderRobot);
      }

      box.createLasers(worldObj, LaserKind.Stripes);

      builderRobot.scheduleContruction(
          bluePrintBuilder.getNextBlock(
              worldObj, new SurroundingInventory(worldObj, xCoord, yCoord, zCoord)),
          bluePrintBuilder.getContext());
    }
  }
Пример #5
0
  @Override
  public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);

    inv.writeToNBT(nbttagcompound);

    if (box.isInitialized()) {
      NBTTagCompound boxStore = new NBTTagCompound();
      box.writeToNBT(boxStore);
      nbttagcompound.setTag("box", boxStore);
    }

    if (path != null) {
      NBTTagList list = new NBTTagList();

      for (BlockIndex i : path) {
        NBTTagCompound c = new NBTTagCompound();
        i.writeTo(c);
        list.appendTag(c);
      }

      nbttagcompound.setTag("path", list);
    }

    nbttagcompound.setBoolean("done", done);
    fluidTank.writeToNBT(nbttagcompound);

    NBTTagCompound bptNBT = new NBTTagCompound();

    if (currentBuilder != null) {
      NBTTagCompound builderCpt = new NBTTagCompound();
      currentBuilder.saveBuildStateToNBT(builderCpt, this);
      bptNBT.setTag("builderState", builderCpt);
    }

    if (currentPathIterator != null) {
      NBTTagCompound iteratorNBT = new NBTTagCompound();
      new BlockIndex(
              (int) currentPathIterator.ix,
              (int) currentPathIterator.iy,
              (int) currentPathIterator.iz)
          .writeTo(iteratorNBT);
      bptNBT.setTag("iterator", iteratorNBT);
    }

    nbttagcompound.setTag("bptBuilder", bptNBT);
  }
Пример #6
0
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (worldObj.isRemote) {
      return;
    }

    if ((currentBuilder == null || currentBuilder.isDone(this)) && box.isInitialized()) {
      box.reset();

      sendNetworkUpdate();

      return;
    }

    iterateBpt(false);

    if (mode != Mode.Off) {
      if (getWorldObj().getWorldInfo().getGameType() == GameType.CREATIVE) {
        build();
      } else if (getBattery().getEnergyStored() > POWER_ACTIVATION) {
        build();
      }
    }

    if (!isBuilding && this.isBuildingBlueprint()) {
      updateRequirements();
    }
    isBuilding = this.isBuildingBlueprint();

    if (done) {
      return;
    } else if (getBattery().getEnergyStored() < 25) {
      return;
    }
  }
Пример #7
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();
    }
  }
Пример #8
0
  @Override
  public void initialize() {
    super.initialize();

    if (worldObj.isRemote) {
      return;
    }

    if (initNBT != null) {
      iterateBpt(true);

      if (initNBT.hasKey("iterator")) {
        BlockIndex expectedTo = new BlockIndex(initNBT.getCompoundTag("iterator"));

        while (!done && currentBuilder != null && currentPathIterator != null) {
          BlockIndex bi =
              new BlockIndex(
                  (int) currentPathIterator.ix,
                  (int) currentPathIterator.iy,
                  (int) currentPathIterator.iz);

          if (bi.equals(expectedTo)) {
            break;
          }

          iterateBpt(true);
        }
      }

      if (currentBuilder != null) {
        currentBuilder.loadBuildStateToNBT(initNBT.getCompoundTag("builderState"), this);
      }

      initNBT = null;
    }

    box.kind = Kind.STRIPES;

    for (int x = xCoord - 1; x <= xCoord + 1; ++x) {
      for (int y = yCoord - 1; y <= yCoord + 1; ++y) {
        for (int z = zCoord - 1; z <= zCoord + 1; ++z) {
          TileEntity tile = worldObj.getTileEntity(x, y, z);

          if (tile instanceof TilePathMarker) {
            path = ((TilePathMarker) tile).getPath();

            for (BlockIndex b : path) {
              worldObj.setBlockToAir(b.x, b.y, b.z);

              BuildCraftBuilders.pathMarkerBlock.dropBlockAsItem(worldObj, b.x, b.y, b.z, 0, 0);
            }

            break;
          }
        }
      }
    }

    if (path != null && pathLasers.size() == 0) {
      createLasersForPath();

      sendNetworkUpdate();
    }

    iterateBpt(false);
  }