Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Rework inventory workaround to cancel animation if in an open inventory
On 1.16, when sending a new inventory while another one is open (without explicitly calling `closeInventory` first), a hand swing is sent from the client, which the server handles like any normal arm swing. This in turn results in the `PlayerInteractEvent` and `PlayerAnimationEvent` both being called on Bukkit's end, which are used to detect for left clicks. If an item in the player's hand opens a menu when left clicked and the above is true, this results in that menu being reopened.
Dieser Commit ist enthalten in:
Ursprung
b209eb3c8b
Commit
7e03da66d4
@ -16,9 +16,11 @@ import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -242,5 +244,18 @@ public class EntityPackets {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
protocol.registerIncoming(ServerboundPackets1_16.ANIMATION, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
handler(wrapper -> {
|
||||||
|
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
|
||||||
|
// Don't send an arm swing if the player is switching between inventories.
|
||||||
|
if (inventoryTracker.getInventory() != -1) {
|
||||||
|
wrapper.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
|||||||
import com.github.steveice10.opennbt.tag.builtin.LongTag;
|
import com.github.steveice10.opennbt.tag.builtin.LongTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
@ -16,8 +15,6 @@ import us.myles.ViaVersion.api.type.Type;
|
|||||||
import us.myles.ViaVersion.api.type.types.UUIDIntArrayType;
|
import us.myles.ViaVersion.api.type.types.UUIDIntArrayType;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
|
||||||
@ -38,24 +35,12 @@ public class InventoryPackets {
|
|||||||
|
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
|
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
|
||||||
if (inventoryTracker.getInventory() != -1) {
|
|
||||||
// Close open inventory before opening a new one.
|
|
||||||
PacketWrapper closePacket = wrapper.create(ClientboundPackets1_16.CLOSE_WINDOW.ordinal());
|
|
||||||
closePacket.write(Type.UNSIGNED_BYTE, inventoryTracker.getInventory());
|
|
||||||
closePacket.send(Protocol1_16To1_15_2.class, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int windowId = wrapper.get(Type.VAR_INT, 0);
|
int windowId = wrapper.get(Type.VAR_INT, 0);
|
||||||
int windowType = wrapper.get(Type.VAR_INT, 1);
|
int windowType = wrapper.get(Type.VAR_INT, 1);
|
||||||
if (windowType >= 20) { // smithing added with id 20
|
if (windowType >= 20) { // smithing added with id 20
|
||||||
wrapper.set(Type.VAR_INT, 1, ++windowType);
|
wrapper.set(Type.VAR_INT, 1, ++windowType);
|
||||||
}
|
}
|
||||||
|
|
||||||
inventoryTracker.setInventory((short) windowId);
|
inventoryTracker.setInventory((short) windowId);
|
||||||
|
|
||||||
// Workaround for packet order issue
|
|
||||||
wrapper.send(Protocol1_16To1_15_2.class, true, true);
|
|
||||||
wrapper.cancel();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren