Commit
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
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
package com.voxelwind.nbt.io; | |||
|
|||
/** | |||
* Created by andrew on 10/21/16. | |||
This comment has been minimized.
Sorry, something went wrong. |
|||
*/ | |||
public class NBTReader { | |||
} |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
} |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; | |||
} | |||
} |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
package com.voxelwind.nbt.tags; | |||
|
|||
public interface Tag<T> { | |||
String getName(); | |||
|
|||
T getValue(); | |||
} |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); | |||
} | |||
} |
6 comments
on commit 625b6f5
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheDiamondYT1 Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🌮 🌋 That's awesome
@TheDiamondYT1 Why yes, my name is Andrew.
Seriously, you need to stop. You're very close to being blocked from this repository and Gitter.