3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 06:30:16 +02:00

Merge branch 'future/1.16.2' of https://github.com/Xernium/Velocity into Xernium-future/1.16.2

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-08-05 10:34:17 -04:00
Commit b8a2d97935
4 geänderte Dateien mit 100 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -36,7 +36,8 @@ public enum ProtocolVersion {
MINECRAFT_1_15_1(575, "1.15.1"),
MINECRAFT_1_15_2(578, "1.15.2"),
MINECRAFT_1_16(735, "1.16"),
MINECRAFT_1_16_1(736, "1.16.1");
MINECRAFT_1_16_1(736, "1.16.1"),
MINECRAFT_1_16_2(741, "1.16.2");
private final int protocol;
private final String name;

Datei anzeigen

@ -79,27 +79,22 @@ public final class DimensionRegistry {
* Encodes the stored Dimension registry as CompoundTag.
* @return the CompoundTag containing identifier:type mappings
*/
public CompoundTag encodeRegistry() {
CompoundTag ret = new CompoundTag();
public ListTag encodeRegistry() {
ListTag list = new ListTag(TagType.COMPOUND);
for (DimensionData iter : registeredDimensions.values()) {
list.add(iter.encodeAsCompundTag());
}
ret.put("dimension", list);
return ret;
return list;
}
/**
* Decodes a CompoundTag storing a dimension registry.
* @param toParse CompoundTag containing a dimension registry
*/
public static ImmutableSet<DimensionData> fromGameData(CompoundTag toParse) {
Preconditions.checkNotNull(toParse, "CompoundTag cannot be null");
Preconditions.checkArgument(toParse.contains("dimension", TagType.LIST),
"CompoundTag does not contain a dimension list");
ListTag dimensions = toParse.getList("dimension");
public static ImmutableSet<DimensionData> fromGameData(ListTag toParse) {
Preconditions.checkNotNull(toParse, "ListTag cannot be null");
ImmutableSet.Builder<DimensionData> mappings = ImmutableSet.builder();
for (Tag iter : dimensions) {
for (Tag iter : toParse) {
if (iter instanceof CompoundTag) {
mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter));
}

Datei anzeigen

@ -7,6 +7,7 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_14;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_15;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_16;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_16_2;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4;
@ -122,7 +123,8 @@ public enum StateRegistry {
map(0x18, MINECRAFT_1_12, false),
map(0x1D, MINECRAFT_1_13, false),
map(0x1F, MINECRAFT_1_14, false),
map(0x20, MINECRAFT_1_16, false));
map(0x20, MINECRAFT_1_16, false),
map(0x21, MINECRAFT_1_16_2, false));
clientbound.register(BossBar.class, BossBar::new,
map(0x0C, MINECRAFT_1_9, false),
@ -139,39 +141,45 @@ public enum StateRegistry {
map(0x0E, MINECRAFT_1_9, false),
map(0x10, MINECRAFT_1_13, false),
map(0x11, MINECRAFT_1_15, false),
map(0x10, MINECRAFT_1_16, false));
map(0x10, MINECRAFT_1_16, false),
map(0x0F, MINECRAFT_1_16_2, false));
clientbound.register(AvailableCommands.class, AvailableCommands::new,
map(0x11, MINECRAFT_1_13, false),
map(0x12, MINECRAFT_1_15, false),
map(0x11, MINECRAFT_1_16, false));
map(0x11, MINECRAFT_1_16, false),
map(0x10, MINECRAFT_1_16_2, false));
clientbound.register(PluginMessage.class, PluginMessage::new,
map(0x3F, MINECRAFT_1_8, false),
map(0x18, MINECRAFT_1_9, false),
map(0x19, MINECRAFT_1_13, false),
map(0x18, MINECRAFT_1_14, false),
map(0x19, MINECRAFT_1_15, false),
map(0x18, MINECRAFT_1_16, false));
map(0x18, MINECRAFT_1_16, false),
map(0x17, MINECRAFT_1_16_2, false));
clientbound.register(Disconnect.class, Disconnect::new,
map(0x40, MINECRAFT_1_8, false),
map(0x1A, MINECRAFT_1_9, false),
map(0x1B, MINECRAFT_1_13, false),
map(0x1A, MINECRAFT_1_14, false),
map(0x1B, MINECRAFT_1_15, false),
map(0x1A, MINECRAFT_1_16, false));
map(0x1A, MINECRAFT_1_16, false),
map(0x19, MINECRAFT_1_16_2, false));
clientbound.register(KeepAlive.class, KeepAlive::new,
map(0x00, MINECRAFT_1_8, false),
map(0x1F, MINECRAFT_1_9, false),
map(0x21, MINECRAFT_1_13, false),
map(0x20, MINECRAFT_1_14, false),
map(0x21, MINECRAFT_1_15, false),
map(0x20, MINECRAFT_1_16, false));
map(0x20, MINECRAFT_1_16, false),
map(0x1F, MINECRAFT_1_16_2, false));
clientbound.register(JoinGame.class, JoinGame::new,
map(0x01, MINECRAFT_1_8, false),
map(0x23, MINECRAFT_1_9, false),
map(0x25, MINECRAFT_1_13, false),
map(0x25, MINECRAFT_1_14, false),
map(0x26, MINECRAFT_1_15, false),
map(0x25, MINECRAFT_1_16, false));
map(0x25, MINECRAFT_1_16, false),
map(0x24, MINECRAFT_1_16_2, false));
clientbound.register(Respawn.class, Respawn::new,
map(0x07, MINECRAFT_1_8, true),
map(0x33, MINECRAFT_1_9, true),
@ -180,7 +188,8 @@ public enum StateRegistry {
map(0x38, MINECRAFT_1_13, true),
map(0x3A, MINECRAFT_1_14, true),
map(0x3B, MINECRAFT_1_15, true),
map(0x3A, MINECRAFT_1_16, true));
map(0x3A, MINECRAFT_1_16, true),
map(0x39, MINECRAFT_1_16_2, true));
clientbound.register(ResourcePackRequest.class, ResourcePackRequest::new,
map(0x48, MINECRAFT_1_8, true),
map(0x32, MINECRAFT_1_9, true),
@ -189,7 +198,8 @@ public enum StateRegistry {
map(0x37, MINECRAFT_1_13, true),
map(0x39, MINECRAFT_1_14, true),
map(0x3A, MINECRAFT_1_15, true),
map(0x39, MINECRAFT_1_16, true));
map(0x39, MINECRAFT_1_16, true),
map(0x38, MINECRAFT_1_16_2, true));
clientbound.register(HeaderAndFooter.class, HeaderAndFooter::new,
map(0x47, MINECRAFT_1_8, true),
map(0x48, MINECRAFT_1_9, true),
@ -216,7 +226,8 @@ public enum StateRegistry {
map(0x30, MINECRAFT_1_13, false),
map(0x33, MINECRAFT_1_14, false),
map(0x34, MINECRAFT_1_15, false),
map(0x33, MINECRAFT_1_16, false));
map(0x33, MINECRAFT_1_16, false),
map(0x32, MINECRAFT_1_16_2, false));
}
},
LOGIN {

Datei anzeigen

@ -8,6 +8,9 @@ import com.velocitypowered.proxy.connection.registry.DimensionInfo;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
import com.velocitypowered.proxy.protocol.*;
import io.netty.buffer.ByteBuf;
import net.kyori.nbt.CompoundTag;
import net.kyori.nbt.ListTag;
import net.kyori.nbt.TagType;
import org.checkerframework.checker.nullness.qual.Nullable;
public class JoinGame implements MinecraftPacket {
@ -17,7 +20,8 @@ public class JoinGame implements MinecraftPacket {
private int dimension;
private long partialHashedSeed; // 1.15+
private short difficulty;
private short maxPlayers;
private boolean isHardcore;
private int maxPlayers;
private @Nullable String levelType;
private int viewDistance; // 1.14+
private boolean reducedDebugInfo;
@ -25,6 +29,7 @@ public class JoinGame implements MinecraftPacket {
private DimensionRegistry dimensionRegistry; // 1.16+
private DimensionInfo dimensionInfo; // 1.16+
private short previousGamemode; // 1.16+
private CompoundTag biomeRegistry; // 1.16.2+
public int getEntityId() {
return entityId;
@ -62,11 +67,11 @@ public class JoinGame implements MinecraftPacket {
this.difficulty = difficulty;
}
public short getMaxPlayers() {
public int getMaxPlayers() {
return maxPlayers;
}
public void setMaxPlayers(short maxPlayers) {
public void setMaxPlayers(int maxPlayers) {
this.maxPlayers = maxPlayers;
}
@ -118,6 +123,22 @@ public class JoinGame implements MinecraftPacket {
this.previousGamemode = previousGamemode;
}
public boolean getIsHardcore() {
return isHardcore;
}
public void setIsHardcore(boolean isHardcore) {
this.isHardcore = isHardcore;
}
public CompoundTag getBiomeRegistry() {
return biomeRegistry;
}
public void setBiomeRegistry(CompoundTag biomeRegistry) {
this.biomeRegistry = biomeRegistry;
}
@Override
public String toString() {
return "JoinGame{"
@ -126,6 +147,7 @@ public class JoinGame implements MinecraftPacket {
+ ", dimension=" + dimension
+ ", partialHashedSeed=" + partialHashedSeed
+ ", difficulty=" + difficulty
+ ", isHardcore=" + isHardcore
+ ", maxPlayers=" + maxPlayers
+ ", levelType='" + levelType + '\''
+ ", viewDistance=" + viewDistance
@ -139,13 +161,30 @@ public class JoinGame implements MinecraftPacket {
@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
this.entityId = buf.readInt();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
this.isHardcore = buf.readBoolean();
this.gamemode = buf.readByte();
} else {
this.gamemode = buf.readByte();
this.isHardcore = (this.gamemode & 0x08) != 0;
this.gamemode &= ~0x08;
}
String dimensionIdentifier = null;
String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
this.previousGamemode = buf.readByte();
ImmutableSet<String> levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf));
ImmutableSet<DimensionData> readData = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf));
CompoundTag registryContainer = ProtocolUtils.readCompoundTag(buf);
ListTag dimensionRegistryContainer = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
dimensionRegistryContainer = registryContainer.getCompound("minecraft:dimension_type")
.getList("value", TagType.COMPOUND);
this.biomeRegistry = registryContainer.getCompound("minecraft:worldgen/biome");
} else {
dimensionRegistryContainer = registryContainer.getList("dimension", TagType.COMPOUND);
}
ImmutableSet<DimensionData> readData =
DimensionRegistry.fromGameData(dimensionRegistryContainer);
this.dimensionRegistry = new DimensionRegistry(readData, levelNames);
dimensionIdentifier = ProtocolUtils.readString(buf);
levelName = ProtocolUtils.readString(buf);
@ -160,7 +199,11 @@ public class JoinGame implements MinecraftPacket {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
this.partialHashedSeed = buf.readLong();
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
this.maxPlayers = ProtocolUtils.readVarInt(buf);
} else {
this.maxPlayers = buf.readUnsignedByte();
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
this.levelType = ProtocolUtils.readString(buf, 16);
}
@ -181,12 +224,28 @@ public class JoinGame implements MinecraftPacket {
@Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
buf.writeInt(entityId);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
buf.writeBoolean(isHardcore);
buf.writeByte(gamemode);
} else {
buf.writeByte(isHardcore ? gamemode | 0x8 : gamemode);
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
buf.writeByte(previousGamemode);
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray(
new String[dimensionRegistry.getLevelNames().size()]));
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry());
CompoundTag registryContainer = new CompoundTag();
ListTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
CompoundTag dimensionRegistryDummy = new CompoundTag();
dimensionRegistryDummy.putString("type", "minecraft:dimension_type");
dimensionRegistryDummy.put("value", encodedDimensionRegistry);
registryContainer.put("minecraft:dimension_type", dimensionRegistryDummy);
registryContainer.put("minecraft:worldgen/biome", biomeRegistry);
} else {
registryContainer.put("dimension", encodedDimensionRegistry);
}
ProtocolUtils.writeCompoundTag(buf, registryContainer);
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
@ -200,7 +259,11 @@ public class JoinGame implements MinecraftPacket {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
buf.writeLong(partialHashedSeed);
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
ProtocolUtils.writeVarInt(buf, maxPlayers);
} else {
buf.writeByte(maxPlayers);
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
if (levelType == null) {
throw new IllegalStateException("No level type specified.");