3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-24 15:20:19 +01:00
Dieser Commit ist enthalten in:
KennyTV 2021-06-10 18:51:12 +02:00
Ursprung 00bc4a9d6a
Commit d62165bf51
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
6 geänderte Dateien mit 176 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@ plugins {
allprojects {
group = "com.viaversion"
version = "4.0.1-SNAPSHOT"
version = "4.0.1-1.17.1-pre1-SNAPSHOT"
description = "Allow older clients to join newer server versions."
}

Datei anzeigen

@ -43,6 +43,7 @@ import com.viaversion.viabackwards.protocol.protocol1_16_2to1_16_3.Protocol1_16_
import com.viaversion.viabackwards.protocol.protocol1_16_3to1_16_4.Protocol1_16_3To1_16_4;
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17;
import com.viaversion.viabackwards.protocol.protocol1_16to1_16_1.Protocol1_16To1_16_1;
import com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.Protocol1_17To1_17_1;
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.ProtocolManager;
@ -104,6 +105,7 @@ public interface ViaBackwardsPlatform {
protocolManager.registerProtocol(new Protocol1_16_3To1_16_4(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_4);
protocolManager.registerProtocol(new Protocol1_16_4To1_17(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_17);
protocolManager.registerProtocol(new Protocol1_17To1_17_1(), ProtocolVersion.v1_17, ProtocolVersion.v1_17_1);
}
/**

Datei anzeigen

@ -0,0 +1,132 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_17to1_17_1;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.storage.InventoryStateIds;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPackets1_17, ClientboundPackets1_17, ServerboundPackets1_17, ServerboundPackets1_17> {
private static final int MAX_PAGE_LENGTH = 8192;
private static final int MAX_TITLE_LENGTH = 128;
public Protocol1_17To1_17_1() {
super(ClientboundPackets1_17.class, ClientboundPackets1_17.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class);
}
@Override
protected void registerPackets() {
registerClientbound(ClientboundPackets1_17.SET_SLOT, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
int stateId = wrapper.read(Type.VAR_INT);
wrapper.user().get(InventoryStateIds.class).setStateId(containerId, stateId);
});
}
});
registerClientbound(ClientboundPackets1_17.WINDOW_ITEMS, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
int stateId = wrapper.read(Type.VAR_INT);
wrapper.user().get(InventoryStateIds.class).setStateId(containerId, stateId);
// Length is encoded as a var int in 1.17.1
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY, wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT));
// Carried item - should work without adding it to the array above
wrapper.read(Type.FLAT_VAR_INT_ITEM);
});
}
});
registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
int stateId = wrapper.user().get(InventoryStateIds.class).removeStateId(containerId);
wrapper.write(Type.VAR_INT, stateId == Integer.MAX_VALUE ? 0 : stateId);
});
}
});
registerServerbound(ServerboundPackets1_17.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Item item = wrapper.read(Type.FLAT_VAR_INT_ITEM);
boolean signing = wrapper.read(Type.BOOLEAN);
wrapper.passthrough(Type.VAR_INT); // Slot comes first
CompoundTag tag = item.tag();
ListTag pagesTag;
StringTag titleTag = null;
if (tag == null || (pagesTag = tag.get("pages")) == null
|| (signing && (titleTag = tag.get("title")) == null)) {
wrapper.write(Type.VAR_INT, 0); // Pages length
wrapper.write(Type.BOOLEAN, false); // Optional title
return;
}
// Write pages
wrapper.write(Type.VAR_INT, pagesTag.size());
for (Tag pageTag : pagesTag) {
String page = ((StringTag) pageTag).getValue();
if (page.length() > MAX_PAGE_LENGTH) {
page = page.substring(0, MAX_PAGE_LENGTH);
}
wrapper.write(Type.STRING, page);
}
// Write optional title
wrapper.write(Type.BOOLEAN, signing);
if (signing) {
if (titleTag == null) {
titleTag = tag.get("title");
}
String title = titleTag.getValue();
if (title.length() > MAX_TITLE_LENGTH) {
title = title.substring(0, MAX_TITLE_LENGTH);
}
wrapper.write(Type.STRING, title);
}
});
}
});
}
@Override
public void init(UserConnection connection) {
connection.put(new InventoryStateIds());
}
}

Datei anzeigen

@ -0,0 +1,39 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
public final class InventoryStateIds implements StorableObject {
private final Int2IntMap ids = new Int2IntOpenHashMap();
public InventoryStateIds() {
// Inventory ids are unsigned bytes, so this is safe to do
ids.defaultReturnValue(Integer.MAX_VALUE);
}
public void setStateId(short containerId, int id) {
ids.put(containerId, id);
}
public int removeStateId(short containerId) {
return ids.remove(containerId);
}
}

Datei anzeigen

@ -3,7 +3,7 @@ metadata.format.version = "1.0"
[versions]
# ViaVersion
viaver = "4.0.1-SNAPSHOT"
viaver = "4.0.1-1.17.1-pre1-SNAPSHOT"
# Common provided
netty = "4.0.20.Final"

Datei anzeigen

@ -5,6 +5,7 @@ rootProject.name = "viabackwards-parent"
dependencyResolutionManagement {
repositories {
mavenLocal()
maven("https://repo.viaversion.com")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://oss.sonatype.org/content/repositories/snapshots/")