Beispiel #1
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();
  }
Beispiel #2
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);
  }
Beispiel #3
0
  @Override
  public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    super.receiveCommand(command, side, sender, stream);
    if (side.isClient()) {
      if ("clearItemRequirements".equals(command)) {
        requiredToBuild = null;
      } else if ("setItemRequirements".equals(command)) {
        int size = stream.readUnsignedMedium();
        requiredToBuild = new ArrayList<RequirementItemStack>();
        for (int i = 0; i < size; i++) {
          int itemId = stream.readUnsignedShort();
          int itemDamage = stream.readShort();
          int stackSize = stream.readUnsignedMedium();
          boolean hasCompound = stackSize >= 0x800000;

          ItemStack stack = new ItemStack(Item.getItemById(itemId), 1, itemDamage);
          if (hasCompound) {
            stack.setTagCompound(NetworkUtils.readNBT(stream));
          }

          if (stack != null && stack.getItem() != null) {
            requiredToBuild.add(new RequirementItemStack(stack, stackSize & 0x7FFFFF));
          } else {
            BCLog.logger.error(
                "Corrupt ItemStack in TileBuilder.receiveCommand! This should not happen! (ID "
                    + itemId
                    + ", damage "
                    + itemDamage
                    + ")");
          }
        }
      }
    } else if (side.isServer()) {
      EntityPlayer player = (EntityPlayer) sender;
      if ("eraseFluidTank".equals(command)) {
        int id = stream.readInt();
        if (id < 0 || id >= fluidTanks.length) {
          return;
        }
        if (isUseableByPlayer(player) && player.getDistanceSq(xCoord, yCoord, zCoord) <= 64) {
          fluidTanks[id].setFluid(null);
          sendNetworkUpdate();
        }
      }
    }
  }
Beispiel #4
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;
    }
  }
Beispiel #5
0
 @Override
 public void readData(ByteBuf stream) {
   super.readData(stream);
   box.readData(stream);
   fluidTank.readData(stream);
 }
Beispiel #6
0
 @Override
 public void writeData(ByteBuf stream) {
   super.writeData(stream);
   box.writeData(stream);
   fluidTank.writeData(stream);
 }
Beispiel #7
0
 @Override
 public void invalidate() {
   super.invalidate();
   destroy();
 }
Beispiel #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);
  }