Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
A furnace fuel leaves its crafting remainder, not only a bucket
Akirabane92967740a6dc
diff --git a/crates/horizon-client/src/furnace.rs b/crates/horizon-client/src/furnace.rsindex 9d8ce4392..dd111e709 100644--- a/crates/horizon-client/src/furnace.rs+++ b/crates/horizon-client/src/furnace.rs@@ -6,7 +6,6 @@ use crate::{items::{ItemStack, Items},providers::Providers,};-use std::sync::Arc;/// The furnace methods that read the recipes.pub trait FurnaceCooking {@@ -22,15 +21,15 @@ pub trait FurnaceCooking {/// (`Slot.setByPlayer`; partial takes and merges keep the stack).fn input_clicked(&mut self, recipes: &Recipes, before: Option<ItemStack>);/// One server tick. Returns `Some(lit)` when the LIT block state must change.- fn tick(&mut self, recipes: &Recipes, items: &Items, providers: &Providers) -> Option<bool>;-}-fn remainder(item: &str) -> Option<&'static str> {- match item {- "minecraft:lava_bucket" | "minecraft:water_bucket" | "minecraft:milk_bucket" => {- Some("minecraft:bucket")- }- _ => None,- }+ /// `drops` collects what the furnace lets fall at its position+ /// (`Containers.dropItemStack`): the remainder of a fuel when more of it is left.+ fn tick(+ &mut self,+ recipes: &Recipes,+ items: &Items,+ providers: &Providers,+ drops: &mut Vec<ItemStack>,+ ) -> Option<bool>;}impl FurnaceCooking for Furnace {fn set_input(&mut self, recipes: &Recipes, stack: Option<ItemStack>) {@@ -59,7 +58,13 @@ impl FurnaceCooking for Furnace {self.set_input(recipes, after);}}- fn tick(&mut self, recipes: &Recipes, items: &Items, providers: &Providers) -> Option<bool> {+ fn tick(+ &mut self,+ recipes: &Recipes,+ items: &Items,+ providers: &Providers,+ drops: &mut Vec<ItemStack>,+ ) -> Option<bool> {let was_lit = self.lit_remaining > 0;let mut lit = false;if self.lit_remaining > 0 {@@ -101,16 +106,19 @@ impl FurnaceCooking for Furnace {(ratio * self.cooking_total as f32).ceil() as i32;}if time > 0 {+ // AbstractFurnaceBlockEntity.consumeFuel: the fuel's crafting+ // remainder takes the slot once the stack is used up, else+ // it is dropped.if let Some(f) = self.items[1].as_mut() {- let item = f.item.clone();+ let remainder = items+ .get(&f.item)+ .and_then(|i| i.crafting_remainder.as_deref())+ .map(|r| ItemStack::new(r, 1));f.count -= 1;if f.count == 0 {- self.items[1] = remainder(&item).map(|r| ItemStack {- item: Arc::from(r),- count: 1,- damage: 0,- extra: None,- });+ self.items[1] = remainder;+ } else if let Some(remainder) = remainder {+ drops.push(remainder);}}lit = true;@@ -171,3 +179,98 @@ fn total_time(time: u32, speed: f32) -> i32 {time as i32}}++#[cfg(test)]+mod tests {+ use super::*;+ use crate::{containers::FurnaceKind, items::Items};+ use horizon_world::loot::PackOverlay;+ use std::{collections::HashMap, fs};++ /// A furnace with `fuel` x `count` burning `test:ore` into `test:ingot`, over a+ /// data root holding that one recipe and an item table with two fuels: `test:coal`+ /// (no remainder) and `test:cell` (a content mod's item that leaves `test:husk`).+ fn burn(fuel: &str, count: u32) -> (Furnace, Vec<ItemStack>) {+ let root = std::env::temp_dir().join(format!(+ "horizon-furnace-remainder-{}-{}-{count}",+ std::process::id(),+ fuel.replace(':', "-")+ ));+ let _ = fs::remove_dir_all(&root);+ fs::create_dir_all(root.join("data/minecraft/recipe")).unwrap();+ fs::write(+ root.join("data/minecraft/recipe/test_ingot.json"),+ br#"{"type":"minecraft:smelting","ingredient":"test:ore","result":{"id":"test:ingot"}}"#,+ )+ .unwrap();+ fs::create_dir_all(root.join("data/minecraft/loot_table")).unwrap();+ let fuel_component =+ r#"{"minecraft:cooking_fuel": {"burn_time": 200, "speed_multiplier": 1.0}}"#;+ fs::write(+ root.join("items.json"),+ format!(+ r#"{{"test:ore": {{}}, "test:ingot": {{}}, "test:coal": {fuel_component}, "test:cell": {fuel_component}, "test:husk": {{}}}}"#+ ),+ )+ .unwrap();+ fs::write(+ root.join(horizon_items::items::MOD_CRAFT_REMAINDERS),+ r#"{"test:cell": "test:husk"}"#,+ )+ .unwrap();+ let items = Items::catalog(&root, &PackOverlay::NONE).unwrap();+ let recipes = Recipes::load(&root, &items, &PackOverlay::NONE).unwrap();+ let providers = Providers::load(&root);+ let mut furnace = Furnace {+ kind: FurnaceKind::Furnace,+ items: [+ Some(ItemStack::new("test:ore", 1)),+ Some(ItemStack::new(fuel, count)),+ None,+ ],+ lit_remaining: 0,+ lit_total: 0,+ cooking_timer: 0,+ cooking_total: 0,+ speed: 1.0,+ recipes_used: HashMap::new(),+ };+ let mut drops = Vec::new();+ let lit = furnace.tick(&recipes, &items, &providers, &mut drops);+ let _ = fs::remove_dir_all(&root);+ assert_eq!(lit, Some(true), "the fuel lit the furnace");+ (furnace, drops)+ }++ fn fuel_slot(furnace: &Furnace) -> Option<(&str, u32)> {+ furnace.items[1].as_ref().map(|s| (&*s.item, s.count))+ }++ /// `AbstractFurnaceBlockEntity.consumeFuel`: the last of a fuel with a remainder+ /// leaves it in the fuel slot.+ #[test]+ fn the_last_fuel_leaves_its_remainder_in_the_slot() {+ let (furnace, drops) = burn("test:cell", 1);+ assert_eq!(fuel_slot(&furnace), Some(("test:husk", 1)));+ assert!(drops.is_empty());+ }++ /// With more of the fuel left, the remainder is dropped at the furnace.+ #[test]+ fn a_fuel_still_in_the_stack_drops_its_remainder() {+ let (furnace, drops) = burn("test:cell", 3);+ assert_eq!(fuel_slot(&furnace), Some(("test:cell", 2)));+ assert_eq!(drops, vec![ItemStack::new("test:husk", 1)]);+ }++ /// A fuel without a remainder leaves nothing.+ #[test]+ fn a_fuel_without_a_remainder_leaves_nothing() {+ let (furnace, drops) = burn("test:coal", 1);+ assert_eq!(fuel_slot(&furnace), None);+ assert!(drops.is_empty());+ let (furnace, drops) = burn("test:coal", 2);+ assert_eq!(fuel_slot(&furnace), Some(("test:coal", 1)));+ assert!(drops.is_empty());+ }+}diff --git a/crates/horizon-client/src/game/block_entity_ticks.rs b/crates/horizon-client/src/game/block_entity_ticks.rsindex 6c78a2a70..5323f7466 100644--- a/crates/horizon-client/src/game/block_entity_ticks.rs+++ b/crates/horizon-client/src/game/block_entity_ticks.rs@@ -218,11 +218,17 @@ impl Game<'_> {let Some(BlockEntity::Furnace(f)) = self.world.block_entities.get_mut(&pos) else {return Ok(());};- let Some(lit) = f.tick(+ let mut drops = Vec::new();+ let lit = f.tick(world_recipes!(self),world_items!(self),self.res.providers(),- ) else {+ &mut drops,+ );+ for stack in drops {+ self.campfire_drop(pos, stack);+ }+ let Some(lit) = lit else {return Ok(());};let state = self.world.block(pos.0, pos.1, pos.2);diff --git a/crates/horizon-client/src/game/campfire.rs b/crates/horizon-client/src/game/campfire.rsindex 5d98521ec..a36cac471 100644--- a/crates/horizon-client/src/game/campfire.rs+++ b/crates/horizon-client/src/game/campfire.rs@@ -171,7 +171,7 @@ impl Game<'_> {/// `Containers.dropItemStack(level, x, y, z, stack)` at the block's/// integer position.- fn campfire_drop(&mut self, pos: Pos, stack: ItemStack) {+ pub(super) fn campfire_drop(&mut self, pos: Pos, stack: ItemStack) {let at = BlockPos::new(pos.0, pos.1, pos.2);for piece inhorizon_world::level::removal::drop_item_stack(&mut self.world.random, at, stack.count)diff --git a/docs/mods.md b/docs/mods.mdindex addd61281..94ef32e5c 100644--- a/docs/mods.md+++ b/docs/mods.md@@ -144,8 +144,8 @@ round-trip through saved NBT; negative zero is not supported. A key such asrecipe uses it, as a milk bucket leaves a bucket (vanilla's`Item.Properties.craftRemainder`, not a data component): a vanilla item orone of the mod's own, refused at load otherwise. It holds on the crafting-table, the inventory grid and the crafter, not yet as furnace fuel or in a-brewing stand. What the item leaves once eaten+table, the inventory grid, the crafter and as furnace fuel (the last of the stack leaves it in+the fuel slot, a stack with more left drops it), not yet in a brewing stand. What the item leaves once eatenor drunk is the `minecraft:use_remainder` component instead:```json