Fix recipe book settings persistence on the server

Send open/filter changes to the authoritative player's recipe book and cover packet settings plus save/reopen in both single-player modes.

Co-Authored-By: OpenCode GPT-6.1 Sol <noreply@opencode.ai>
This commit is contained in:
rdbtCVS
2026-10-26 17:11:51 +00:00
parent 93e3096e06
commit de141bb7cb
10 changed files with 236 additions and 6 deletions
@@ -2219,6 +2219,7 @@ packet_enum!(Serverbound, crate::ids::play::serverbound {
ChatCommandSigned(ChatCommandSigned) = CHAT_COMMAND_SIGNED,
ChatSessionUpdate(ChatSessionUpdate) = CHAT_SESSION_UPDATE,
PlaceRecipe(super::recipes::PlaceRecipe) = PLACE_RECIPE,
RecipeBookChangeSettings(super::recipes::RecipeBookChangeSettings) = RECIPE_BOOK_CHANGE_SETTINGS,
ChunkBatchReceived(ChunkBatchReceived) = CHUNK_BATCH_RECEIVED,
ClientCommand(ClientCommand) = CLIENT_COMMAND,
ClientInformation(ClientInformation) = CLIENT_INFORMATION,
@@ -500,6 +500,33 @@ impl Codec<RecipeBookSettings> for RecipeBookSettings {
}
}
/// ServerboundRecipeBookChangeSettingsPacket: the active book's open and
/// filtering flags, with its `RecipeBookType` ordinal as a VarInt.
#[derive(Clone, Debug, PartialEq)]
pub struct RecipeBookChangeSettings {
pub book_type: i32,
pub open: bool,
pub filtering: bool,
}
impl Codec<RecipeBookChangeSettings> for RecipeBookChangeSettings {
fn read(r: &mut Reader) -> Result<Self> {
let book_type = r.varint()?;
if !(0..4).contains(&book_type) {
return Err(crate::Error::new("invalid recipe book type"));
}
Ok(Self {
book_type,
open: r.bool()?,
filtering: r.bool()?,
})
}
fn write(v: &Self, w: &mut Writer) {
w.varint(v.book_type);
w.bool(v.open);
w.bool(v.filtering);
}
}
/// ClientboundPlaceGhostRecipePacket: the recipe to show faded in a menu
/// whose items were missing.
#[derive(Clone, Debug, PartialEq)]