protected void streamACK(String identifier, int identifierACK) {
   byte[] buffer =
       Binary.appendBytes(
           RakNet.PACKET_ACK_NOTIFICATION,
           new byte[] {(byte) (identifier.length() & 0xff)},
           identifier.getBytes(StandardCharsets.UTF_8),
           Binary.writeInt(identifierACK));
   this.server.pushThreadToMainPacket(buffer);
 }
示例#2
0
  @Override
  public AsyncTask requestChunkTask(int x, int z) throws ChunkException {
    FullChunk chunk = this.getChunk(x, z, false);
    if (chunk == null) {
      throw new ChunkException("Invalid Chunk Set");
    }

    byte[] tiles = new byte[0];

    if (!chunk.getTiles().isEmpty()) {
      List<CompoundTag> tagList = new ArrayList<>();

      for (Tile tile : chunk.getTiles().values()) {
        if (tile instanceof Spawnable) {
          tagList.add(((Spawnable) tile).getSpawnCompound());
        }
      }

      try {
        tiles = NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }

    BinaryStream extraData = new BinaryStream();
    extraData.putLInt(chunk.getBlockExtraDataArray().size());
    for (Integer key : chunk.getBlockExtraDataArray().values()) {
      extraData.putLInt(key);
      extraData.putLShort(chunk.getBlockExtraDataArray().get(key));
    }

    BinaryStream stream = new BinaryStream();
    stream.put(chunk.getBlockIdArray());
    stream.put(chunk.getBlockDataArray());
    stream.put(chunk.getBlockSkyLightArray());
    stream.put(chunk.getBlockLightArray());
    for (int height : chunk.getHeightMapArray()) {
      stream.putByte((byte) (height & 0xff));
    }
    for (int color : chunk.getBiomeColorArray()) {
      stream.put(Binary.writeInt(color));
    }
    stream.put(extraData.getBuffer());
    stream.put(tiles);

    this.getLevel()
        .chunkRequestCallback(x, z, stream.getBuffer(), FullChunkDataPacket.ORDER_LAYERED);

    return null;
  }