Merge pull request #10101 from DUzzL/fix/10051-frame-item-count

Keep one item in item frames filled by /item or NBT
This commit is contained in:
Kacper authored and GitHub committed 2026-11-06 08:59:35 +01:00
commit 208f1c010f
3 files changed
+22 -4

No files matched your search

+4 -1
View File
@@ -3235,7 +3235,10 @@ pub fn item_frame_from_nbt(tag: &Tag, id: u32) -> Option<ItemFrame> {
pos,
facing: number(tag.get("Facing")).unwrap_or(2).clamp(0, 5) as u8,
glow: kind(tag).as_deref() == Some("minecraft:glow_item_frame"),
item: tag.get("Item").and_then(item_from_nbt),
item: tag
.get("Item")
.and_then(item_from_nbt)
.map(|s| crate::items::ItemStack { count: 1, ..s }),
rotation: (number(tag.get("ItemRotation")).unwrap_or(0) & 7) as u8,
drop_chance: float(tag.get("ItemDropChance")).map_or(1.0, |v| v as f32),
fixed: flag(tag, "Fixed"),
@@ -635,9 +635,9 @@ impl Game<'_> {
}
true
}
Slot::Frame(id) => match self.item_frames.iter_mut().find(|f| f.id == *id) {
Some(f) => {
f.item = stack;
Slot::Frame(id) => match self.item_frames.iter().position(|f| f.id == *id) {
Some(i) => {
self.set_frame_item(i, stack);
true
}
None => false,
+15
View File
@@ -379,6 +379,21 @@ impl Game<'_> {
}
true
}
/// `ItemFrame.setItem(stack, true)`: keeps one item, plays the add sound
/// for a non-empty stack and updates the comparators.
pub(super) fn set_frame_item(&mut self, i: usize, stack: Option<ItemStack>) {
let f = &mut self.item_frames[i];
f.item = stack.map(|s| ItemStack { count: 1, ..s });
let (pos, filled) = (f.pos, f.item.is_some());
if filled {
let (name, at) = (
sound(&self.item_frames[i], "add_item"),
center(&self.item_frames[i]),
);
self.audio.play(&name, Some(at), 1.0, 1.0);
}
self.frame_output_changed(pos);
}
/// `ItemFrame.setItem` / `setRotation`: `updateNeighbourForOutputSignal`, so
/// the comparators reading the frame take its new signal.
fn frame_output_changed(&mut self, pos: [i32; 3]) {