Merge pull request #1252 from creeper123123321/dev2

Resync the inventory when selecting trade
This commit is contained in:
Myles 2019-04-11 16:15:29 +01:00 committed by GitHub
commit 1e53803353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 6 deletions

View File

@ -225,7 +225,6 @@ public class Protocol1_14To1_13_2 extends Protocol {
registerIncoming(State.PLAY, 0x1C, 0x1E);
registerIncoming(State.PLAY, 0x1D, 0x1F);
registerIncoming(State.PLAY, 0x1E, 0x20);
registerIncoming(State.PLAY, 0x1F, 0x21);
registerIncoming(State.PLAY, 0x20, 0x22);
registerIncoming(State.PLAY, 0x21, 0x23);

View File

@ -181,7 +181,7 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception {
short animation = wrapper.passthrough(Type.UNSIGNED_BYTE);
if (animation == 2) { //Leave bed
PacketWrapper metadataPacket = wrapper.create(0x3F);
PacketWrapper metadataPacket = wrapper.create(0x43);
metadataPacket.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
List<Metadata> metadataList = new LinkedList<>();
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, null));

View File

@ -1,10 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets;
import com.github.steveice10.opennbt.conversion.ConverterRegistry;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.builtin.*;
import com.google.common.collect.Sets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
@ -15,9 +12,12 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
public class InventoryPackets {
private static String NBT_TAG_NAME;
@ -151,6 +151,7 @@ public class InventoryPackets {
wrapper.read(Type.STRING); // Remove channel
int windowId = wrapper.read(Type.INT);
wrapper.user().get(EntityTracker.class).setLatestTradeWindowId(windowId);
wrapper.write(Type.VAR_INT, windowId);
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
@ -280,6 +281,29 @@ public class InventoryPackets {
}
});
// Select trade
protocol.registerIncoming(State.PLAY, 0x1F, 0x21, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Selecting trade now moves the items, we need to resync the inventory
PacketWrapper resyncPacket = wrapper.create(0x08);
resyncPacket.write(Type.UNSIGNED_BYTE, ((short) wrapper.user().get(EntityTracker.class).getLatestTradeWindowId())); // 0 - Window ID
resyncPacket.write(Type.SHORT, ((short) -999)); // 1 - Slot
resyncPacket.write(Type.BYTE, (byte) 2); // 2 - Button - End left click
resyncPacket.write(Type.SHORT, ((short) ThreadLocalRandom.current().nextInt())); // 3 - Action number
resyncPacket.write(Type.VAR_INT, 5); // 4 - Mode - Drag
CompoundTag tag = new CompoundTag("");
tag.put(new DoubleTag("force_resync", Double.NaN)); // Tags with NaN are not equal
resyncPacket.write(Type.FLAT_VAR_INT_ITEM, new Item(1, (byte) 1, (short) 0, tag)); // 5 - Clicked Item
resyncPacket.sendToServer(Protocol1_14To1_13_2.class, true, true);
}
});
}
});
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x24, 0x26, new PacketRemapper() {
@Override

View File

@ -1,6 +1,8 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage;
import com.google.common.base.Optional;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
@ -11,6 +13,9 @@ import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker extends StoredObject {
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
@Getter
@Setter
private int latestTradeWindowId;
public EntityTracker(UserConnection user) {
super(user);