Support for 1.15.2 - 1.16.2 (and all snapshots between)

This commit is contained in:
Bixilon 2020-09-01 23:08:42 +02:00
parent d0e246e8b4
commit 8901f38824
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
19 changed files with 201 additions and 87 deletions

View File

@ -23,4 +23,8 @@ public class MagmaCube extends Slime {
public MagmaCube(int entityId, UUID uuid, Location location, short yaw, short pitch, short headYaw, EntityMetaData.MetaDataHashMap sets, int protocolId) {
super(entityId, uuid, location, yaw, pitch, headYaw, sets, protocolId);
}
public MagmaCube(int entityId, UUID uuid, Location location, short yaw, short pitch, int headYaw) {
super(entityId, uuid, location, yaw, pitch, headYaw);
}
}

View File

@ -29,6 +29,10 @@ public class Slime extends Mob implements MobInterface {
this.metaData = new SlimeMetaData(sets, protocolId);
}
public Slime(int entityId, UUID uuid, Location location, short yaw, short pitch, int headYaw) {
super(entityId, uuid, location, yaw, pitch, headYaw);
}
@Override
public EntityMetaData getMetaData() {
return metaData;

View File

@ -60,7 +60,6 @@ public class MainWindow implements Initializable {
serverAddress.setPromptText("Server address");
GUITools.versionList.getSelectionModel().select(Versions.getLowestVersionSupported());
GUITools.versionList.setEditable(true);
grid.add(new Label("Servername:"), 0, 0);
grid.add(serverName, 1, 0);

View File

@ -198,7 +198,6 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
} else {
GUITools.versionList.getSelectionModel().select(Versions.getVersionById(server.getDesiredVersion()));
}
GUITools.versionList.setEditable(true);
grid.add(new Label("Servername:"), 0, 0);
grid.add(serverName, 1, 0);

View File

@ -33,7 +33,7 @@ public class ServerListPing {
playersOnline = json.getAsJsonObject("players").get("online").getAsInt();
maxPlayers = json.getAsJsonObject("players").get("max").getAsInt();
if (json.has("favicon")) {
base64Favicon = json.get("favicon").getAsString().replace("data:image/png;base64,", "");
base64Favicon = json.get("favicon").getAsString().replace("data:image/png;base64,", "").replace("\n", "");
favicon = GUITools.getImageFromBase64(base64Favicon);
}

View File

@ -23,24 +23,24 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import java.util.UUID;
public class PacketChatMessageReceiving implements ClientboundPacket {
TextComponent c;
TextComponent message;
ChatTextPositions position;
UUID sender;
@Override
public boolean read(InByteBuffer buffer) {
if (buffer.getProtocolId() < 7) {
c = buffer.readTextComponent();
message = buffer.readTextComponent();
position = ChatTextPositions.CHAT_BOX;
return true;
}
if (buffer.getProtocolId() < 743) { //ToDo: when exactly did this change?
c = buffer.readTextComponent();
if (buffer.getProtocolId() < 718) {
message = buffer.readTextComponent();
position = ChatTextPositions.byId(buffer.readByte());
return true;
}
c = buffer.readTextComponent();
message = buffer.readTextComponent();
position = ChatTextPositions.byId(buffer.readByte());
sender = buffer.readUUID();
return true;
@ -48,11 +48,11 @@ public class PacketChatMessageReceiving implements ClientboundPacket {
@Override
public void log() {
Log.game(String.format("[CHAT] %s", c.getColoredMessage()));
Log.game(String.format("[CHAT] %s", message.getColoredMessage()));
}
public TextComponent getChatComponent() {
return c;
public TextComponent getMessage() {
return message;
}
@Override

View File

@ -27,12 +27,12 @@ import de.bixilon.minosoft.util.nbt.tag.CompoundTag;
import java.util.HashMap;
public class PacketChunkData implements ClientboundPacket {
final HashMap<BlockPosition, CompoundTag> blockEntities = new HashMap<>();
ChunkLocation location;
Chunk chunk;
CompoundTag heightMap;
int[] biomes;
boolean ignoreOldData;
final HashMap<BlockPosition, CompoundTag> blockEntities = new HashMap<>();
@Override
public boolean read(InByteBuffer buffer) {
@ -72,7 +72,7 @@ public class PacketChunkData implements ClientboundPacket {
}
this.location = new ChunkLocation(buffer.readInt(), buffer.readInt());
boolean groundUpContinuous = buffer.readBoolean();
if (buffer.getProtocolId() >= 743) { //ToDo: find out exact version
if (buffer.getProtocolId() >= 732 && buffer.getProtocolId() < 746) {
this.ignoreOldData = buffer.readBoolean();
}
int sectionBitMask;
@ -85,7 +85,7 @@ public class PacketChunkData implements ClientboundPacket {
heightMap = (CompoundTag) buffer.readNBT();
}
if (groundUpContinuous) {
if (buffer.getProtocolId() >= 743) { //ToDo: find out exact version
if (buffer.getProtocolId() >= 740) {
biomes = buffer.readVarIntArray(buffer.readVarInt());
} else if (buffer.getProtocolId() >= 552) {
biomes = buffer.readIntArray(1024);

View File

@ -39,7 +39,7 @@ public class PacketEntityEquipment implements ClientboundPacket {
slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readShort(), buffer.getProtocolId()), buffer.readSlot());
return true;
}
if (buffer.getProtocolId() < 743) { //ToDo: find out version
if (buffer.getProtocolId() < 732) {
entityId = buffer.readVarInt();
slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readVarInt(), buffer.getProtocolId()), buffer.readSlot());
return true;

View File

@ -70,55 +70,73 @@ public class PacketJoinGame implements ClientboundPacket {
reducedDebugScreen = buffer.readBoolean();
return true;
}
if (buffer.getProtocolId() < 743) { //ToDo
this.entityId = buffer.readInt();
if (buffer.getProtocolId() < 738) {
byte gameModeRaw = buffer.readByte();
hardcore = BitByte.isBitSet(gameModeRaw, 3);
// remove hardcore bit and get gamemode
gameModeRaw &= ~0x8;
gameMode = GameModes.byId(gameModeRaw);
} else {
hardcore = buffer.readBoolean();
gameMode = GameModes.byId(buffer.readByte());
}
if (buffer.getProtocolId() >= 730) {
buffer.readByte(); // previous game mode
}
if (buffer.getProtocolId() >= 719) {
String[] worlds = buffer.readStringArray(buffer.readVarInt());
}
if (buffer.getProtocolId() < 718) {
dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readInt());
} else {
NBTTag dimensionCodec = buffer.readNBT();
dimensions = parseDimensionCodec(dimensionCodec, buffer.getProtocolId());
if (buffer.getProtocolId() < 748) {
String[] currentDimensionSplit = buffer.readString().split(":", 2);
dimension = dimensions.get(currentDimensionSplit[0]).get(currentDimensionSplit[1]);
} else {
CompoundTag tag = (CompoundTag) buffer.readNBT();
if (tag.getByteTag("has_skylight").getValue() == 0x01) { //ToDo: this is just for not messing up the skylight
dimension = dimensions.get("minecraft").get("overworld");
} else {
dimension = dimensions.get("minecraft").get("the_nether");
}
}
}
if (buffer.getProtocolId() >= 719) {
buffer.readString(); // world
}
if (buffer.getProtocolId() >= 552) {
hashedSeed = buffer.readLong();
}
if (buffer.getProtocolId() < 464) {
difficulty = Difficulties.byId(buffer.readByte());
}
if (buffer.getProtocolId() < 749) {
maxPlayers = buffer.readByte();
} else {
maxPlayers = buffer.readVarInt();
}
if (buffer.getProtocolId() < 716) {
levelType = LevelTypes.byType(buffer.readString());
}
if (buffer.getProtocolId() >= 468) {
viewDistance = buffer.readVarInt();
}
if (buffer.getProtocolId() >= 716) {
boolean isDebug = buffer.readBoolean();
if (buffer.readBoolean()) {
levelType = LevelTypes.FLAT;
}
}
reducedDebugScreen = buffer.readBoolean();
if (buffer.getProtocolId() >= 552) {
enableRespawnScreen = buffer.readBoolean();
}
return true;
}
this.entityId = buffer.readInt();
hardcore = buffer.readBoolean();
gameMode = GameModes.byId(buffer.readByte());
buffer.readByte(); // previous game mode
// worlds
String[] worlds = buffer.readStringArray(buffer.readVarInt());
NBTTag dimensionCodec = buffer.readNBT();
dimensions = parseDimensionCodec(dimensionCodec);
String[] currentDimensionSplit = buffer.readString().split(":", 2);
dimension = dimensions.get(currentDimensionSplit[0]).get(currentDimensionSplit[1]);
buffer.readString(); // world name
hashedSeed = buffer.readLong();
maxPlayers = buffer.readByte();
levelType = LevelTypes.UNKNOWN;
viewDistance = buffer.readVarInt();
reducedDebugScreen = buffer.readBoolean();
enableRespawnScreen = buffer.readBoolean();
boolean isDebug = buffer.readBoolean();
if (buffer.readBoolean()) {
levelType = LevelTypes.FLAT;
}
return true;
}
@Override
public void log() {
@ -130,17 +148,33 @@ public class PacketJoinGame implements ClientboundPacket {
h.handle(this);
}
private HashMap<String, HashBiMap<String, Dimension>> parseDimensionCodec(NBTTag nbt) {
private HashMap<String, HashBiMap<String, Dimension>> parseDimensionCodec(NBTTag nbt, int protocolId) {
HashMap<String, HashBiMap<String, Dimension>> dimensionMap = new HashMap<>();
ListTag listTag = ((CompoundTag) nbt).getCompoundTag("minecraft:dimension_type").getListTag("value");
ListTag listTag;
if (protocolId < 740) {
listTag = ((CompoundTag) nbt).getListTag("dimension");
} else {
listTag = ((CompoundTag) nbt).getCompoundTag("minecraft:dimension_type").getListTag("value");
}
for (NBTTag tag : listTag.getValue()) {
CompoundTag compoundTag = (CompoundTag) tag;
String[] name = compoundTag.getStringTag("name").getValue().split(":", 2);
String[] name;
if (protocolId < 725) {
name = compoundTag.getStringTag("key").getValue().split(":", 2);
} else {
name = compoundTag.getStringTag("name").getValue().split(":", 2);
}
if (!dimensionMap.containsKey(name[0])) {
dimensionMap.put(name[0], HashBiMap.create());
}
dimensionMap.get(name[0]).put(name[1], new Dimension(name[0], name[1], compoundTag.getByteTag("has_skylight").getValue() == 0x01));
boolean hasSkylight;
if (protocolId < 725 || protocolId >= 744) {
hasSkylight = compoundTag.getCompoundTag("element").getByteTag("has_skylight").getValue() == 0x01;
} else {
hasSkylight = compoundTag.getByteTag("has_skylight").getValue() == 0x01;
}
dimensionMap.get(name[0]).put(name[1], new Dimension(name[0], name[1], hasSkylight));
}
return dimensionMap;
}

View File

@ -48,7 +48,7 @@ public class PacketMultiBlockChange implements ClientboundPacket {
}
return true;
}
if (buffer.getProtocolId() < 743) { //ToDo
if (buffer.getProtocolId() < 740) {
location = new ChunkLocation(buffer.readInt(), buffer.readInt());
int count = buffer.readVarInt();
for (int i = 0; i < count; i++) {
@ -62,6 +62,9 @@ public class PacketMultiBlockChange implements ClientboundPacket {
long rawPos = buffer.readLong();
location = new ChunkLocation((int) (rawPos >> 42), (int) (rawPos << 22 >> 42));
int yOffset = ((int) rawPos & 0xFFFFF) * 16;
if (buffer.getProtocolId() > 748) {
buffer.readBoolean(); // ToDo
}
int count = buffer.readVarInt();
for (int i = 0; i < count; i++) {
long data = buffer.readVarLong();

View File

@ -34,32 +34,40 @@ public class PacketRespawn implements ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
if (buffer.getProtocolId() < 743) { //ToDo
if (buffer.getProtocolId() < 718) {
if (buffer.getProtocolId() < 108) {
dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readByte());
} else {
dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readInt());
}
} else {
dimension = buffer.getConnection().getMapping().getDimensionByIdentifier(buffer.readString());
}
if (buffer.getProtocolId() < 464) {
difficulty = Difficulties.byId(buffer.readByte());
}
if (buffer.getProtocolId() >= 719) {
buffer.readString(); // world
}
if (buffer.getProtocolId() >= 552) {
hashedSeed = buffer.readLong();
}
gameMode = GameModes.byId(buffer.readByte());
if (buffer.getProtocolId() >= 1) {
if (buffer.getProtocolId() >= 730) {
buffer.readByte(); // previous game mode
}
if (buffer.getProtocolId() >= 1 && buffer.getProtocolId() < 716) {
levelType = LevelTypes.byType(buffer.readString());
}
return true;
}
dimension = buffer.getConnection().getMapping().getDimensionByIdentifier(buffer.readString());
buffer.readString(); // world
hashedSeed = buffer.readLong();
gameMode = GameModes.byId(buffer.readByte());
buffer.readByte(); // previous game mode
if (buffer.getProtocolId() >= 716) {
isDebug = buffer.readBoolean();
isFlat = buffer.readBoolean();
}
if (buffer.getProtocolId() >= 714) {
copyMetaData = buffer.readBoolean();
}
return true;
}

View File

@ -46,7 +46,7 @@ public class PacketUnlockRecipes implements ClientboundPacket {
isSmeltingBookOpen = buffer.readBoolean();
isSmeltingFilteringActive = buffer.readBoolean();
}
if (buffer.getProtocolId() >= 743) { //ToDo
if (buffer.getProtocolId() >= 738) {
isBlastFurnaceBookOpen = buffer.readBoolean();
isBlastFurnaceFilteringActive = buffer.readBoolean();
isSmokerBookOpen = buffer.readBoolean();

View File

@ -26,7 +26,7 @@ public class PacketUpdateLight implements ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
location = new ChunkLocation(buffer.readVarInt(), buffer.readVarInt());
if (buffer.getProtocolId() >= 743) { //ToDo
if (buffer.getProtocolId() >= 725) {
boolean trustEdges = buffer.readBoolean();
}
int skyLightMask = buffer.readVarInt();

View File

@ -36,7 +36,9 @@ public class PacketGenerateStructure implements ServerboundPacket {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_GENERATE_STRUCTURE);
buffer.writePosition(position);
buffer.writeVarInt(levels);
if (buffer.getProtocolId() <= 719) {
buffer.writeBoolean(keepJigsaw);
}
return buffer;
}

View File

@ -82,11 +82,15 @@ public class PacketInteractEntity implements ServerboundPacket {
if (buffer.getProtocolId() >= 49) {
buffer.writeVarInt(hand.getId());
}
}
}
if (buffer.getProtocolId() >= 743) { //ToDo
if (buffer.getProtocolId() >= 725 && buffer.getProtocolId() < 729) {
buffer.writeBoolean(sneaking);
}
}
if (buffer.getProtocolId() <= 729) {
buffer.writeBoolean(sneaking);
}
}
return buffer;
}

View File

@ -34,7 +34,7 @@ public class PacketPlayerAbilitiesSending implements ServerboundPacket {
flags |= 0b10;
}
buffer.writeByte(flags);
if (buffer.getProtocolId() < 743) { //ToDo
if (buffer.getProtocolId() < 727) {
// only fly matters, everything else ignored
buffer.writeFloat(0.0F);
buffer.writeFloat(0.0F);

View File

@ -0,0 +1,57 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets;
public class PacketRecipeBookState implements ServerboundPacket {
final RecipeBooks book;
final boolean bookOpen;
final boolean filterActive;
public PacketRecipeBookState(RecipeBooks book, boolean bookOpen, boolean filterActive) {
this.book = book;
this.bookOpen = bookOpen;
this.filterActive = filterActive;
}
@Override
public OutPacketBuffer write(Connection connection) {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_SET_RECIPE_BOOK_STATE);
buffer.writeVarInt(book.ordinal());
buffer.writeBoolean(bookOpen);
buffer.writeBoolean(filterActive);
return buffer;
}
@Override
public void log() {
Log.protocol(String.format("Sending recipe book state (book=%s, bookOpen=%s, filterActive=%s)", book, bookOpen, filterActive));
}
public enum RecipeBooks {
CRAFTING,
FURNACE,
BLAST_FURNACE,
SMOKER;
public static RecipeBooks byId(int id) {
return values()[id];
}
}
}

View File

@ -49,7 +49,7 @@ public class PacketUpdateJigsawBlock implements ServerboundPacket {
public OutPacketBuffer write(Connection connection) {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_UPDATE_JIGSAW_BLOCK);
buffer.writePosition(position);
if (buffer.getProtocolId() < 743) { //ToDo
if (buffer.getProtocolId() < 708) {
buffer.writeString(attachmentType);
buffer.writeString(targetPool);
buffer.writeString(finalState);

File diff suppressed because one or more lines are too long