Permalink
Browse files

Began working on a new 0.16 update and a new NBT library.

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 625b6f52ea1ce5751d0eadf55eee42e2c4834aa5
View
@@ -42,7 +42,6 @@
<configuration>
<links>
<link>https://flowpowered.com/math</link>
<link>https://flowpowered.com/math</link>
</links>
</configuration>
</plugin>
View
@@ -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>
@@ -0,0 +1,7 @@
package com.voxelwind.nbt.io;
/**
* Created by andrew on 10/21/16.

This comment has been minimized.

Show comment
Hide comment
@Chnkr

Chnkr Oct 21, 2016

Could you please keep these pointless comments away from the repository, there are people such as me who have notifications turned on to stay up-to-date about this project, pointless comments like these go straight into my inbox.

Please, just don't.

@Chnkr

Chnkr Oct 21, 2016

Could you please keep these pointless comments away from the repository, there are people such as me who have notifications turned on to stay up-to-date about this project, pointless comments like these go straight into my inbox.

Please, just don't.

This comment has been minimized.

Show comment
Hide comment
@minecrafter

minecrafter Oct 21, 2016

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.

@minecrafter

minecrafter Oct 21, 2016

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 {
}
@@ -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
}
@@ -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;
}
}
@@ -0,0 +1,7 @@
package com.voxelwind.nbt.tags;
public interface Tag<T> {
String getName();
T getValue();
}
@@ -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);
}
}
View
@@ -12,6 +12,7 @@
<module>api</module>
<module>server</module>
<module>natives</module>
<module>nbt</module>
</modules>
<repositories>
@@ -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: net.minidev:json-smart:1.3.1" 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-core:2.6.2" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.0.41.Final" level="project" />

6 comments on commit 625b6f5

@TheDiamondYT1

This comment has been minimized.

Show comment
Hide comment
@TheDiamondYT1

TheDiamondYT1 Oct 21, 2016

Contributor

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

Contributor

TheDiamondYT1 replied Oct 21, 2016

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

@minecrafter

This comment has been minimized.

Show comment
Hide comment
@minecrafter

minecrafter Oct 21, 2016

Member

That's not a priority at the moment.

Member

minecrafter replied Oct 21, 2016

That's not a priority at the moment.

@Techcable

This comment has been minimized.

Show comment
Hide comment
@Techcable

Techcable Oct 23, 2016

Does this support traditional NBT?

Techcable replied Oct 23, 2016

Does this support traditional NBT?

@TheDiamondYT1

This comment has been minimized.

Show comment
Hide comment
@TheDiamondYT1
Contributor

TheDiamondYT1 replied Oct 23, 2016

@minecrafter

This comment has been minimized.

Show comment
Hide comment
@minecrafter
Member

minecrafter replied Oct 23, 2016

@Techcable

This comment has been minimized.

Show comment
Hide comment
@Techcable

Techcable Oct 24, 2016

🌮 🌋 That's awesome

Techcable replied Oct 24, 2016

🌮 🌋 That's awesome

Please sign in to comment.