Skip to content

Commit d878472

Browse files
committed
Update slot packets
1 parent 1fff094 commit d878472

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import net.minecraft.network.protocol.Packet;
3131
import net.minecraft.network.protocol.common.ServerboundClientInformationPacket;
3232
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
33+
import net.minecraft.network.protocol.game.ClientboundSetCursorItemPacket;
34+
import net.minecraft.network.protocol.game.ClientboundSetPlayerInventoryPacket;
3335
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
3436
import net.minecraft.network.syncher.EntityDataAccessor;
3537
import net.minecraft.server.level.ServerLevel;
@@ -103,7 +105,7 @@ public static void handleSlotRestore(@Nullable final Player player, final @Nulla
103105
final org.spongepowered.api.item.inventory.ItemStack stack = snapshot.asMutable();
104106
slot.set(stack);
105107
((net.minecraft.server.level.ServerPlayer) player).connection.send(
106-
new ClientboundContainerSetSlotPacket(-2, player.inventoryMenu.getStateId(), ((SlotAdapter) slot).getOrdinal(), ItemStackUtil.toNative(stack)));
108+
new ClientboundSetPlayerInventoryPacket(((SlotAdapter) slot).getOrdinal(), ItemStackUtil.toNative(stack)));
107109
} else {
108110
final int slotNumber = ((SlotAdapter) slot).getOrdinal();
109111
final Slot nmsSlot = containerMenu.getSlot(slotNumber);
@@ -138,15 +140,15 @@ public static void handleCursorRestore(final Player player, final Transaction<It
138140
player.containerMenu.setCarried(cursor);
139141
player.containerMenu.setRemoteCarried(cursor);
140142
if (player instanceof net.minecraft.server.level.ServerPlayer) {
141-
((net.minecraft.server.level.ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(-1, player.containerMenu.getStateId(), -1, cursor));
143+
((net.minecraft.server.level.ServerPlayer) player).connection.send(new ClientboundSetCursorItemPacket(cursor));
142144
}
143145
}
144146

145147
public static void handleCustomCursor(final Player player, final ItemStackSnapshot customCursor) {
146148
final ItemStack cursor = ItemStackUtil.fromSnapshotToNative(customCursor);
147149
player.containerMenu.setCarried(cursor);
148150
if (player instanceof net.minecraft.server.level.ServerPlayer) {
149-
((net.minecraft.server.level.ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(-1, -1, -1, cursor));
151+
((net.minecraft.server.level.ServerPlayer) player).connection.send(new ClientboundSetCursorItemPacket(cursor));
150152
}
151153
}
152154

src/main/java/org/spongepowered/common/util/BookUtil.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import net.minecraft.network.protocol.Packet;
2929
import net.minecraft.network.protocol.game.ClientGamePacketListener;
3030
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
31-
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
3231
import net.minecraft.network.protocol.game.ClientboundOpenBookPacket;
32+
import net.minecraft.network.protocol.game.ClientboundSetPlayerInventoryPacket;
3333
import net.minecraft.world.InteractionHand;
3434
import net.minecraft.world.entity.player.Inventory;
3535
import org.spongepowered.api.data.Keys;
@@ -43,8 +43,6 @@
4343

4444
public final class BookUtil {
4545

46-
public static final int PLAYER_INVENTORY = -2;
47-
4846
public static ClientboundBundlePacket createFakeBookViewPacket(final Player player, final Book book) {
4947
final ItemStack item = ItemStack.of(ItemTypes.WRITTEN_BOOK);
5048
item.offer(Keys.CUSTOM_NAME, book.title());
@@ -59,14 +57,14 @@ public static ClientboundBundlePacket createFakeBookViewPacket(final Player play
5957

6058
// First we need to send a fake a Book ItemStack with the BookView's
6159
// contents to the player's hand
62-
packets.add(new ClientboundContainerSetSlotPacket(BookUtil.PLAYER_INVENTORY, 0, bookSlot, ItemStackUtil.toNative(item)));
60+
packets.add(new ClientboundSetPlayerInventoryPacket(bookSlot, ItemStackUtil.toNative(item)));
6361

6462
// Next we tell the client to open the Book GUI
6563
packets.add(new ClientboundOpenBookPacket(InteractionHand.MAIN_HAND));
6664

6765
// Now we can remove the fake Book since it's contents will have already
6866
// been transferred to the GUI
69-
packets.add(new ClientboundContainerSetSlotPacket(BookUtil.PLAYER_INVENTORY, 0, bookSlot, oldItem));
67+
packets.add(new ClientboundSetPlayerInventoryPacket(bookSlot, oldItem));
7068

7169
return new ClientboundBundlePacket(packets);
7270
}

src/mixins/java/org/spongepowered/common/mixin/inventory/impl/server/level/ServerPlayer_Mixin_Inventory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
package org.spongepowered.common.mixin.inventory.impl.server.level;
2626

2727
import net.minecraft.core.NonNullList;
28-
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
28+
import net.minecraft.network.protocol.game.ClientboundSetPlayerInventoryPacket;
2929
import net.minecraft.server.level.ServerPlayer;
3030
import net.minecraft.world.inventory.AbstractContainerMenu;
3131
import net.minecraft.world.item.ItemStack;
@@ -54,6 +54,6 @@ public abstract class ServerPlayer_Mixin_Inventory {
5454
final org.spongepowered.api.item.inventory.Slot offhand
5555
= ((org.spongepowered.api.entity.living.player.server.ServerPlayer) this.this$0).inventory().offhand();
5656
this.this$0.connection.send(
57-
new ClientboundContainerSetSlotPacket(-2, 0, ((SlotAdapter) offhand).getOrdinal(), ItemStackUtil.toNative(offhand.peek())));
57+
new ClientboundSetPlayerInventoryPacket(((SlotAdapter) offhand).getOrdinal(), ItemStackUtil.toNative(offhand.peek())));
5858
}
5959
}

0 commit comments

Comments
 (0)