示例#1
0
  @Override
  public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);

    Utils.writeStacksToNBT(nbttagcompound, "Items", items);

    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);
  }
示例#2
0
  public void createUtilsIfNeeded() {
    if (bluePrintBuilder == null) {

      if (!box.isInitialized()) {
        setBoundaries(loadDefaultBoundaries);
      }

      initializeBluePrintBuilder();
    }

    if (builderDone) {

      box.deleteLasers();

      if (arm == null) {
        createArm();
      }

      if (findTarget(false)) {
        isDigging = true;
      }

    } else {

      box.createLasers(worldObj, LaserKind.Stripes);
      isDigging = true;
    }
  }
示例#3
0
  @Override
  public void handleUpdatePacket(PacketUpdate packet) {
    boolean initialized = box.isInitialized();

    super.handleUpdatePacket(packet);

    if (!initialized && box.isInitialized()) {
      box.createLasers(worldObj, LaserKind.Stripes);
    }
  }
示例#4
0
  @Override
  public AxisAlignedBB getRenderBoundingBox() {
    Box renderBox = new Box(this).extendToEncompass(box);

    for (LaserData l : pathLasers) {
      renderBox = renderBox.extendToEncompass(l.head);
      renderBox = renderBox.extendToEncompass(l.tail);
    }

    return renderBox.expand(50).getBoundingBox();
  }
示例#5
0
  @Override
  public void destroy() {
    if (box.isInitialized()) {
      box.deleteLasers();
    }

    if (builderRobot != null) {
      builderRobot.setDead();
      builderRobot = null;
    }

    cleanPathLasers();
  }
示例#6
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);

    inv.readFromNBT(nbttagcompound);

    if (nbttagcompound.hasKey("box")) {
      box.initialize(nbttagcompound.getCompoundTag("box"));
    }

    if (nbttagcompound.hasKey("path")) {
      path = new LinkedList<BlockIndex>();
      NBTTagList list = nbttagcompound.getTagList("path", Constants.NBT.TAG_COMPOUND);

      for (int i = 0; i < list.tagCount(); ++i) {
        path.add(new BlockIndex(list.getCompoundTagAt(i)));
      }
    }

    done = nbttagcompound.getBoolean("done");
    fluidTank.readFromNBT(nbttagcompound);

    // The rest of load has to be done upon initialize.
    initNBT = (NBTTagCompound) nbttagcompound.getCompoundTag("bptBuilder").copy();
  }
示例#7
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);
  }
示例#8
0
  @Override
  public Template getTemplate(Box box, World world) {
    int xMin = (int) box.pMin().x;
    int yMin = (int) box.pMin().y;
    int zMin = (int) box.pMin().z;

    int xMax = (int) box.pMax().x;
    int yMax = (int) box.pMax().y;
    int zMax = (int) box.pMax().z;

    Template bpt = new Template(xMax - xMin + 1, yMax - yMin + 1, zMax - zMin + 1);

    int xSize = xMax - xMin + 1;
    int zSize = zMax - zMin + 1;

    int step = 0;
    int height;

    int stepY = 1;

    if (param1) {
      stepY = 1;
    } else {
      stepY = -1;
    }

    if (stepY == 1) {
      height = yMin;
    } else {
      height = yMax;
    }

    while (step <= xSize / 2 && step <= zSize / 2 && height >= yMin && height <= yMax) {
      for (int x = xMin + step; x <= xMax - step; ++x) {
        for (int z = zMin + step; z <= zMax - step; ++z) {
          bpt.contents[x - xMin][height - yMin][z - zMin] = new SchematicMask(true);
        }
      }

      step++;
      height += stepY;
    }

    return bpt;
  }
示例#9
0
  public Box rotateLeft() {
    Box nBox = new Box();
    nBox.xMin = (sizeZ() - 1) - zMin;
    nBox.yMin = yMin;
    nBox.zMin = xMin;

    nBox.xMax = (sizeZ() - 1) - zMax;
    nBox.yMax = yMax;
    nBox.zMax = xMax;

    nBox.reorder();

    return nBox;
  }
示例#10
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());
    }
  }
示例#11
0
  @Override
  public void destroy() {

    if (arm != null) {
      arm.setDead();
    }

    if (builder != null) {
      builder.setDead();
    }

    box.deleteLasers();
    arm = null;
  }
示例#12
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;
    }
  }
示例#13
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);

    PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound);

    if (nbttagcompound.hasKey("box")) {
      box.initialize(nbttagcompound.getCompoundTag("box"));

      loadDefaultBoundaries = false;
    } else if (nbttagcompound.hasKey("xSize")) {
      // This is a legacy save, get old data

      int xMin = nbttagcompound.getInteger("xMin");
      int zMin = nbttagcompound.getInteger("zMin");

      int xSize = nbttagcompound.getInteger("xSize");
      int ySize = nbttagcompound.getInteger("ySize");
      int zSize = nbttagcompound.getInteger("zSize");

      box.initialize(xMin, yCoord, zMin, xMin + xSize - 1, yCoord + ySize - 1, zMin + zSize - 1);

      loadDefaultBoundaries = false;
    } else {
      // This is a legacy save, compute boundaries

      loadDefaultBoundaries = true;
    }

    targetX = nbttagcompound.getInteger("targetX");
    targetY = nbttagcompound.getInteger("targetY");
    targetZ = nbttagcompound.getInteger("targetZ");
    headPosX = nbttagcompound.getDouble("headPosX");
    headPosY = nbttagcompound.getDouble("headPosY");
    headPosZ = nbttagcompound.getDouble("headPosZ");
  }
示例#14
0
  @Override
  public void updateEntity() {

    super.updateEntity();

    if ((bluePrintBuilder == null || bluePrintBuilder.done)
        && box.isInitialized()
        && (builderRobot == null || builderRobot.done())) {

      box.deleteLasers();
      box.reset();

      if (CoreProxy.proxy.isSimulating(worldObj)) {
        sendNetworkUpdate();
      }

      return;
    }

    if (!box.isInitialized() && bluePrintBuilder == null && builderRobot != null) {
      builderRobot.setDead();
      builderRobot = null;
    }
  }
示例#15
0
  @Override
  public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);

    PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound);

    nbttagcompound.setInteger("targetX", targetX);
    nbttagcompound.setInteger("targetY", targetY);
    nbttagcompound.setInteger("targetZ", targetZ);
    nbttagcompound.setDouble("headPosX", headPosX);
    nbttagcompound.setDouble("headPosY", headPosY);
    nbttagcompound.setDouble("headPosZ", headPosZ);

    NBTTagCompound boxTag = new NBTTagCompound();
    box.writeToNBT(boxTag);
    nbttagcompound.setTag("box", boxTag);
  }
示例#16
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);

    Utils.readStacksFromNBT(nbttagcompound, "Items", items);

    if (nbttagcompound.hasKey("box")) {
      box.initialize(nbttagcompound.getCompoundTag("box"));
    }

    if (nbttagcompound.hasKey("path")) {
      path = new LinkedList<BlockIndex>();
      NBTTagList list = nbttagcompound.getTagList("path");

      for (int i = 0; i < list.tagCount(); ++i) {
        path.add(new BlockIndex((NBTTagCompound) list.tagAt(i)));
      }
    }

    done = nbttagcompound.getBoolean("done");
  }
示例#17
0
  private void initializeBluePrintBuilder() {

    BptBlueprint bluePrint = new BptBlueprint(box.sizeX(), box.sizeY(), box.sizeZ());

    for (int i = 0; i < bluePrint.sizeX; ++i) {
      for (int j = 0; j < bluePrint.sizeY; ++j) {
        for (int k = 0; k < bluePrint.sizeZ; ++k) {
          bluePrint.setBlockId(i, j, k, 0);
        }
      }
    }

    for (int it = 0; it < 2; it++) {
      for (int i = 0; i < bluePrint.sizeX; ++i) {
        bluePrint.setBlockId(i, it * (box.sizeY() - 1), 0, BuildCraftFactory.frameBlock.blockID);
        bluePrint.setBlockId(
            i, it * (box.sizeY() - 1), bluePrint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID);
      }

      for (int k = 0; k < bluePrint.sizeZ; ++k) {
        bluePrint.setBlockId(0, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID);
        bluePrint.setBlockId(
            bluePrint.sizeX - 1, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID);
      }
    }

    for (int h = 1; h < box.sizeY(); ++h) {
      bluePrint.setBlockId(0, h, 0, BuildCraftFactory.frameBlock.blockID);
      bluePrint.setBlockId(0, h, bluePrint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID);
      bluePrint.setBlockId(bluePrint.sizeX - 1, h, 0, BuildCraftFactory.frameBlock.blockID);
      bluePrint.setBlockId(
          bluePrint.sizeX - 1, h, bluePrint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID);
    }

    bluePrintBuilder = new BptBuilderBlueprint(bluePrint, worldObj, box.xMin, yCoord, box.zMin);
  }
示例#18
0
  public void iterateBpt() {
    if (items[0] == null || !(items[0].getItem() instanceof ItemBptBase)) {

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

      if (builderRobot != null) {
        builderRobot.setDead();
        builderRobot = null;
      }

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

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

      return;
    }

    if (bluePrintBuilder == null || bluePrintBuilder.done) {
      if (path != null && path.size() > 1) {
        if (currentPathIterator == null) {
          Iterator<BlockIndex> it = path.iterator();
          BlockIndex start = it.next();
          currentPathIterator = new PathIterator(start, it);
        }

        if (bluePrintBuilder != null && builderRobot != null) {
          builderRobot.markEndOfBlueprint(bluePrintBuilder);
        }

        bluePrintBuilder = currentPathIterator.next();

        if (bluePrintBuilder != null) {
          box.deleteLasers();
          box.reset();
          box.initialize(bluePrintBuilder);
          box.createLasers(worldObj, LaserKind.Stripes);
        }

        if (builderRobot != null) {
          builderRobot.setBox(box);
        }

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

        if (currentPathIterator == null) {
          done = true;
        }
      } else {
        if (bluePrintBuilder != null && bluePrintBuilder.done) {
          if (builderRobot != null) {
            builderRobot.markEndOfBlueprint(bluePrintBuilder);
          }

          done = true;
          bluePrintBuilder = null;
        } else {
          bluePrintBuilder =
              instanciateBluePrint(
                  xCoord,
                  yCoord,
                  zCoord,
                  Orientations.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)]
                      .reverse());

          if (bluePrintBuilder != null) {
            box.initialize(bluePrintBuilder);
            box.createLasers(worldObj, LaserKind.Stripes);
          }
        }
      }
    }
  }
示例#19
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);
  }
示例#20
0
 @Override
 public void writeData(ByteBuf stream) {
   super.writeData(stream);
   box.writeData(stream);
   fluidTank.writeData(stream);
 }
示例#21
0
  private void setBoundaries(boolean useDefault) {

    IAreaProvider a = null;

    if (!useDefault) {
      a = Utils.getNearbyAreaProvider(worldObj, xCoord, yCoord, zCoord);
    }

    if (a == null) {
      a = new DefaultAreaProvider(xCoord, yCoord, zCoord, xCoord + 10, yCoord + 4, zCoord + 10);

      useDefault = true;
    }

    int xSize = a.xMax() - a.xMin() + 1;
    int ySize = a.yMax() - a.yMin() + 1;
    int zSize = a.zMax() - a.zMin() + 1;

    if (xSize < 3 || zSize < 3) {
      a = new DefaultAreaProvider(xCoord, yCoord, zCoord, xCoord + 10, yCoord + 4, zCoord + 10);

      useDefault = true;
    }

    xSize = a.xMax() - a.xMin() + 1;
    ySize = a.yMax() - a.yMin() + 1;
    zSize = a.zMax() - a.zMin() + 1;

    box.initialize(a);

    if (ySize < 5) {
      ySize = 5;
      box.yMax = box.yMin + ySize - 1;
    }

    if (useDefault) {
      int xMin = 0, zMin = 0;

      Orientations o =
          Orientations.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)].reverse();

      switch (o) {
        case XPos:
          xMin = xCoord + 1;
          zMin = zCoord - 4 - 1;
          break;
        case XNeg:
          xMin = xCoord - 9 - 2;
          zMin = zCoord - 4 - 1;
          break;
        case ZPos:
          xMin = xCoord - 4 - 1;
          zMin = zCoord + 1;
          break;
        case ZNeg:
        default:
          xMin = xCoord - 4 - 1;
          zMin = zCoord - 9 - 2;
          break;
      }

      box.initialize(xMin, yCoord, zMin, xMin + xSize - 1, yCoord + ySize - 1, zMin + zSize - 1);
    }

    a.removeFromWorld();
  }
示例#22
0
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (inProcess && arm != null) {

      arm.setArmSpeed(0);
      float energyToUse = 2 + powerProvider.getEnergyStored() / 1000;

      boolean enoughStep =
          (0.015 + energyToUse / 200F)
              > (1F
                  / 32F); // (otherwise the movement is rounded to 0 and the energy absorbed with no
                          // movement)
      if (enoughStep) {
        float energy = powerProvider.useEnergy(energyToUse, energyToUse, true);

        if (energy > 0) {
          arm.doMove(0.015 + energy / 200F);
        }
      }
    }

    if (arm != null) {
      double[] head = arm.getHead();
      headPosX = head[0];
      headPosY = head[1];
      headPosZ = head[2];

      speed = arm.getArmSpeed();
    }

    if (ProxyCore.proxy.isSimulating(worldObj)) {
      sendNetworkUpdate();
    }
    if (inProcess || !isDigging) {
      return;
    }

    createUtilsIfNeeded();

    if (bluePrintBuilder != null) {

      builderDone = bluePrintBuilder.done;
      if (!builderDone) {

        buildFrame();
        return;

      } else {

        if (builder != null && builder.done()) {

          box.deleteLasers();
          builder.setDead();
          builder = null;
        }
      }
    }

    if (builder == null) {
      dig();
    }
  }
示例#23
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();
    }
  }
示例#24
0
 @Override
 public void readData(ByteBuf stream) {
   super.readData(stream);
   box.readData(stream);
   fluidTank.readData(stream);
 }
示例#25
0
  public TileBuilder() {
    super();

    box.kind = Kind.STRIPES;
  }