Skip to content

Commit

Permalink
Began working on a new 0.16 update and a new NBT library.
Browse files Browse the repository at this point in the history
Why do we need to do this?

I decided to start over with a new branch as a lot has changed in Voxelwind since my last 0.16-related work in late August.

As for the NBT library, this is because Mojang introduced a new NBT encoding in MCPE 0.16. This encoding uses VarInts instead of regular types. None of the other NBT libraries are active, so I'm forced to create a new library. This means I can do some things I've wanted to do for a while (immutable tag instances!)
  • Loading branch information
minecrafter committed Oct 21, 2016
1 parent 393a310 commit 625b6f5
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 2 deletions.
1 change: 0 additions & 1 deletion api/pom.xml
Expand Up @@ -42,7 +42,6 @@
<configuration> <configuration>
<links> <links>
<link>https://flowpowered.com/math</link> <link>https://flowpowered.com/math</link>
<link>https://flowpowered.com/math</link>
</links> </links>
</configuration> </configuration>
</plugin> </plugin>
Expand Down
28 changes: 28 additions & 0 deletions nbt/pom.xml
@@ -0,0 +1,28 @@
<?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">
<parent>
<artifactId>voxelwind</artifactId>
<groupId>com.voxelwind</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>voxelwind-nbt</artifactId>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>4.0.41.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
7 changes: 7 additions & 0 deletions nbt/src/main/java/com/voxelwind/nbt/io/NBTReader.java
@@ -0,0 +1,7 @@
package com.voxelwind.nbt.io;

/**
* Created by andrew on 10/21/16.

This comment has been minimized.

Copy link
@minecrafter

minecrafter Oct 21, 2016

Author Member

@TheDiamondYT1 Why yes, my name is Andrew.

Seriously, you need to stop. You're very close to being blocked from this repository and Gitter.

*/
public class NBTReader {
}
15 changes: 15 additions & 0 deletions nbt/src/main/java/com/voxelwind/nbt/io/NBTType.java
@@ -0,0 +1,15 @@
package com.voxelwind.nbt.io;

/**
* Represents the type of NBT represented by this stream.
*/
public enum NBTType {
/**
* Plain, uncompressed Notchian compression.
*/
NOTCHIAN,
/**
* A special NBT encoding introduced in MCPE 0.16.
*/
MCPE_0_16_NETWORK
}
20 changes: 20 additions & 0 deletions nbt/src/main/java/com/voxelwind/nbt/tags/EndTag.java
@@ -0,0 +1,20 @@
package com.voxelwind.nbt.tags;

/**
* Represents the end of an NBT structure.
*/
public class EndTag implements Tag<Void> {
public static final EndTag INSTANCE = new EndTag();

private EndTag() {

}

public String getName() {
return "";
}

public Void getValue() {
return null;
}
}
7 changes: 7 additions & 0 deletions nbt/src/main/java/com/voxelwind/nbt/tags/Tag.java
@@ -0,0 +1,7 @@
package com.voxelwind.nbt.tags;

public interface Tag<T> {
String getName();

T getValue();
}
70 changes: 70 additions & 0 deletions nbt/src/main/java/com/voxelwind/nbt/util/Varints.java
@@ -0,0 +1,70 @@
package com.voxelwind.nbt.util;

import io.netty.buffer.ByteBuf;

import java.io.IOException;
import java.nio.ByteBuffer;

public class Varints {
private static final int MSB = 0x80
, REST = 0x7F
, MSBALL = ~REST;

public static void encodeUnsigned(int num, ByteBuf output) {
while ((num & MSBALL) != 0) {
output.writeByte((num & 0xFF) | MSB);
num >>>= 7;
}
output.writeByte(num & REST);
}

public static void encodeUnsigned(int num, ByteBuffer output) {
while ((num & MSBALL) != 0) {
output.put((byte) ((num & 0xFF) | MSB));
num >>>= 7;
}
output.put((byte) (num & REST));
}

public static int decodeUnsigned(ByteBuf input) throws IOException {
int res = 0, shift = 0, b;
while (((b = input.readByte()) & MSB) == 0) {
res += (b & REST) << shift;
shift += 7;
if (shift > 35) {
throw new IllegalArgumentException("Provided VarInt is not valid.");
}
}
return res;
}

public static int decodeUnsigned(ByteBuffer input) throws IOException {
int res = 0, shift = 0, b;
while (((b = input.get()) & MSB) == 0) {
res += (b & REST) << shift;
shift += 7;
if (shift > 35) {
throw new IllegalArgumentException("Provided VarInt is not valid.");
}
}
return res;
}

public static void encodeSigned(int num, ByteBuf output) throws IOException {
encodeUnsigned((num << 1) ^ (num >> 31), output);
}

public static void encodeSigned(int num, ByteBuffer output) throws IOException {
encodeUnsigned((num << 1) ^ (num >> 31), output);
}

public static int decodeSigned(ByteBuf input) throws IOException {
int n = decodeUnsigned(input);
return (n << 1) ^ (n >> 31);
}

public static int decodeSigned(ByteBuffer input) throws IOException {
int n = decodeUnsigned(input);
return (n << 1) ^ (n >> 31);
}
}
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -12,6 +12,7 @@
<module>api</module> <module>api</module>
<module>server</module> <module>server</module>
<module>natives</module> <module>natives</module>
<module>nbt</module>
</modules> </modules>


<repositories> <repositories>
Expand Down
2 changes: 1 addition & 1 deletion server/voxelwind-server.iml
Expand Up @@ -29,7 +29,7 @@
<orderEntry type="library" name="Maven: com.github.stephenc.jcip:jcip-annotations:1.0-1" level="project" /> <orderEntry type="library" name="Maven: com.github.stephenc.jcip:jcip-annotations:1.0-1" level="project" />
<orderEntry type="library" name="Maven: net.minidev:json-smart:1.3.1" level="project" /> <orderEntry type="library" name="Maven: net.minidev:json-smart:1.3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" /> <orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="module" module-name="natives" /> <orderEntry type="module" module-name="voxelwind-natives" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.0.41.Final" level="project" /> <orderEntry type="library" name="Maven: io.netty:netty-handler:4.0.41.Final" level="project" />
Expand Down

6 comments on commit 625b6f5

@TheDiamondYT1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make a seperate repo for it and put it on maven for others.

@minecrafter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a priority at the moment.

@Techcable
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this support traditional NBT?

@TheDiamondYT1
Copy link
Contributor

@TheDiamondYT1 TheDiamondYT1 commented on 625b6f5 Oct 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minecrafter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Techcable
Copy link

@Techcable Techcable commented on 625b6f5 Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌮 🌋 That's awesome

Please sign in to comment.