Skip to content

Instantly share code, notes, and snippets.

@SupremeMortal
Last active June 23, 2022 08:57
Show Gist options
  • Save SupremeMortal/874ee03df233d0d29976f8deb65fa079 to your computer and use it in GitHub Desktop.
Save SupremeMortal/874ee03df233d0d29976f8deb65fa079 to your computer and use it in GitHub Desktop.
level.dat Reader
package com.github.suprememortal.leveldatreader;
import com.nukkitx.nbt.stream.LittleEndianDataInputStream;
import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.tag.Tag;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class LevelDatReader {
public static void main(String[] args) {
Path path = Paths.get("level.dat"); // Same directory as jar
try (InputStream inStream = Files.newInputStream(path)) {
LittleEndianDataInputStream dataInputStream = new LittleEndianDataInputStream(new DataInputStream(inStream));
int version = dataInputStream.readInt();
int length = dataInputStream.readInt();
NBTInputStream nbtInputStream = new NBTInputStream(dataInputStream);
Tag<?> tag = nbtInputStream.readTag();
System.out.println("Version " + version);
System.out.println("Length " + length);
System.out.println(tag.toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Version 8
Length 1794
TAG_Compound: 77 entries
(
TAG_Int("lightningTime"): 12103
TAG_Byte("commandblocksenabled"): 1
TAG_Int("randomtickspeed"): 1
TAG_Int("Platform"): 2
TAG_Int("Difficulty"): 0
TAG_Byte("naturalregeneration"): 1
TAG_Byte("hasLockedResourcePack"): 0
TAG_Byte("texturePacksRequired"): 0
TAG_Byte("bonusChestEnabled"): 0
TAG_Int("GameType"): 1
TAG_Byte("isFromWorldTemplate"): 0
TAG_Byte("dofiretick"): 1
TAG_Compound("abilities"): 17 entries
(
TAG_Byte("lightning"): 0
TAG_Byte("mine"): 1
TAG_Byte("mayfly"): 0
TAG_Byte("op"): 1
TAG_Float("walkSpeed"): 0.1
TAG_Int("permissionsLevel"): 2
TAG_Byte("teleport"): 1
TAG_Byte("attackplayers"): 1
TAG_Float("flySpeed"): 0.05
TAG_Byte("instabuild"): 0
TAG_Byte("invulnerable"): 0
TAG_Byte("build"): 1
TAG_Byte("flying"): 0
TAG_Byte("attackmobs"): 1
TAG_Byte("opencontainers"): 1
TAG_Byte("doorsandswitches"): 1
TAG_Int("playerPermissionsLevel"): 2
)
TAG_Byte("hasBeenLoadedInCreative"): 1
TAG_Float("lightningLevel"): 0.62573946
TAG_Int("maxcommandchainlength"): 65535
TAG_Byte("XBLBroadcastIntent"): 1
TAG_Byte("startWithMapEnabled"): 0
TAG_Byte("bonusChestSpawned"): 0
TAG_Byte("MultiplayerGame"): 1
TAG_Byte("drowningdamage"): 1
TAG_Float("rainLevel"): 1.0
TAG_List("lastOpenedWithVersion"): 4 entries of type TAG_INT
{
TAG_Int: 1
TAG_Int: 8
TAG_Int: 0
TAG_Int: 24
}
TAG_Int("SpawnY"): 32767
TAG_Int("SpawnZ"): 0
TAG_Byte("eduLevel"): 0
TAG_Int("SpawnX"): 0
TAG_Byte("doentitydrops"): 1
TAG_String("prid"):
TAG_Int("serverChunkTickRange"): 12
TAG_Byte("pvp"): 1
TAG_Byte("keepinventory"): 0
TAG_Long("worldStartCount"): 4294967281
TAG_Byte("ForceGameType"): 1
TAG_String("LevelName"): pf8bAHOAEQQ
TAG_Byte("isWorldTemplateOptionLocked"): 0
TAG_Byte("firedamage"): 1
TAG_Byte("educationFeaturesEnabled"): 1
TAG_Int("XBLBroadcastMode"): 1
TAG_Int("Generator"): 2
TAG_Long("RandomSeed"): 1790941856
TAG_Byte("sendcommandfeedback"): 1
TAG_Byte("dodaylightcycle"): 1
TAG_Int("NetworkVersion"): 291
TAG_Long("Time"): 109091
TAG_Byte("commandblockoutput"): 1
TAG_Byte("commandsEnabled"): 1
TAG_Int("PlatformBroadcastMode"): 3
TAG_Byte("spawnMobs"): 1
TAG_Int("LimitedWorldOriginY"): 32767
TAG_Int("LimitedWorldOriginX"): 0
TAG_String("InventoryVersion"): 1.7.1
TAG_Byte("CenterMapsToOrigin"): 0
TAG_Byte("falldamage"): 1
TAG_Byte("tntexplodes"): 1
TAG_Int("LimitedWorldOriginZ"): 0
TAG_Byte("domobloot"): 1
TAG_Byte("domobspawning"): 0
TAG_Long("currentTick"): 4333091
TAG_Byte("isFromLockedTemplate"): 0
TAG_Byte("PlatformBroadcast"): 1
TAG_Int("rainTime"): 12103
TAG_Byte("doweathercycle"): 1
TAG_Byte("LANBroadcast"): 1
TAG_Byte("experimentalgameplay"): 1
TAG_Long("LastPlayed"): 1544974934
TAG_Int("NetherScale"): 8
TAG_Byte("useMsaGamertagsOnly"): 1
TAG_Byte("hasLockedBehaviorPack"): 0
TAG_Byte("doinsomnia"): 1
TAG_Byte("mobgriefing"): 1
TAG_String("FlatWorldLayers"): null
TAG_Byte("XBLBroadcast"): 1
TAG_Byte("dotiledrops"): 1
TAG_Int("StorageVersion"): 8
TAG_Byte("immutableWorld"): 0
TAG_Byte("showcoordinates"): 1
)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.suprememortal</groupId>
<artifactId>leveldatreader</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>nukkitx-repo</id>
<url>https://repo.nukkitx.com/snapshot</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.nukkitx</groupId>
<artifactId>nbt</artifactId>
<version>1.1.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<Main-Class>com.github.suprememortal.leveldatreader.LevelDatReader</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment