Archived
0

парсинг level.dat - LevelInfo

This commit is contained in:
2018-10-14 00:47:39 +03:00
parent 35ecd49ce3
commit 56b6487d8a
2 changed files with 44 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
package mc.world.anvil;
import com.flowpowered.nbt.*;
import lombok.Getter;
import lombok.ToString;
import mc.core.world.block.BlockLocation;
@Getter
@ToString
class LevelInfo {
private long seed;
private BlockLocation spawn;
private int version;
LevelInfo(CompoundTag levelDatTag) {
CompoundMap dataMapTag = ((CompoundTag) levelDatTag.getValue().get("Data")).getValue();
seed = ((LongTag) dataMapTag.get("RandomSeed")).getValue();
spawn = new BlockLocation(
((IntTag) dataMapTag.get("SpawnX")).getValue(),
((IntTag) dataMapTag.get("SpawnY")).getValue(),
((IntTag) dataMapTag.get("SpawnZ")).getValue()
);
version = ((IntTag) dataMapTag.get("version")).getValue();
}
}

View File

@@ -1,14 +1,29 @@
package mc.world.anvil;
import com.flowpowered.nbt.CompoundTag;
import com.flowpowered.nbt.Tag;
import com.flowpowered.nbt.stream.NBTInputStream;
import lombok.extern.slf4j.Slf4j;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
@Slf4j
public class Main {
public static void main(String[] args) throws IOException {
final Path levelDatPath = Paths.get(args[0]);
final Path worldPath = Paths.get(args[0]);
RegionFile regionFile = new RegionFile(levelDatPath.toFile());
regionFile.getChunk(0,0);
// level.dat
FileInputStream fis = new FileInputStream(worldPath.resolve("level.dat").toFile());
NBTInputStream nbtInputStream = new NBTInputStream(fis);
Tag rootTag = nbtInputStream.readTag();
LevelInfo levelInfo = new LevelInfo((CompoundTag) rootTag);
nbtInputStream.close();
fis.close();
log.info(levelInfo.toString());
}
}