From 78c994987f80fd06b085b674101a26e431d92def Mon Sep 17 00:00:00 2001 From: booky10 Date: Mon, 21 Oct 2024 02:05:52 +0200 Subject: [PATCH 1/6] Update client settings packet wrapper to 1.21.2 Also refactors it's logic into a common class, as it was previously split in config and play state packets --- .../client/WrapperCommonClientSettings.java | 250 ++++++++++++++++++ .../client/WrapperConfigClientSettings.java | 146 ++++------ .../client/WrapperPlayClientSettings.java | 213 +++------------ 3 files changed, 343 insertions(+), 266 deletions(-) create mode 100644 api/src/main/java/com/github/retrooper/packetevents/wrapper/common/client/WrapperCommonClientSettings.java diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/common/client/WrapperCommonClientSettings.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/common/client/WrapperCommonClientSettings.java new file mode 100644 index 0000000000..e96b008b70 --- /dev/null +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/common/client/WrapperCommonClientSettings.java @@ -0,0 +1,250 @@ +/* + * This file is part of packetevents - https://github.com/retrooper/packetevents + * Copyright (C) 2024 retrooper 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.github.retrooper.packetevents.wrapper.common.client; + +import com.github.retrooper.packetevents.event.PacketReceiveEvent; +import com.github.retrooper.packetevents.manager.server.ServerVersion; +import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; +import com.github.retrooper.packetevents.protocol.player.HumanoidArm; +import com.github.retrooper.packetevents.protocol.player.SkinSection; +import com.github.retrooper.packetevents.wrapper.PacketWrapper; +import org.jetbrains.annotations.ApiStatus; + +public class WrapperCommonClientSettings> extends PacketWrapper { + + private String locale; + private int viewDistance; + private ChatVisibility chatVisibility; + private boolean chatColors; + private byte skinMask; + private HumanoidArm mainHand; + private boolean textFilteringEnabled; + private boolean allowServerListings; + /** + * Added with 1.21.2 + */ + private ParticleStatus particleStatus; + /** + * Removed with 1.8 + */ + @ApiStatus.Obsolete + private byte ignoredDifficulty; + + public WrapperCommonClientSettings(PacketReceiveEvent event) { + super(event); + } + + public WrapperCommonClientSettings( + PacketTypeCommon packetType, + String locale, int viewDistance, ChatVisibility chatVisibility, + boolean chatColors, byte skinMask, HumanoidArm mainHand, + boolean textFilteringEnabled, boolean allowServerListings, + ParticleStatus particleStatus, byte ignoredDifficulty + ) { + super(packetType); + this.locale = locale; + this.viewDistance = viewDistance; + this.chatVisibility = chatVisibility; + this.chatColors = chatColors; + this.skinMask = skinMask; + this.mainHand = mainHand; + this.textFilteringEnabled = textFilteringEnabled; + this.allowServerListings = allowServerListings; + this.particleStatus = particleStatus; + this.ignoredDifficulty = ignoredDifficulty; + } + + @Override + public void read() { + this.locale = this.readString(this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_12) ? 16 : 7); + this.viewDistance = this.readByte(); + this.chatVisibility = this.readEnum(ChatVisibility.values()); + this.chatColors = this.readBoolean(); + if (this.serverVersion == ServerVersion.V_1_7_10) { + this.ignoredDifficulty = this.readByte(); + if (this.readBoolean()) { // show cape + this.skinMask = SkinSection.CAPE.getMask(); + } + } else { + this.skinMask = (byte) this.readUnsignedByte(); + } + this.mainHand = this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9) + ? this.readEnum(HumanoidArm.values()) : HumanoidArm.RIGHT; + this.textFilteringEnabled = this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_17) && this.readBoolean(); + this.allowServerListings = this.serverVersion.isOlderThan(ServerVersion.V_1_18) || this.readBoolean(); + this.particleStatus = this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2) + ? this.readEnum(ParticleStatus.values()) : ParticleStatus.ALL; + } + + @Override + public void write() { + this.writeString(this.locale, this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_12) ? 16 : 7); + this.writeByte(this.viewDistance); + this.writeEnum(this.chatVisibility); + this.writeBoolean(this.chatColors); + if (this.serverVersion == ServerVersion.V_1_7_10) { + this.writeByte(this.ignoredDifficulty); + this.writeBoolean(SkinSection.CAPE.isSet(this.skinMask)); + } else { + this.writeByte(this.skinMask); + } + if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9)) { + this.writeEnum(this.mainHand); + } + if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_17)) { + this.writeBoolean(this.textFilteringEnabled); + } + if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_18)) { + this.writeBoolean(this.allowServerListings); + } + if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2)) { + this.writeEnum(this.particleStatus); + } + } + + @Override + public void copy(T wrapper) { + this.locale = wrapper.getLocale(); + this.viewDistance = wrapper.getViewDistance(); + this.chatVisibility = wrapper.getChatVisibility(); + this.chatColors = wrapper.isChatColors(); + this.skinMask = wrapper.getSkinMask(); + this.mainHand = wrapper.getMainHand(); + this.textFilteringEnabled = wrapper.isTextFilteringEnabled(); + this.allowServerListings = wrapper.isServerListingAllowed(); + this.particleStatus = wrapper.getParticleStatus(); + this.ignoredDifficulty = wrapper.getIgnoredDifficulty(); + } + + public String getLocale() { + return this.locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } + + public int getViewDistance() { + return this.viewDistance; + } + + public void setViewDistance(int viewDistance) { + this.viewDistance = viewDistance; + } + + public ChatVisibility getChatVisibility() { + return this.chatVisibility; + } + + public void setChatVisibility(ChatVisibility chatVisibility) { + this.chatVisibility = chatVisibility; + } + + public boolean isChatColors() { + return this.chatColors; + } + + public void setChatColors(boolean chatColors) { + this.chatColors = chatColors; + } + + public byte getSkinMask() { + return this.skinMask; + } + + public void setSkinMask(byte skinMask) { + this.skinMask = skinMask; + } + + public SkinSection getVisibleSkinSection() { + return new SkinSection(this.skinMask); + } + + public void setVisibleSkinSections(SkinSection visibleSkinSection) { + this.skinMask = visibleSkinSection.getMask(); + } + + public boolean isSkinSectionVisible(SkinSection section) { + return section.isSet(this.skinMask); + } + + public void setSkinSectionVisible(SkinSection section, boolean visible) { + this.skinMask = section.set(this.skinMask, visible); + } + + public HumanoidArm getMainHand() { + return this.mainHand; + } + + public void setMainHand(HumanoidArm mainHand) { + this.mainHand = mainHand; + } + + public boolean isTextFilteringEnabled() { + return this.textFilteringEnabled; + } + + public void setTextFilteringEnabled(boolean textFilteringEnabled) { + this.textFilteringEnabled = textFilteringEnabled; + } + + public boolean isServerListingAllowed() { + return this.allowServerListings; + } + + public void setServerListingAllowed(boolean allowServerListings) { + this.allowServerListings = allowServerListings; + } + + public ParticleStatus getParticleStatus() { + return this.particleStatus; + } + + public void setParticleStatus(ParticleStatus particleStatus) { + this.particleStatus = particleStatus; + } + + /** + * Removed with 1.8 + */ + @ApiStatus.Obsolete + public byte getIgnoredDifficulty() { + return this.ignoredDifficulty; + } + + /** + * Removed with 1.8 + */ + @ApiStatus.Obsolete + public void setIgnoredDifficulty(byte ignoredDifficulty) { + this.ignoredDifficulty = ignoredDifficulty; + } + + public enum ChatVisibility { + FULL, + SYSTEM, + HIDDEN, + } + + public enum ParticleStatus { + ALL, + DECREASED, + MINIMAL, + } +} diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/configuration/client/WrapperConfigClientSettings.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/configuration/client/WrapperConfigClientSettings.java index 610803d281..08406f59f9 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/configuration/client/WrapperConfigClientSettings.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/configuration/client/WrapperConfigClientSettings.java @@ -21,143 +21,101 @@ import com.github.retrooper.packetevents.event.PacketReceiveEvent; import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.player.HumanoidArm; -import com.github.retrooper.packetevents.wrapper.PacketWrapper; +import com.github.retrooper.packetevents.wrapper.common.client.WrapperCommonClientSettings; +import net.kyori.adventure.util.Index; -public class WrapperConfigClientSettings extends PacketWrapper { - - private String locale; - private int viewDistance; - private ChatVisibility visibility; - private boolean chatColorable; - private byte visibleSkinSectionMask; - private HumanoidArm hand; - private boolean textFilteringEnabled; - private boolean allowServerListings; +public class WrapperConfigClientSettings extends WrapperCommonClientSettings { public WrapperConfigClientSettings(PacketReceiveEvent event) { super(event); } - public WrapperConfigClientSettings(String locale, int viewDistance, ChatVisibility visibility, - boolean chatColorable, byte visibleSkinSectionMask, HumanoidArm hand, - boolean textFilteringEnabled, boolean allowServerListings) { - super(PacketType.Configuration.Client.CLIENT_SETTINGS); - this.locale = locale; - this.viewDistance = viewDistance; - this.visibility = visibility; - this.chatColorable = chatColorable; - this.visibleSkinSectionMask = visibleSkinSectionMask; - this.hand = hand; - this.textFilteringEnabled = textFilteringEnabled; - this.allowServerListings = allowServerListings; - } - - @Override - public void read() { - this.locale = this.readString(16); - this.viewDistance = this.readByte(); - this.visibility = ChatVisibility.VALUES[this.readVarInt()]; - this.chatColorable = this.readBoolean(); - this.visibleSkinSectionMask = (byte) this.readUnsignedByte(); - this.hand = HumanoidArm.VALUES[this.readVarInt()]; - this.textFilteringEnabled = this.readBoolean(); - this.allowServerListings = this.readBoolean(); - } - - @Override - public void write() { - this.writeString(this.locale, 16); - this.writeByte(this.viewDistance); - this.writeVarInt(this.visibility.ordinal()); - this.writeBoolean(this.chatColorable); - this.writeByte(this.visibleSkinSectionMask); - this.writeVarInt(this.hand.ordinal()); - this.writeBoolean(this.textFilteringEnabled); - this.writeBoolean(this.allowServerListings); + public WrapperConfigClientSettings( + String locale, int viewDistance, WrapperCommonClientSettings.ChatVisibility chatVisibility, + boolean chatColors, byte skinMask, HumanoidArm mainHand, boolean textFilteringEnabled, + boolean allowServerListings, ParticleStatus particleStatus + ) { + super(PacketType.Configuration.Client.CLIENT_SETTINGS, locale, viewDistance, + chatVisibility, chatColors, skinMask, mainHand, textFilteringEnabled, + allowServerListings, particleStatus, (byte) 0); } - @Override - public void copy(WrapperConfigClientSettings wrapper) { - this.locale = wrapper.locale; - this.viewDistance = wrapper.viewDistance; - this.visibility = wrapper.visibility; - this.chatColorable = wrapper.chatColorable; - this.visibleSkinSectionMask = wrapper.visibleSkinSectionMask; - this.hand = wrapper.hand; - this.textFilteringEnabled = wrapper.textFilteringEnabled; - this.allowServerListings = wrapper.allowServerListings; - } - - public String getLocale() { - return this.locale; - } - - public void setLocale(String locale) { - this.locale = locale; - } - - public int getViewDistance() { - return this.viewDistance; - } - - public void setViewDistance(int viewDistance) { - this.viewDistance = viewDistance; + @Deprecated + public WrapperConfigClientSettings( + String locale, int viewDistance, ChatVisibility visibility, + boolean chatColorable, byte visibleSkinSectionMask, HumanoidArm hand, + boolean textFilteringEnabled, boolean allowServerListings + ) { + this(locale, viewDistance, visibility.modern, chatColorable, + visibleSkinSectionMask, hand, textFilteringEnabled, + allowServerListings, ParticleStatus.ALL); } + @Deprecated public ChatVisibility getVisibility() { - return this.visibility; + return ChatVisibility.MODERN_INDEX.valueOrThrow(this.getChatVisibility()); } + @Deprecated public void setVisibility(ChatVisibility visibility) { - this.visibility = visibility; + this.setChatVisibility(visibility.modern); } + @Deprecated public boolean isChatColorable() { - return this.chatColorable; + return this.isChatColors(); } + @Deprecated public void setChatColorable(boolean chatColorable) { - this.chatColorable = chatColorable; + this.setChatColors(chatColorable); } + @Deprecated public byte getVisibleSkinSectionMask() { - return this.visibleSkinSectionMask; + return this.getSkinMask(); } + @Deprecated public void setVisibleSkinSectionMask(byte visibleSkinSectionMask) { - this.visibleSkinSectionMask = visibleSkinSectionMask; + this.setSkinMask(visibleSkinSectionMask); } + @Deprecated public HumanoidArm getHand() { - return this.hand; + return this.getMainHand(); } + @Deprecated public void setHand(HumanoidArm hand) { - this.hand = hand; - } - - public boolean isTextFilteringEnabled() { - return this.textFilteringEnabled; - } - - public void setTextFilteringEnabled(boolean textFilteringEnabled) { - this.textFilteringEnabled = textFilteringEnabled; + this.setMainHand(hand); } + @Deprecated public boolean isAllowServerListings() { - return this.allowServerListings; + return this.isServerListingAllowed(); } + @Deprecated public void setAllowServerListings(boolean allowServerListings) { - this.allowServerListings = allowServerListings; + this.setServerListingAllowed(allowServerListings); } + @Deprecated public enum ChatVisibility { - FULL, - SYSTEM, - HIDDEN; + FULL(WrapperCommonClientSettings.ChatVisibility.FULL), + SYSTEM(WrapperCommonClientSettings.ChatVisibility.SYSTEM), + HIDDEN(WrapperCommonClientSettings.ChatVisibility.HIDDEN); public static final ChatVisibility[] VALUES = values(); + private static final Index MODERN_INDEX = + Index.create(ChatVisibility.class, visibility -> visibility.modern); + + private final WrapperCommonClientSettings.ChatVisibility modern; + + ChatVisibility(WrapperCommonClientSettings.ChatVisibility modern) { + this.modern = modern; + } } } diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientSettings.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientSettings.java index f732d9868c..3242ce9047 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientSettings.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientSettings.java @@ -19,211 +19,80 @@ package com.github.retrooper.packetevents.wrapper.play.client; import com.github.retrooper.packetevents.event.PacketReceiveEvent; -import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.player.HumanoidArm; -import com.github.retrooper.packetevents.protocol.player.SkinSection; -import com.github.retrooper.packetevents.wrapper.PacketWrapper; - -public class WrapperPlayClientSettings extends PacketWrapper { - private String locale; - private int viewDistance; - private ChatVisibility visibility; - private boolean chatColorable; - private byte visibleSkinSectionMask; - private HumanoidArm hand; - private boolean textFilteringEnabled; - private boolean allowServerListings; - - //Not accessible, only for 1.7 - private byte ignoredDifficulty; +import com.github.retrooper.packetevents.wrapper.common.client.WrapperCommonClientSettings; +import net.kyori.adventure.util.Index; - public enum ChatVisibility { - FULL, SYSTEM, HIDDEN; - - public static final ChatVisibility[] VALUES = values(); - } +public class WrapperPlayClientSettings extends WrapperCommonClientSettings { public WrapperPlayClientSettings(PacketReceiveEvent event) { super(event); } - public WrapperPlayClientSettings(String locale, int viewDistance, ChatVisibility visibility, - boolean chatColorable, byte visibleSkinSectionMask, HumanoidArm hand, - boolean textFilteringEnabled, boolean allowServerListings) { - super(PacketType.Play.Client.CLIENT_SETTINGS); - this.locale = locale; - this.viewDistance = viewDistance; - this.visibility = visibility; - this.chatColorable = chatColorable; - this.visibleSkinSectionMask = visibleSkinSectionMask; - this.hand = hand; - this.textFilteringEnabled = textFilteringEnabled; - this.allowServerListings = allowServerListings; - } - - @Override - public void read() { - int localeLength = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_12) ? 16 : 7; - locale = readString(localeLength); - viewDistance = readByte(); - int visibilityIndex = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9) ? readVarInt() : readByte(); - visibility = ChatVisibility.VALUES[visibilityIndex]; - chatColorable = readBoolean(); - if (serverVersion == ServerVersion.V_1_7_10) { - //Ignored - ignoredDifficulty = readByte(); - //We use this for the skin sections - boolean showCape = readBoolean(); - if (showCape) { - visibleSkinSectionMask = SkinSection.CAPE.getMask(); - } - } else { - visibleSkinSectionMask = (byte) readUnsignedByte(); - } - - if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9)) { - hand = HumanoidArm.VALUES[readVarInt()]; - } else { - hand = HumanoidArm.RIGHT; - } - - if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_17)) { - textFilteringEnabled = readBoolean(); - } else { - textFilteringEnabled = false; - } - - if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_18)) { - allowServerListings = readBoolean(); - } else { - allowServerListings = true; - } - } - - @Override - public void write() { - int localeLength = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_12) ? 16 : 7; - writeString(locale, localeLength); - writeByte(viewDistance); - if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9)) { - writeVarInt(visibility.ordinal()); - } else { - writeByte(visibility.ordinal()); - } - writeBoolean(chatColorable); - if (serverVersion == ServerVersion.V_1_7_10) { - writeByte(ignoredDifficulty); - //Show cape - boolean showCape = SkinSection.CAPE.isSet(visibleSkinSectionMask); - writeBoolean(showCape); - } else { - writeByte(visibleSkinSectionMask); - } - - if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9)) { - writeVarInt(hand.ordinal()); - } - - if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_17)) { - writeBoolean(textFilteringEnabled); - } - - if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_18)) { - writeBoolean(allowServerListings); - } - } - - @Override - public void copy(WrapperPlayClientSettings wrapper) { - locale = wrapper.locale; - viewDistance = wrapper.viewDistance; - visibility = wrapper.visibility; - chatColorable = wrapper.chatColorable; - visibleSkinSectionMask = wrapper.visibleSkinSectionMask; - hand = wrapper.hand; - textFilteringEnabled = wrapper.textFilteringEnabled; - allowServerListings = wrapper.allowServerListings; - ignoredDifficulty = wrapper.ignoredDifficulty; - } - - public String getLocale() { - return locale; - } - - public void setLocale(String locale) { - this.locale = locale; - } - - public int getViewDistance() { - return viewDistance; + public WrapperPlayClientSettings( + String locale, int viewDistance, WrapperCommonClientSettings.ChatVisibility visibility, + boolean chatColors, byte visibleSkinSectionMask, HumanoidArm hand, boolean textFilteringEnabled, + boolean allowServerListings, ParticleStatus particleStatus + ) { + super(PacketType.Play.Client.CLIENT_SETTINGS, locale, viewDistance, visibility, + chatColors, visibleSkinSectionMask, hand, textFilteringEnabled, + allowServerListings, particleStatus, (byte) 0); } - public void setViewDistance(int viewDistance) { - this.viewDistance = viewDistance; + @Deprecated + public WrapperPlayClientSettings(String locale, int viewDistance, ChatVisibility visibility, + boolean chatCOlors, byte visibleSkinSectionMask, HumanoidArm hand, + boolean textFilteringEnabled, boolean allowServerListings) { + this(locale, viewDistance, visibility.modern, chatCOlors, visibleSkinSectionMask, + hand, textFilteringEnabled, allowServerListings, ParticleStatus.ALL); } + @Deprecated public ChatVisibility getVisibility() { - return visibility; + return ChatVisibility.MODERN_INDEX.valueOrThrow(super.getChatVisibility()); } + @Deprecated public void setVisibility(ChatVisibility visibility) { - this.visibility = visibility; + this.setChatVisibility(visibility.modern); } + @Deprecated public boolean isChatColorable() { - return chatColorable; + return this.isChatColors(); } + @Deprecated public void setChatColorable(boolean chatColorable) { - this.chatColorable = chatColorable; + this.setChatColors(chatColorable); } + @Deprecated public byte getVisibleSkinSectionMask() { - return visibleSkinSectionMask; + return this.getSkinMask(); } + @Deprecated public void setVisibleSkinSectionMask(byte visibleSkinSectionMask) { - this.visibleSkinSectionMask = visibleSkinSectionMask; - } - - public SkinSection getVisibleSkinSection() { - return new SkinSection(getVisibleSkinSectionMask()); - } - - public void setVisibleSkinSections(SkinSection visibleSkinSection) { - this.visibleSkinSectionMask = visibleSkinSection.getMask(); + this.setSkinMask(visibleSkinSectionMask); } - public boolean isSkinSectionVisible(SkinSection section) { - return section.isSet(visibleSkinSectionMask); - } - - public void setSkinSectionVisible(SkinSection section, boolean visible) { - visibleSkinSectionMask = section.set(visibleSkinSectionMask, visible); - } - - public HumanoidArm getMainHand() { - return hand; - } - - public void setMainHand(HumanoidArm hand) { - this.hand = hand; - } + @Deprecated + public enum ChatVisibility { - public boolean isTextFilteringEnabled() { - return textFilteringEnabled; - } + FULL(WrapperCommonClientSettings.ChatVisibility.FULL), + SYSTEM(WrapperCommonClientSettings.ChatVisibility.SYSTEM), + HIDDEN(WrapperCommonClientSettings.ChatVisibility.HIDDEN); - public void setTextFilteringEnabled(boolean textFilteringEnabled) { - this.textFilteringEnabled = textFilteringEnabled; - } + public static final ChatVisibility[] VALUES = values(); + private static final Index MODERN_INDEX = + Index.create(ChatVisibility.class, visibility -> visibility.modern); - public boolean isServerListingAllowed() { - return allowServerListings; - } + private final WrapperCommonClientSettings.ChatVisibility modern; - public void setServerListingAllowed(boolean allowServerListings) { - this.allowServerListings = allowServerListings; + ChatVisibility(WrapperCommonClientSettings.ChatVisibility modern) { + this.modern = modern; + } } } From dd6eb173a0554319bb155bf37dfa8c05675bb735 Mon Sep 17 00:00:00 2001 From: booky10 Date: Mon, 21 Oct 2024 02:10:49 +0200 Subject: [PATCH 2/6] Fix ENTITY_POSITION_SYNC packet id --- .../packettype/clientbound/ClientboundPacketType_1_21_2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/packettype/clientbound/ClientboundPacketType_1_21_2.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/packettype/clientbound/ClientboundPacketType_1_21_2.java index d43dbadc7d..d879c1e758 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/packettype/clientbound/ClientboundPacketType_1_21_2.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/packettype/clientbound/ClientboundPacketType_1_21_2.java @@ -51,8 +51,8 @@ public enum ClientboundPacketType_1_21_2 { DELETE_CHAT, DISCONNECT, DISGUISED_CHAT, - ENTITY_POSITION_SYNC, // new packet ENTITY_STATUS, + ENTITY_POSITION_SYNC, // new packet EXPLOSION, UNLOAD_CHUNK, CHANGE_GAME_STATE, From bd499550d8b852ff4d458b7f6be141d50af09266 Mon Sep 17 00:00:00 2001 From: booky10 Date: Mon, 21 Oct 2024 02:19:10 +0200 Subject: [PATCH 3/6] Reuse entity position sync EntityPositionData in more places for 1.21.2 --- .../protocol/entity/EntityPositionData.java | 109 ++++++++++++++++++ .../WrapperPlayServerEntityPositionSync.java | 87 +------------- .../WrapperPlayServerEntityTeleport.java | 79 +++++++------ ...rapperPlayServerPlayerPositionAndLook.java | 86 +++++++------- 4 files changed, 196 insertions(+), 165 deletions(-) create mode 100644 api/src/main/java/com/github/retrooper/packetevents/protocol/entity/EntityPositionData.java diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/entity/EntityPositionData.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/entity/EntityPositionData.java new file mode 100644 index 0000000000..45d46bf1b3 --- /dev/null +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/entity/EntityPositionData.java @@ -0,0 +1,109 @@ +/* + * This file is part of packetevents - https://github.com/retrooper/packetevents + * Copyright (C) 2024 retrooper 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.github.retrooper.packetevents.protocol.entity; +// Created by booky10 in packetevents (02:12 21.10.2024) + +import com.github.retrooper.packetevents.util.Vector3d; +import com.github.retrooper.packetevents.wrapper.PacketWrapper; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityPositionSync; + +import java.util.Objects; + +public final class EntityPositionData { + + private Vector3d position; + private Vector3d deltaMovement; + private float yaw; + private float pitch; + + public EntityPositionData(Vector3d position, Vector3d deltaMovement, float yaw, float pitch) { + this.position = position; + this.deltaMovement = deltaMovement; + this.yaw = yaw; + this.pitch = pitch; + } + + public static EntityPositionData read(PacketWrapper wrapper) { + Vector3d position = Vector3d.read(wrapper); + Vector3d deltaMovement = Vector3d.read(wrapper); + float yaw = wrapper.readFloat(); + float pitch = wrapper.readFloat(); + return new EntityPositionData(position, deltaMovement, yaw, pitch); + } + + public static void write(PacketWrapper wrapper, EntityPositionData positionData) { + Vector3d.write(wrapper, positionData.position); + Vector3d.write(wrapper, positionData.deltaMovement); + wrapper.writeFloat(positionData.yaw); + wrapper.writeFloat(positionData.pitch); + } + + public Vector3d getPosition() { + return this.position; + } + + public void setPosition(Vector3d position) { + this.position = position; + } + + public Vector3d getDeltaMovement() { + return this.deltaMovement; + } + + public void setDeltaMovement(Vector3d deltaMovement) { + this.deltaMovement = deltaMovement; + } + + public float getYaw() { + return this.yaw; + } + + public void setYaw(float yaw) { + this.yaw = yaw; + } + + public float getPitch() { + return this.pitch; + } + + public void setPitch(float pitch) { + this.pitch = pitch; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof EntityPositionData)) return false; + EntityPositionData that = (EntityPositionData) obj; + if (Float.compare(that.yaw, this.yaw) != 0) return false; + if (Float.compare(that.pitch, this.pitch) != 0) return false; + if (!this.position.equals(that.position)) return false; + return this.deltaMovement.equals(that.deltaMovement); + } + + @Override + public int hashCode() { + return Objects.hash(this.position, this.deltaMovement, this.yaw, this.pitch); + } + + @Override + public String toString() { + return "EntityPositionData{position=" + this.position + ", deltaMovement=" + this.deltaMovement + ", yaw=" + this.yaw + ", pitch=" + this.pitch + '}'; + } +} diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerEntityPositionSync.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerEntityPositionSync.java index 8a90f704bc..7e702fc745 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerEntityPositionSync.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerEntityPositionSync.java @@ -19,12 +19,10 @@ package com.github.retrooper.packetevents.wrapper.play.server; import com.github.retrooper.packetevents.event.PacketSendEvent; +import com.github.retrooper.packetevents.protocol.entity.EntityPositionData; import com.github.retrooper.packetevents.protocol.packettype.PacketType; -import com.github.retrooper.packetevents.util.Vector3d; import com.github.retrooper.packetevents.wrapper.PacketWrapper; -import java.util.Objects; - public class WrapperPlayServerEntityPositionSync extends PacketWrapper { private int id; @@ -86,87 +84,4 @@ public boolean isOnGround() { public void setOnGround(boolean onGround) { this.onGround = onGround; } - - public static final class EntityPositionData { - - private Vector3d position; - private Vector3d deltaMovement; - private float yaw; - private float pitch; - - public EntityPositionData(Vector3d position, Vector3d deltaMovement, float yaw, float pitch) { - this.position = position; - this.deltaMovement = deltaMovement; - this.yaw = yaw; - this.pitch = pitch; - } - - public static EntityPositionData read(PacketWrapper wrapper) { - Vector3d position = Vector3d.read(wrapper); - Vector3d deltaMovement = Vector3d.read(wrapper); - float yaw = wrapper.readFloat(); - float pitch = wrapper.readFloat(); - return new EntityPositionData(position, deltaMovement, yaw, pitch); - } - - public static void write(PacketWrapper wrapper, EntityPositionData positionData) { - Vector3d.write(wrapper, positionData.position); - Vector3d.write(wrapper, positionData.deltaMovement); - wrapper.writeFloat(positionData.yaw); - wrapper.writeFloat(positionData.pitch); - } - - public Vector3d getPosition() { - return this.position; - } - - public void setPosition(Vector3d position) { - this.position = position; - } - - public Vector3d getDeltaMovement() { - return this.deltaMovement; - } - - public void setDeltaMovement(Vector3d deltaMovement) { - this.deltaMovement = deltaMovement; - } - - public float getYaw() { - return this.yaw; - } - - public void setYaw(float yaw) { - this.yaw = yaw; - } - - public float getPitch() { - return this.pitch; - } - - public void setPitch(float pitch) { - this.pitch = pitch; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (!(obj instanceof EntityPositionData)) return false; - EntityPositionData that = (EntityPositionData) obj; - if (Float.compare(that.yaw, this.yaw) != 0) return false; - if (Float.compare(that.pitch, this.pitch) != 0) return false; - if (!this.position.equals(that.position)) return false; - return this.deltaMovement.equals(that.deltaMovement); - } - - @Override - public int hashCode() { - return Objects.hash(this.position, this.deltaMovement, this.yaw, this.pitch); - } - - @Override - public String toString() { - return "EntityPositionData{position=" + this.position + ", deltaMovement=" + this.deltaMovement + ", yaw=" + this.yaw + ", pitch=" + this.pitch + '}'; - } - } } diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerEntityTeleport.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerEntityTeleport.java index 428a63c4c1..3c8679ae65 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerEntityTeleport.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerEntityTeleport.java @@ -20,6 +20,7 @@ import com.github.retrooper.packetevents.event.PacketSendEvent; import com.github.retrooper.packetevents.manager.server.ServerVersion; +import com.github.retrooper.packetevents.protocol.entity.EntityPositionData; import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.teleport.RelativeFlag; import com.github.retrooper.packetevents.protocol.world.Location; @@ -35,12 +36,12 @@ public class WrapperPlayServerEntityTeleport extends PacketWrapper + * In versions before 1.21.2, the {@link EntityPositionData#getDeltaMovement()} will always be zero. */ - private Vector3d deltaMovement; - private float yaw, pitch; + private EntityPositionData values; /** * Added with 1.21.2 */ @@ -62,13 +63,16 @@ public WrapperPlayServerEntityTeleport(int entityID, Vector3d position, float ya public WrapperPlayServerEntityTeleport( int entityID, Vector3d position, Vector3d deltaMovement, float yaw, float pitch, RelativeFlag relativeFlags, boolean onGround + ) { + this(entityID, new EntityPositionData(position, deltaMovement, yaw, pitch), relativeFlags, onGround); + } + + public WrapperPlayServerEntityTeleport( + int entityID, EntityPositionData values, RelativeFlag relativeFlags, boolean onGround ) { super(PacketType.Play.Server.ENTITY_TELEPORT); this.entityID = entityID; - this.position = position; - this.deltaMovement = deltaMovement; - this.yaw = yaw; - this.pitch = pitch; + this.values = values; this.relativeFlags = relativeFlags; this.onGround = onGround; } @@ -77,17 +81,15 @@ public WrapperPlayServerEntityTeleport( public void read() { if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2)) { this.entityID = this.readVarInt(); - this.position = Vector3d.read(this); - this.deltaMovement = Vector3d.read(this); - this.yaw = this.readFloat(); - this.pitch = this.readFloat(); + this.values = EntityPositionData.read(this); this.relativeFlags = new RelativeFlag(this.readInt()); } else { this.entityID = this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_8) ? this.readVarInt() : this.readInt(); - this.position = this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9) ? Vector3d.read(this) : + Vector3d position = this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9) ? Vector3d.read(this) : new Vector3d(this.readInt() / 32d, this.readInt() / 32d, this.readInt() / 32d); - this.yaw = this.readByte() / ROTATION_FACTOR; - this.pitch = this.readByte() / ROTATION_FACTOR; + float yaw = this.readByte() / ROTATION_FACTOR; + float pitch = this.readByte() / ROTATION_FACTOR; + this.values = new EntityPositionData(position, Vector3d.zero(), yaw, pitch); } if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_8)) { this.onGround = this.readBoolean(); @@ -98,10 +100,7 @@ public void read() { public void write() { if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2)) { this.writeVarInt(this.entityID); - Vector3d.write(this, this.position); - Vector3d.write(this, this.deltaMovement); - this.writeFloat(this.yaw); - this.writeFloat(this.pitch); + EntityPositionData.write(this, this.values); this.writeInt(this.relativeFlags.getFullMask()); } else { if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_8)) { @@ -110,14 +109,15 @@ public void write() { this.writeInt(this.entityID); } if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9)) { - Vector3d.write(this, this.position); + Vector3d.write(this, this.values.getPosition()); } else { - this.writeInt(MathUtil.floor(this.position.x * 32d)); - this.writeInt(MathUtil.floor(this.position.y * 32d)); - this.writeInt(MathUtil.floor(this.position.z * 32d)); + Vector3d pos = this.values.getPosition(); + this.writeInt(MathUtil.floor(pos.x * 32d)); + this.writeInt(MathUtil.floor(pos.y * 32d)); + this.writeInt(MathUtil.floor(pos.z * 32d)); } - this.writeByte((int) (this.yaw * ROTATION_FACTOR)); - this.writeByte((int) (this.pitch * ROTATION_FACTOR)); + this.writeByte((int) (this.values.getYaw() * ROTATION_FACTOR)); + this.writeByte((int) (this.values.getPitch() * ROTATION_FACTOR)); } if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_8)) { this.writeBoolean(this.onGround); @@ -127,10 +127,7 @@ public void write() { @Override public void copy(WrapperPlayServerEntityTeleport wrapper) { this.entityID = wrapper.entityID; - this.position = wrapper.position; - this.deltaMovement = wrapper.deltaMovement; - this.yaw = wrapper.yaw; - this.pitch = wrapper.pitch; + this.values = wrapper.values; this.relativeFlags = wrapper.relativeFlags; this.onGround = wrapper.onGround; } @@ -143,36 +140,44 @@ public void setEntityId(int entityID) { this.entityID = entityID; } + public EntityPositionData getValues() { + return this.values; + } + + public void setValues(EntityPositionData values) { + this.values = values; + } + public Vector3d getPosition() { - return this.position; + return this.values.getPosition(); } public void setPosition(Vector3d position) { - this.position = position; + this.values.setPosition(position); } public Vector3d getDeltaMovement() { - return this.deltaMovement; + return this.values.getDeltaMovement(); } public void setDeltaMovement(Vector3d deltaMovement) { - this.deltaMovement = deltaMovement; + this.values.setDeltaMovement(deltaMovement); } public float getYaw() { - return this.yaw; + return this.values.getYaw(); } public void setYaw(float yaw) { - this.yaw = yaw; + this.values.setYaw(yaw); } public float getPitch() { - return this.pitch; + return this.values.getPitch(); } public void setPitch(float pitch) { - this.pitch = pitch; + this.values.setPitch(pitch); } public RelativeFlag getRelativeFlags() { diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerPlayerPositionAndLook.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerPlayerPositionAndLook.java index c215cc7efb..a131c36551 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerPlayerPositionAndLook.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerPlayerPositionAndLook.java @@ -2,6 +2,7 @@ import com.github.retrooper.packetevents.event.PacketSendEvent; import com.github.retrooper.packetevents.manager.server.ServerVersion; +import com.github.retrooper.packetevents.protocol.entity.EntityPositionData; import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.teleport.RelativeFlag; import com.github.retrooper.packetevents.util.Vector3d; @@ -15,13 +16,12 @@ public class WrapperPlayServerPlayerPositionAndLook extends PacketWrapper { private int teleportId; - private Vector3d position; /** - * Added with 1.21.2 + * Changed with 1.21.2 + *

+ * In versions before 1.21.2, the {@link EntityPositionData#getDeltaMovement()} will always be zero. */ - private Vector3d deltaMovement; - private float yaw; - private float pitch; + private EntityPositionData values; private RelativeFlag relativeFlags; /** @@ -67,13 +67,16 @@ public WrapperPlayServerPlayerPositionAndLook( public WrapperPlayServerPlayerPositionAndLook( int teleportId, Vector3d position, Vector3d deltaMovement, float yaw, float pitch, RelativeFlag flags + ) { + this(teleportId, new EntityPositionData(position, deltaMovement, yaw, pitch), flags); + } + + public WrapperPlayServerPlayerPositionAndLook( + int teleportId, EntityPositionData values, RelativeFlag flags ) { super(PacketType.Play.Server.PLAYER_POSITION_AND_LOOK); this.teleportId = teleportId; - this.position = position; - this.deltaMovement = deltaMovement; - this.yaw = yaw; - this.pitch = pitch; + this.values = values; this.relativeFlags = flags; } @@ -81,16 +84,13 @@ public WrapperPlayServerPlayerPositionAndLook( public void read() { if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2)) { this.teleportId = this.readVarInt(); - this.position = Vector3d.read(this); - this.deltaMovement = Vector3d.read(this); - this.yaw = this.readFloat(); - this.pitch = this.readFloat(); + this.values = EntityPositionData.read(this); this.relativeFlags = new RelativeFlag(this.readInt()); } else { - this.position = Vector3d.read(this); - this.deltaMovement = Vector3d.zero(); - this.yaw = this.readFloat(); - this.pitch = this.readFloat(); + Vector3d position = Vector3d.read(this); + float yaw = this.readFloat(); + float pitch = this.readFloat(); + this.values = new EntityPositionData(position, Vector3d.zero(), yaw, pitch); this.relativeFlags = new RelativeFlag(this.readUnsignedByte()); if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9)) { this.teleportId = this.readVarInt(); @@ -106,15 +106,12 @@ public void read() { public void write() { if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2)) { this.writeVarInt(this.teleportId); - Vector3d.write(this, this.position); - Vector3d.write(this, this.deltaMovement); - this.writeFloat(this.yaw); - this.writeFloat(this.pitch); + EntityPositionData.write(this, this.values); this.writeInt(this.relativeFlags.getFullMask()); } else { - Vector3d.write(this, this.position); - this.writeFloat(this.yaw); - this.writeFloat(this.pitch); + Vector3d.write(this, this.values.getPosition()); + this.writeFloat(this.values.getYaw()); + this.writeFloat(this.values.getPitch()); this.writeByte(this.relativeFlags.getFullMask()); if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_9)) { this.writeVarInt(this.teleportId); @@ -129,10 +126,7 @@ public void write() { @Override public void copy(WrapperPlayServerPlayerPositionAndLook wrapper) { this.teleportId = wrapper.teleportId; - this.position = wrapper.position; - this.deltaMovement = wrapper.deltaMovement; - this.yaw = wrapper.yaw; - this.pitch = wrapper.pitch; + this.values = wrapper.values; this.relativeFlags = wrapper.relativeFlags; this.dismountVehicle = wrapper.dismountVehicle; } @@ -145,60 +139,68 @@ public void setTeleportId(int teleportId) { this.teleportId = teleportId; } + public EntityPositionData getValues() { + return this.values; + } + + public void setValues(EntityPositionData values) { + this.values = values; + } + public Vector3d getPosition() { - return this.position; + return this.values.getPosition(); } public void setPosition(Vector3d position) { - this.position = position; + this.values.setPosition(position); } public double getX() { - return this.position.x; + return this.getPosition().getX(); } public void setX(double x) { - this.position = new Vector3d(x, this.getY(), this.getZ()); + this.setPosition(new Vector3d(x, this.getY(), this.getZ())); } public double getY() { - return this.position.y; + return this.getPosition().getY(); } public void setY(double y) { - this.position = new Vector3d(this.getX(), y, this.getZ()); + this.setPosition(new Vector3d(this.getX(), y, this.getZ())); } public double getZ() { - return this.position.z; + return this.getPosition().getZ(); } public void setZ(double z) { - this.position = new Vector3d(this.getX(), this.getY(), z); + this.setPosition(new Vector3d(this.getX(), this.getY(), z)); } public Vector3d getDeltaMovement() { - return this.deltaMovement; + return this.values.getDeltaMovement(); } public void setDeltaMovement(Vector3d deltaMovement) { - this.deltaMovement = deltaMovement; + this.values.setDeltaMovement(deltaMovement); } public float getYaw() { - return this.yaw; + return this.values.getYaw(); } public void setYaw(float yaw) { - this.yaw = yaw; + this.values.setYaw(yaw); } public float getPitch() { - return this.pitch; + return this.values.getPitch(); } public void setPitch(float pitch) { - this.pitch = pitch; + this.values.setPitch(pitch); } /** From 9391b16f50c9c5b4cf491a17686c4bdd4d815b69 Mon Sep 17 00:00:00 2001 From: booky10 Date: Mon, 21 Oct 2024 02:21:32 +0200 Subject: [PATCH 4/6] Fix missing sealevel write in login packet --- .../wrapper/play/server/WrapperPlayServerJoinGame.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerJoinGame.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerJoinGame.java index accafafa56..ca7b21181e 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerJoinGame.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerJoinGame.java @@ -456,6 +456,9 @@ public void write() { int pCooldown = portalCooldown != null ? portalCooldown : 0; writeVarInt(pCooldown); } + if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2)) { + this.writeVarInt(this.seaLevel); + } if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_20_5)) { writeBoolean(enforcesSecureChat); } From eda7d9273f6d8fbca22c52628854ac57d1ca8d3f Mon Sep 17 00:00:00 2001 From: booky10 Date: Mon, 21 Oct 2024 02:29:17 +0200 Subject: [PATCH 5/6] Fix serialization of SingleInputOptionDisplay --- .../protocol/recipe/SingleInputOptionDisplay.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/SingleInputOptionDisplay.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/SingleInputOptionDisplay.java index c449e07d58..eac994caa9 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/SingleInputOptionDisplay.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/SingleInputOptionDisplay.java @@ -18,6 +18,9 @@ package com.github.retrooper.packetevents.protocol.recipe; +import com.github.retrooper.packetevents.protocol.item.type.ItemType; +import com.github.retrooper.packetevents.protocol.item.type.ItemTypes; +import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet; import com.github.retrooper.packetevents.protocol.recipe.display.slot.SlotDisplay; import com.github.retrooper.packetevents.wrapper.PacketWrapper; @@ -31,30 +34,30 @@ */ public class SingleInputOptionDisplay { - private Ingredient input; + private MappedEntitySet input; private SlotDisplay optionDisplay; - public SingleInputOptionDisplay(Ingredient input, SlotDisplay optionDisplay) { + public SingleInputOptionDisplay(MappedEntitySet input, SlotDisplay optionDisplay) { this.input = input; this.optionDisplay = optionDisplay; } public static SingleInputOptionDisplay read(PacketWrapper wrapper) { - Ingredient ingredient = Ingredient.read(wrapper); + MappedEntitySet ingredient = MappedEntitySet.read(wrapper, ItemTypes.getRegistry()); SlotDisplay optionDisplay = SlotDisplay.read(wrapper); return new SingleInputOptionDisplay(ingredient, optionDisplay); } public static void write(PacketWrapper wrapper, SingleInputOptionDisplay recipe) { - Ingredient.write(wrapper, recipe.input); + MappedEntitySet.write(wrapper, recipe.input); SlotDisplay.write(wrapper, recipe.optionDisplay); } - public Ingredient getInput() { + public MappedEntitySet getInput() { return this.input; } - public void setInput(Ingredient input) { + public void setInput(MappedEntitySet input) { this.input = input; } From 52b6cb6a71c57fe3c710ab53559084d977db1555 Mon Sep 17 00:00:00 2001 From: booky10 Date: Mon, 21 Oct 2024 02:29:24 +0200 Subject: [PATCH 6/6] Fix writing of WrapperPlayClientCraftRecipeRequest --- .../play/client/WrapperPlayClientCraftRecipeRequest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientCraftRecipeRequest.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientCraftRecipeRequest.java index b77b3b6ae6..332769612b 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientCraftRecipeRequest.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientCraftRecipeRequest.java @@ -80,7 +80,8 @@ public void read() { @Override public void write() { this.writeContainerId(this.windowId); - if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_13)) { + if (this.serverVersion.isOlderThan(ServerVersion.V_1_21_2) + && this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_13)) { this.writeIdentifier(this.recipeKey); } else { RecipeDisplayId.write(this, this.recipeId);