Merge from master

This commit is contained in:
Myles 2019-12-15 09:16:53 +00:00
commit 6eabb17f67
8 changed files with 43 additions and 40 deletions

View File

@ -1,14 +1,12 @@
# ViaVersion 2.2.0 - Spigot, Sponge, BungeeCord, Velocity # ViaVersion 2.2.1 - Spigot, Sponge, BungeeCord, Velocity
[![Build Status](https://travis-ci.com/ViaVersion/ViaVersion.svg?branch=master)](https://travis-ci.com/ViaVersion/ViaVersion) [![Build Status](https://travis-ci.com/ViaVersion/ViaVersion.svg?branch=master)](https://travis-ci.com/ViaVersion/ViaVersion)
[![Discord](https://img.shields.io/badge/chat-on%20discord-blue.svg)](https://viaversion.com/discord) [![Discord](https://img.shields.io/badge/chat-on%20discord-blue.svg)](https://viaversion.com/discord)
IRC: [#viaversion](http://irc.spi.gt/iris/?channels=viaversion) on irc.spi.gt for Support.
**Allows the connection of higher client versions to lower server versions** **Allows the connection of higher client versions to lower server versions**
Supported Versions: Supported Versions:
![Table (https://i.imgur.com/iWAtD1p.png)](https://i.imgur.com/iWAtD1p.png) ![Table (https://i.imgur.com/yDtAgF7.png)](https://i.imgur.com/yDtAgF7.png)
On Bukkit you may also use ProtocolSupport, but ensure you have the right build for your server version. On Bukkit you may also use ProtocolSupport, but ensure you have the right build for your server version.

View File

@ -63,12 +63,12 @@ public class MappingDataLoader {
} }
} }
public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, boolean warnOnMissing) {
for (int i = 0; i < oldIdentifiers.size(); i++) { for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement v = oldIdentifiers.get(i); JsonElement v = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, v.getAsString()); Integer index = findIndex(newIdentifiers, v.getAsString());
if (index == null) { if (index == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("No key for " + v + " :( "); Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
} }
continue; continue;

View File

@ -51,18 +51,27 @@ public class Mappings {
/** /**
* Maps old identifiers to the new ones. * Maps old identifiers to the new ones.
* *
* @param size set size of the underlying short array * @param size set size of the underlying short array
* @param oldMapping mappings to map from * @param oldMapping mappings to map from
* @param newMapping mappings to map to * @param newMapping mappings to map to
* @param warnOnMissing should "No key for x" be printed if there is no matching identifier
*/ */
public Mappings(int size, JsonArray oldMapping, JsonArray newMapping) { public Mappings(int size, JsonArray oldMapping, JsonArray newMapping, boolean warnOnMissing) {
oldToNew = new short[size]; oldToNew = new short[size];
Arrays.fill(oldToNew, (short) -1); Arrays.fill(oldToNew, (short) -1);
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping); MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, warnOnMissing);
}
public Mappings(JsonArray oldMapping, JsonArray newMapping, boolean warnOnMissing) {
this(oldMapping.size(), oldMapping, newMapping, warnOnMissing);
}
public Mappings(int size, JsonArray oldMapping, JsonArray newMapping) {
this(size, oldMapping, newMapping, true);
} }
public Mappings(JsonArray oldMapping, JsonArray newMapping) { public Mappings(JsonArray oldMapping, JsonArray newMapping) {
this(oldMapping.size(), oldMapping, newMapping); this(oldMapping.size(), oldMapping, newMapping, true);
} }
public int getNewId(int old) { public int getNewId(int old) {

View File

@ -1,14 +1,15 @@
package us.myles.ViaVersion.api.type.types; package us.myles.ViaVersion.api.type.types;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import java.nio.charset.StandardCharsets;
public class StringType extends Type<String> { public class StringType extends Type<String> {
// String#length() (used to limit the string in Minecraft source code) uses char[]#length // String#length() (used to limit the string in Minecraft source code) uses char[]#length
private static final int maxJavaCharUtf8Length = Character.toString(Character.MAX_VALUE) private static final int maxJavaCharUtf8Length = Character.toString(Character.MAX_VALUE)
.getBytes(Charsets.UTF_8).length; .getBytes(StandardCharsets.UTF_8).length;
public StringType() { public StringType() {
super(String.class); super(String.class);
@ -21,9 +22,9 @@ public class StringType extends Type<String> {
Preconditions.checkArgument(len <= Short.MAX_VALUE * maxJavaCharUtf8Length, Preconditions.checkArgument(len <= Short.MAX_VALUE * maxJavaCharUtf8Length,
"Cannot receive string longer than Short.MAX_VALUE * " + maxJavaCharUtf8Length + " bytes (got %s bytes)", len); "Cannot receive string longer than Short.MAX_VALUE * " + maxJavaCharUtf8Length + " bytes (got %s bytes)", len);
byte[] b = new byte[len]; String string = buffer.toString(buffer.readerIndex(), len, StandardCharsets.UTF_8);
buffer.readBytes(b); buffer.skipBytes(len);
String string = new String(b, Charsets.UTF_8);
Preconditions.checkArgument(string.length() <= Short.MAX_VALUE, Preconditions.checkArgument(string.length() <= Short.MAX_VALUE,
"Cannot receive string longer than Short.MAX_VALUE characters (got %s bytes)", string.length()); "Cannot receive string longer than Short.MAX_VALUE characters (got %s bytes)", string.length());
@ -34,7 +35,7 @@ public class StringType extends Type<String> {
public void write(ByteBuf buffer, String object) throws Exception { public void write(ByteBuf buffer, String object) throws Exception {
Preconditions.checkArgument(object.length() <= Short.MAX_VALUE, "Cannot send string longer than Short.MAX_VALUE (got %s characters)", object.length()); Preconditions.checkArgument(object.length() <= Short.MAX_VALUE, "Cannot send string longer than Short.MAX_VALUE (got %s characters)", object.length());
byte[] b = object.getBytes(Charsets.UTF_8); byte[] b = object.getBytes(StandardCharsets.UTF_8);
Type.VAR_INT.write(buffer, b.length); Type.VAR_INT.write(buffer, b.length);
buffer.writeBytes(b); buffer.writeBytes(b);
} }

View File

@ -36,10 +36,7 @@ public class NBTType extends Type<CompoundTag> {
return null; return null;
} else { } else {
buffer.readerIndex(readerIndex); buffer.readerIndex(readerIndex);
ByteBufInputStream bytebufStream = new ByteBufInputStream(buffer); return (CompoundTag) NBTIO.readTag((DataInput) new ByteBufInputStream(buffer));
try (DataInputStream dataInputStream = new DataInputStream(bytebufStream)) {
return (CompoundTag) NBTIO.readTag((DataInput) dataInputStream);
}
} }
} }
@ -49,11 +46,7 @@ public class NBTType extends Type<CompoundTag> {
buffer.writeByte(0); buffer.writeByte(0);
} else { } else {
ByteBufOutputStream bytebufStream = new ByteBufOutputStream(buffer); ByteBufOutputStream bytebufStream = new ByteBufOutputStream(buffer);
DataOutputStream dataOutputStream = new DataOutputStream(bytebufStream); NBTIO.writeTag((DataOutput) bytebufStream, object);
NBTIO.writeTag((DataOutput) dataOutputStream, object);
dataOutputStream.close();
} }
} }
} }

View File

@ -58,7 +58,7 @@ public class Protocol1_15To1_14_4 extends Protocol {
}); });
// Edit Book // Edit Book
registerIncoming(State.PLAY, 0x0C, 0x0D, new PacketRemapper() { registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(new PacketHandler() {

View File

@ -25,6 +25,6 @@ public class MappingData {
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 item mapping..."); Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 item mapping...");
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items")); MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"));
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 sound mapping..."); Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 sound mapping...");
soundMappings = new Mappings(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds")); soundMappings = new Mappings(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), false);
} }
} }

View File

@ -101,18 +101,20 @@ public class WorldPackets {
if (chunk.isGroundUp()) { if (chunk.isGroundUp()) {
int[] biomeData = chunk.getBiomeData(); int[] biomeData = chunk.getBiomeData();
int[] newBiomeData = new int[1024]; int[] newBiomeData = new int[1024];
// Now in 4x4x4 areas - take the biome of each "middle" if (biomeData != null) {
for (int i = 0; i < 4; ++i) { // Now in 4x4x4 areas - take the biome of each "middle"
for (int j = 0; j < 4; ++j) { for (int i = 0; i < 4; ++i) {
int x = (j << 2) + 2; for (int j = 0; j < 4; ++j) {
int z = (i << 2) + 2; int x = (j << 2) + 2;
int oldIndex = (z << 4 | x); int z = (i << 2) + 2;
newBiomeData[i << 2 | j] = biomeData[oldIndex]; int oldIndex = (z << 4 | x);
newBiomeData[i << 2 | j] = biomeData[oldIndex];
}
}
// ... and copy it to the new y layers
for (int i = 1; i < 64; ++i) {
System.arraycopy(newBiomeData, 0, newBiomeData, i * 16, 16);
} }
}
// ... and copy it to the new y layers
for (int i = 1; i < 64; ++i) {
System.arraycopy(newBiomeData, 0, newBiomeData, i * 16, 16);
} }
chunk.setBiomeData(newBiomeData); chunk.setBiomeData(newBiomeData);