парсинг level.dat - LevelInfo
This commit is contained in:
26
anvil-loader/src/main/java/mc/world/anvil/LevelInfo.java
Normal file
26
anvil-loader/src/main/java/mc/world/anvil/LevelInfo.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,29 @@
|
|||||||
package mc.world.anvil;
|
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.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
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());
|
// level.dat
|
||||||
regionFile.getChunk(0,0);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user