From fd9dab8aa12ff578a876840bb42acb30f29edf2c Mon Sep 17 00:00:00 2001 From: KennyTV Date: Wed, 26 May 2021 21:36:20 +0200 Subject: [PATCH] Replace inventory ack by using 1.17 ping packets --- .../Protocol1_17To1_16_4.java | 5 ++- .../packets/InventoryPackets.java | 32 +++++++++++++++-- .../storage/InventoryAcknowledgements.java | 34 +++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/storage/InventoryAcknowledgements.java diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java index 8413a0d16..aa0db4a53 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java @@ -33,6 +33,7 @@ import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.metadata.Metadat import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.WorldPackets; +import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.InventoryAcknowledgements; import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.rewriter.RegistryType; import com.viaversion.viaversion.rewriter.SoundRewriter; @@ -204,9 +205,6 @@ public class Protocol1_17To1_16_4 extends AbstractProtocol { + int id = wrapper.read(Type.INT); + // Check extra bit for fast dismissal + if ((id & (1 << 30)) != 0 && wrapper.user().get(InventoryAcknowledgements.class).removeId(id)) { + // Decode inventory acknowledgement + int inventoryId = (id >> 16) & 0xFF; + int confirmationId = id & 0xFFFF; PacketWrapper packet = wrapper.create(ServerboundPackets1_16_2.WINDOW_CONFIRMATION); - packet.write(Type.UNSIGNED_BYTE, inventoryId); - packet.write(Type.SHORT, confirmationId); + packet.write(Type.UNSIGNED_BYTE, (short) inventoryId); + packet.write(Type.SHORT, (short) confirmationId); packet.write(Type.BYTE, (byte) 1); // Accept packet.sendToServer(Protocol1_17To1_16_4.class, true, true); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/storage/InventoryAcknowledgements.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/storage/InventoryAcknowledgements.java new file mode 100644 index 000000000..17b858a62 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/storage/InventoryAcknowledgements.java @@ -0,0 +1,34 @@ +/* + * 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 . + */ +package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; + +public final class InventoryAcknowledgements implements StorableObject { + private final IntSet ids = new IntOpenHashSet(); + + public void addId(int id) { + ids.add(id); + } + + public boolean removeId(int id) { + return ids.remove(id); + } +}