Merge pull request #1476 from ludovic111/fix/st-held-use

🤖 Agent: merged after verify and CI parity passed, built merged with current main (st-default-1: server-thread gaps checked against vanilla, each with a lan_e2e check that fails on main and passes here, host and guest, both modes; tables in the PR body).
This commit is contained in:
Ludovic Marie
2026-10-24 03:43:11 +02:00
committed by GitHub
7 changed files with 242 additions and 28 deletions
+26
View File
@@ -32,6 +32,7 @@ pub mod component {
pub const DYED_COLOR: i32 = 47;
pub const MAP_ID: i32 = 48;
pub const MAP_POST_PROCESSING: i32 = 50;
pub const CHARGED_PROJECTILES: i32 = 51;
pub const WRITABLE_BOOK_CONTENT: i32 = 56;
pub const WRITTEN_BOOK_CONTENT: i32 = 57;
}
@@ -75,6 +76,8 @@ pub enum Component {
/// `WritableBookContent`: the pages (raw text).
WritableBook(Vec<String>),
WrittenBook(WrittenBook),
/// `ChargedProjectiles`: a loaded crossbow's ammunition, as templates.
Stacks(Vec<Stack>),
}
/// `Filterable.streamCodec`: the raw value, then an optional filtered one
@@ -125,6 +128,10 @@ impl Component {
resolved: r.bool()?,
})
}
CHARGED_PROJECTILES => {
let n = r.count(1024)?;
Self::Stacks((0..n).map(|_| Template::read(r)).collect::<Result<_>>()?)
}
DYED_COLOR => Self::Int(r.i32()?),
UNBREAKABLE | CREATIVE_SLOT_LOCK => Self::Unit,
ENCHANTMENT_GLINT_OVERRIDE => Self::Bool(r.bool()?),
@@ -283,6 +290,10 @@ impl Component {
w.varint(hidden.len() as i32);
hidden.iter().for_each(|h| w.varint(*h));
}
Self::Stacks(stacks) => {
w.varint(stacks.len() as i32);
stacks.iter().for_each(|s| Template::write(s, w));
}
Self::WritableBook(pages) => {
w.varint(pages.len() as i32);
for page in pages {
@@ -533,6 +544,21 @@ mod tests {
round::<Option<Hashed>, HashedSlot>(None);
}
#[test]
fn charged_projectiles_are_item_stack_templates() {
// A crossbow (id 7) loaded with one arrow (id 9): ChargedProjectiles
// is a list of ItemStackTemplate, the item before the count.
let bytes = [1, 7, 1, 0, 51, 1, 9, 1, 0, 0];
let stack = Slot::read(&mut Reader::new(&bytes)).unwrap().unwrap();
assert_eq!(
stack.component(component::CHARGED_PROJECTILES),
Some(&Component::Stacks(vec![Stack::new(9, 1)]))
);
let mut w = Writer::new();
Slot::write(&Some(stack), &mut w);
assert_eq!(w.data, bytes);
}
#[test]
fn filtered_book_pages_are_read_and_dropped() {
// A writable book with one page "hi" and its filtered "**".