Update to newer NBT library
This commit is contained in:
parent
8d4b49f99c
commit
278c168036
@ -11,7 +11,6 @@
|
|||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry exported="true" kind="lib" path="lib/JNBT_1.3.jar"/>
|
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
|
BIN
lib/JNBT_1.3.jar
BIN
lib/JNBT_1.3.jar
Binary file not shown.
11
pom.xml
11
pom.xml
@ -25,6 +25,12 @@
|
|||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
@ -54,5 +60,10 @@
|
|||||||
<version>3.7.0</version>
|
<version>3.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.piegamesde</groupId>
|
||||||
|
<artifactId>nbt</artifactId>
|
||||||
|
<version>dbe4ea253b</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -28,14 +28,16 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.jnbt.CompoundTag;
|
|
||||||
import org.jnbt.IntTag;
|
|
||||||
import org.jnbt.NBTInputStream;
|
|
||||||
import org.jnbt.NBTOutputStream;
|
|
||||||
import org.jnbt.Tag;
|
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
import org.joml.Vector3i;
|
import org.joml.Vector3i;
|
||||||
|
|
||||||
|
import com.flowpowered.nbt.CompoundMap;
|
||||||
|
import com.flowpowered.nbt.CompoundTag;
|
||||||
|
import com.flowpowered.nbt.IntTag;
|
||||||
|
import com.flowpowered.nbt.Tag;
|
||||||
|
import com.flowpowered.nbt.stream.NBTInputStream;
|
||||||
|
import com.flowpowered.nbt.stream.NBTOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author morlok8k
|
* @author morlok8k
|
||||||
@ -93,28 +95,17 @@ public class Server {
|
|||||||
* @author Corrodias
|
* @author Corrodias
|
||||||
*/
|
*/
|
||||||
protected static Vector3i getSpawn(final File level) throws IOException {
|
protected static Vector3i getSpawn(final File level) throws IOException {
|
||||||
try {
|
try (NBTInputStream input = new NBTInputStream(new FileInputStream(level));) {
|
||||||
final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
|
final CompoundTag levelTag = (CompoundTag) input.readTag();
|
||||||
final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
final Map<String, Tag<?>> levelData =
|
||||||
input.close();
|
((CompoundTag) levelTag.getValue().get("Data")).getValue();
|
||||||
|
|
||||||
final Map<String, Tag> originalData =
|
final IntTag spawnX = (IntTag) levelData.get("SpawnX");
|
||||||
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
final IntTag spawnY = (IntTag) levelData.get("SpawnY");
|
||||||
// This is our map of data. It is an unmodifiable map, for some
|
final IntTag spawnZ = (IntTag) levelData.get("SpawnZ");
|
||||||
// reason, so we have to make a copy.
|
|
||||||
final Map<String, Tag> newData = new LinkedHashMap<>(originalData);
|
|
||||||
// .get() a couple of values, just to make sure we're dealing with a
|
|
||||||
// valid level file, here. Good for debugging, too.
|
|
||||||
final IntTag spawnX = (IntTag) newData.get("SpawnX");
|
|
||||||
final IntTag spawnY = (IntTag) newData.get("SpawnY");
|
|
||||||
final IntTag spawnZ = (IntTag) newData.get("SpawnZ");
|
|
||||||
|
|
||||||
final Vector3i ret =
|
return new Vector3i(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue());
|
||||||
new Vector3i(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue());
|
} catch (final ClassCastException | NullPointerException ex) {
|
||||||
return ret;
|
|
||||||
} catch (final ClassCastException ex) {
|
|
||||||
throw new IOException("Invalid level format.");
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
throw new IOException("Invalid level format.");
|
throw new IOException("Invalid level format.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,64 +129,25 @@ public class Server {
|
|||||||
* @author Corrodias
|
* @author Corrodias
|
||||||
*/
|
*/
|
||||||
protected static void setSpawn(final File level, final Vector3i xyz) throws IOException {
|
protected static void setSpawn(final File level, final Vector3i xyz) throws IOException {
|
||||||
|
// TODO clean this up even more
|
||||||
try {
|
try (NBTInputStream input = new NBTInputStream(new FileInputStream(level));) {
|
||||||
final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
|
|
||||||
final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
||||||
input.close();
|
input.close();
|
||||||
|
|
||||||
//@formatter:off
|
final Map<String, Tag<?>> originalData =
|
||||||
|
|
||||||
//Note: The Following Information is Old (from 2010), compared to the Data inside a current "level.dat".
|
|
||||||
//However, What we look at (SpawnX,Y,Z and RandomSeed) have not changed.
|
|
||||||
|
|
||||||
/* <editor-fold defaultstate="collapsed" desc="structure">
|
|
||||||
* Structure:
|
|
||||||
*
|
|
||||||
*TAG_Compound("Data"): World data.
|
|
||||||
* * TAG_Long("Time"): Stores the current "time of day" in ticks. There are 20 ticks per real-life second, and 24000 ticks per Minecraft day, making the day length 20 minutes. 0 appears to be sunrise, 12000 sunset and 24000 sunrise again.
|
|
||||||
* * TAG_Long("LastPlayed"): Stores the Unix time stamp (in milliseconds) when the player saved the game.
|
|
||||||
* * TAG_Compound("Player"): Player entity information. See Entity Format and Mob Entity Format for details. Has additional elements:
|
|
||||||
* o TAG_List("Inventory"): Each TAG_Compound in this list defines an item the player is carrying, holding, or wearing as armor.
|
|
||||||
* + TAG_Compound: Inventory item data
|
|
||||||
* # TAG_Short("id"): Item or Block ID.
|
|
||||||
* # TAG_Short("Damage"): The amount of wear each item has suffered. 0 means undamaged. When the Damage exceeds the item's durability, it breaks and disappears. Only tools and armor accumulate damage normally.
|
|
||||||
* # TAG_Byte("Count"): Number of items stacked in this inventory slot. Any item can be stacked, including tools, armor, and vehicles. Range is 1-255. Values above 127 are not displayed in-game.
|
|
||||||
* # TAG_Byte("Slot"): Indicates which inventory slot this item is in.
|
|
||||||
* o TAG_Int("Score"): Current score, doesn't appear to be implemented yet. Always 0.
|
|
||||||
* * TAG_Int("SpawnX"): X coordinate of the player's spawn position. Default is 0.
|
|
||||||
* * TAG_Int("SpawnY"): Y coordinate of the player's spawn position. Default is 64.
|
|
||||||
* * TAG_Int("SpawnZ"): Z coordinate of the player's spawn position. Default is 0.
|
|
||||||
* * TAG_Byte("SnowCovered"): 1 enables, 0 disables, see Winter Mode
|
|
||||||
* * TAG_Long("SizeOnDisk"): Estimated size of the entire world in bytes.
|
|
||||||
* * TAG_Long("RandomSeed"): Random number providing the Random Seed for the terrain.
|
|
||||||
* </editor-fold>
|
|
||||||
*/
|
|
||||||
|
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
final Map<String, Tag> originalData =
|
|
||||||
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
||||||
// This is our map of data. It is an unmodifiable map, for some reason, so we have to make a copy.
|
// This is our map of data. It is an unmodifiable map, for some reason, so we have to make a copy.
|
||||||
final Map<String, Tag> newData = new LinkedHashMap<>(originalData);
|
final Map<String, Tag<?>> newData = new LinkedHashMap<>(originalData);
|
||||||
|
|
||||||
// .get() a couple of values, just to make sure we're dealing with a valid level file, here. Good for debugging, too.
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
final IntTag spawnX = (IntTag) newData.get("SpawnX"); // we never use these... Its only here for potential debugging.
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
final IntTag spawnY = (IntTag) newData.get("SpawnY"); // but whatever... so I (Morlok8k) suppressed these warnings.
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
final IntTag spawnZ = (IntTag) newData.get("SpawnZ"); // I don't want to remove existing code, either by myself (Morlok8k) or Corrodias
|
|
||||||
|
|
||||||
newData.put("SpawnX", new IntTag("SpawnX", xyz.x)); // pulling the data out of the Coordinates,
|
newData.put("SpawnX", new IntTag("SpawnX", xyz.x)); // pulling the data out of the Coordinates,
|
||||||
newData.put("SpawnY", new IntTag("SpawnY", xyz.y)); // and putting it into our IntTag's
|
newData.put("SpawnY", new IntTag("SpawnY", xyz.y)); // and putting it into our IntTag's
|
||||||
newData.put("SpawnZ", new IntTag("SpawnZ", xyz.z));
|
newData.put("SpawnZ", new IntTag("SpawnZ", xyz.z));
|
||||||
|
|
||||||
// Again, we can't modify the data map in the old Tag, so we have to make a new one.
|
// Again, we can't modify the data map in the old Tag, so we have to make a new one.
|
||||||
final CompoundTag newDataTag = new CompoundTag("Data", newData);
|
final CompoundTag newDataTag = new CompoundTag("Data", new CompoundMap(newData));
|
||||||
final Map<String, Tag> newTopLevelMap = new HashMap<>(1);
|
final Map<String, Tag<?>> newTopLevelMap = new HashMap<>(1);
|
||||||
newTopLevelMap.put("Data", newDataTag);
|
newTopLevelMap.put("Data", newDataTag);
|
||||||
final CompoundTag newTopLevelTag = new CompoundTag("", newTopLevelMap);
|
final CompoundTag newTopLevelTag = new CompoundTag("", new CompoundMap(newTopLevelMap));
|
||||||
|
|
||||||
final NBTOutputStream output = new NBTOutputStream(new FileOutputStream(level));
|
final NBTOutputStream output = new NBTOutputStream(new FileOutputStream(level));
|
||||||
output.writeTag(newTopLevelTag);
|
output.writeTag(newTopLevelTag);
|
||||||
|
Reference in New Issue
Block a user