Пример #1
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;
  }
Пример #2
0
  public static void generate(
      String path,
      String name,
      long seed,
      Class<? extends Generator> generator,
      Map<String, String> options)
      throws IOException {
    if (!new File(path + "/region").exists()) {
      new File(path + "/region").mkdirs();
    }

    CompoundTag levelData =
        new CompoundTag("Data")
            .putCompound("GameRules", new CompoundTag())
            .putLong("DayTime", 0)
            .putInt("GameType", 0)
            .putString("generatorName", Generator.getGeneratorName(generator))
            .putString(
                "generatorOptions", options.containsKey("preset") ? options.get("preset") : "")
            .putInt("generatorVersion", 1)
            .putBoolean("hardcore", false)
            .putBoolean("initialized", true)
            .putLong("LastPlayed", System.currentTimeMillis() / 1000)
            .putString("LevelName", name)
            .putBoolean("raining", false)
            .putInt("rainTime", 0)
            .putLong("RandomSeed", seed)
            .putInt("SpawnX", 128)
            .putInt("SpawnY", 70)
            .putInt("SpawnZ", 128)
            .putBoolean("thundering", false)
            .putInt("thunderTime", 0)
            .putInt("version", 19133)
            .putLong("Time", 0)
            .putLong("SizeOnDisk", 0);

    NBTIO.writeGZIPCompressed(
        new CompoundTag().putCompound("Data", levelData),
        new FileOutputStream(path + "level.dat"),
        ByteOrder.BIG_ENDIAN);
  }