diff --git a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPacketChannel.java b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPacketChannel.java index 3f6b626..5c3ef4f 100644 --- a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPacketChannel.java +++ b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPacketChannel.java @@ -54,13 +54,20 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } private Packet handleMenuChange(@NotNull ClientboundContainerSetContentPacket packet) { + MessagesUtil.sendDebugMessages("ClientboundContainerSetContentPacket"); MessagesUtil.sendDebugMessages("Menu Initial "); Integer windowId = packet.containerId(); - NonNullList slotData = NonNullList.create(); - slotData.addAll(packet.items()); + List slotData = packet.items(); - List bukkitItems = slotData.stream().map(CraftItemStack::asBukkitCopy).toList(); + List bukkitItems = new ArrayList<>(); + for (ItemStack nmsItem : slotData) { + if (nmsItem == null) { + slotData.add(null); + continue; + } + bukkitItems.add(CraftItemStack.asBukkitCopy(nmsItem)); + } AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); ContainerContentWrapper wrapper = new ContainerContentWrapper(windowId, bukkitItems); @@ -72,12 +79,20 @@ public class NMSPacketChannel extends ChannelDuplexHandler { if (action.get() == PacketAction.CANCELLED) return null; if (action.get() == PacketAction.NOTHING) return packet; - List nmsItems = wrapper.getSlotData().stream().map(CraftItemStack::asNMSCopy).toList(); + List nmsItems = new ArrayList<>(); + for (org.bukkit.inventory.ItemStack bukkitItem : bukkitItems) { + if (bukkitItem == null) { + slotData.add(null); + continue; + } + nmsItems.add(CraftItemStack.asNMSCopy(bukkitItem)); + } + return new ClientboundContainerSetContentPacket(0, packet.stateId(), nmsItems, packet.carriedItem()); } private Packet handleSlotChange(@NotNull ClientboundContainerSetSlotPacket packet) { - MessagesUtil.sendDebugMessages("SetSlot Initial "); + MessagesUtil.sendDebugMessages("ClientboundContainerSetSlotPacket"); final int windowId = packet.getContainerId(); final int slot = packet.getSlot(); @@ -98,10 +113,11 @@ public class NMSPacketChannel extends ChannelDuplexHandler { final ItemStack nmsItem = CraftItemStack.asNMSCopy(wrapper.getItemStack()); - return new ClientboundContainerSetSlotPacket(0, packet.getStateId(), wrapper.getSlot(), nmsItem); + return new ClientboundContainerSetSlotPacket(packet.getContainerId(), packet.getStateId(), wrapper.getSlot(), nmsItem); } private Packet handlePlayerEquipment(@NotNull ClientboundSetEquipmentPacket packet) { + MessagesUtil.sendDebugMessages("ClientboundSetEquipmentPacket"); final List> nmsArmor = packet.getSlots(); final int entity = packet.getEntity(); HashMap bukkitArmor = new HashMap<>(); @@ -122,7 +138,6 @@ public class NMSPacketChannel extends ChannelDuplexHandler { if (action.get() == PacketAction.CANCELLED) return null; if (action.get() == PacketAction.NOTHING) return packet; - List> newArmor = new ArrayList<>(); for (Map.Entry entry : wrapper.getArmor().entrySet()) { net.minecraft.world.entity.EquipmentSlot slot = CraftEquipmentSlot.getNMS(entry.getKey()); @@ -134,6 +149,7 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } private Packet handlePassengerSet(@NotNull ClientboundSetPassengersPacket packet) { + MessagesUtil.sendDebugMessages("ClientboundSetPassengersPacket"); int ownerId = packet.getVehicle(); List passengers = Arrays.stream(packet.getPassengers()).boxed().collect(Collectors.toList()); MessagesUtil.sendDebugMessages("Mount Packet Sent - Read - EntityID: " + ownerId); @@ -172,6 +188,7 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } private Packet handleInventoryClick(@NotNull ServerboundContainerClickPacket packet) { + MessagesUtil.sendDebugMessages("ServerboundContainerClickPacket"); ClickType clickType = packet.clickType(); int slotClicked = packet.slotNum(); @@ -187,6 +204,7 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } private Packet handlePlayerAction(ServerboundPlayerActionPacket packet) { + MessagesUtil.sendDebugMessages("ServerboundPlayerActionPacket"); ServerboundPlayerActionPacket.Action playerAction = packet.getAction(); AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); @@ -201,6 +219,7 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } private Packet handlePlayerArm(ServerboundSwingPacket packet) { + MessagesUtil.sendDebugMessages("ServerboundSwingPacket"); AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); SubPlugins.getSubPlugins().forEach(plugin -> { @@ -213,6 +232,7 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } private Packet handleInteract(ServerboundInteractPacket packet) { + MessagesUtil.sendDebugMessages("ServerboundInteractPacket"); AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); SubPlugins.getSubPlugins().forEach(plugin -> { diff --git a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java index 8c3cc00..d4849c1 100644 --- a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java +++ b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPackets.java @@ -10,6 +10,7 @@ import io.papermc.paper.adventure.PaperAdventure; import it.unimi.dsi.fastutil.ints.IntList; import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; import me.lojosho.hibiscuscommons.util.AdventureUtils; +import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.advancements.Advancement; @@ -145,10 +146,11 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons. } @Override - public void sendRotationPacket(int entityId, float yaw, float pitch, boolean onGround, List sendTo) { + public void sendRotationPacket(int entityId, float originalYaw, float pitch, boolean onGround, List sendTo) { float ROTATION_FACTOR = 256.0F / 360.0F; - yaw = (byte) (yaw * ROTATION_FACTOR); + byte yaw = (byte) (originalYaw * ROTATION_FACTOR); pitch = (byte) (pitch * ROTATION_FACTOR); + MessagesUtil.sendDebugMessages("sendRotationPacket. Original: " + originalYaw + " modified: " + yaw); ClientboundMoveEntityPacket.Rot packet = new ClientboundMoveEntityPacket.Rot(entityId, (byte) yaw, (byte) pitch, onGround); for (Player p : sendTo) sendPacket(p, packet); }