diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 49db6bdc0..381d64dc8 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1443,11 +1443,12 @@ impl Game<'_> { let name = self.res.facts.get(state).name.clone(); self.release_contents([pos.x, pos.y, pos.z], entity, &name); } - let drops = self.res.items.block_drops( + let drops = self.res.items.block_drops_in( self.res.assets.registry, state, None, &mut self.world.random, + Some((&mut self.rand_sequences, self.level.seed)), ); for d in drops { if &*d.item != "minecraft:air" { @@ -1794,11 +1795,12 @@ impl Game<'_> { let harvest = !facts.requires_tool || self.res.items.correct_for_drops(held.as_ref(), &facts.name); if harvest { - let drops = self.res.items.block_drops( + let drops = self.res.items.block_drops_in( self.res.assets.registry, state, held.as_ref(), &mut self.world.random, + Some((&mut self.rand_sequences, self.level.seed)), ); let silk = held .as_ref() diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index be0a6b0df..3c8a406cc 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -511,6 +511,17 @@ impl Game<'_> { return; } self.check_inventory_trigger(); + // ServerPlayer.tick: PlayerTrigger.TICK every tick. + let me = self.player_entity(); + self.trigger("minecraft:tick", |c, w| { + let ctx = adv::Entities { + this: Some(&me), + origin: me.position, + tool: None, + block_pos: None, + }; + adv::conditions(&c["player"], &ctx, w) + }); if self.ticks.is_multiple_of(20) { let me = self.player_entity(); self.trigger("minecraft:location", |c, w| { diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index c2585d49d..880091491 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -98,6 +98,10 @@ impl Game<'_> { self.command_failure(e.message); } } + // InventoryChangeTrigger fires as slots change, not on the next tick. + if self.player.is_some() { + self.check_inventory_trigger(); + } } fn syntax_failure(&mut self, e: &CommandError, command: &str) { self.command_failure(e.message.clone()); diff --git a/crates/horizon-client/src/game/commands/world_cmds.rs b/crates/horizon-client/src/game/commands/world_cmds.rs index bd00c40f1..e006b8f89 100644 --- a/crates/horizon-client/src/game/commands/world_cmds.rs +++ b/crates/horizon-client/src/game/commands/world_cmds.rs @@ -31,7 +31,38 @@ impl Game<'_> { // ---- /recipe ----------------------------------------------------------- /// Every `minecraft:` recipe that `/recipe` can give (non-special ones). + /// `Recipe.display().size()`. + fn recipe_display_count(&self, id: &str) -> i32 { + let path = self.options.resources.join(format!( + "data/minecraft/recipe/{}.json", + id.trim_start_matches("minecraft:") + )); + let Some(v) = std::fs::read(path) + .ok() + .and_then(|b| serde_json::from_slice::(&b).ok()) + else { + return 1; + }; + if v["type"].as_str() != Some("minecraft:crafting_transmute") { + return 1; + } + // TransmuteRecipe: material_count defaults to exactly 1; open + // bounds are 1 and 8. + let (min, max) = match &v["material_count"] { + serde_json::Value::Null => (1, 1), + serde_json::Value::Number(n) => { + let n = n.as_i64().unwrap_or(1); + (n, n) + } + b => (b["min"].as_i64().unwrap_or(1), b["max"].as_i64().unwrap_or(8)), + }; + (max - min + 1).max(0) as i32 + } pub(super) fn learnable_recipes(&self) -> Vec { + // RecipeManager's learnable (non-special) recipes, as exported. + if !self.ui.registries.learnable_recipes.is_empty() { + return self.ui.registries.learnable_recipes.clone(); + } let dir = self.options.resources.join("data/minecraft/recipe"); let mut out = Vec::new(); let Ok(entries) = std::fs::read_dir(&dir) else { @@ -72,14 +103,27 @@ impl Game<'_> { let mut tracker = Tracker::default(); for &t in &targets { let h = holder(self.target_name(t)); + // ServerRecipeBook.addRecipes/removeRecipes count recipe book + // displays (a transmute recipe has one per material count). let mut n = 0; + let mut unlocked = Vec::new(); for r in &recipes { let changed = if give { self.adv.recipes.insert(r.clone()) } else { self.adv.recipes.remove(r) }; - n += i32::from(changed); + if changed { + n += self.recipe_display_count(r); + if give { + unlocked.push(r.clone()); + } + } + } + for r in unlocked { + self.trigger("minecraft:recipe_unlocked", |c, _| { + c["recipes"].as_str() == Some(r.as_str()) + }); } tracker.track(&h, n); } diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 50d0d1aab..af6c90f24 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -1061,11 +1061,12 @@ impl Game<'_> { let old = self.world.block(pos[0], pos[1], pos[2]); self.destroy_particles(pos, old); if drop { - let drops = self.res.items.block_drops( + let drops = self.res.items.block_drops_in( self.res.assets.registry, old, None, &mut self.world.random, + Some((&mut self.rand_sequences, self.level.seed)), ); for d in drops { self.pop_resource(pos, d); diff --git a/crates/horizon-client/src/game/explosion.rs b/crates/horizon-client/src/game/explosion.rs index 4bd13bd15..d42996f24 100644 --- a/crates/horizon-client/src/game/explosion.rs +++ b/crates/horizon-client/src/game/explosion.rs @@ -391,11 +391,12 @@ impl Game<'_> { let name = self.res.facts.get(state).name.clone(); let is_tnt = &*name == "minecraft:tnt"; if !is_tnt { - let drops = self.res.items.block_drops( + let drops = self.res.items.block_drops_in( self.res.assets.registry, state, None, &mut self.world.random, + Some((&mut self.rand_sequences, self.level.seed)), ); for stack in drops { if &*stack.item == "minecraft:air" || stack.count == 0 { diff --git a/crates/horizon-client/src/items.rs b/crates/horizon-client/src/items.rs index 1aa72b554..b9fa89fdf 100644 --- a/crates/horizon-client/src/items.rs +++ b/crates/horizon-client/src/items.rs @@ -553,6 +553,18 @@ impl Items { state: BlockStateId, held: Option<&ItemStack>, random: &mut R, + ) -> Vec { + self.block_drops_in(registry, state, held, random, None) + } + /// `block_drops` drawing from the table's random sequence when it has one + /// (`sequences`: the world's sequences and seed), as BlockState.getDrops. + pub fn block_drops_in( + &self, + registry: &BlockRegistry, + state: BlockStateId, + held: Option<&ItemStack>, + random: &mut R, + sequences: Option<(&mut crate::random_sequences::RandomSequences, i64)>, ) -> Vec { let Some(block) = registry.state(state) else { return vec![]; @@ -570,6 +582,21 @@ impl Items { let Some(table) = table else { return vec![]; }; + // LootTable.getRandomItems draws from the table's random sequence. + if let (Some(seq), Some(sequences)) = ( + table.get("random_sequence").and_then(Value::as_str), + sequences, + ) { + let random = sequences.0.get(seq, sequences.1); + let ctx = LootContext { + items: self, + block: &block.name, + properties: &block.properties, + held, + killed_by_player: false, + }; + return ctx.evaluate(table, random); + } let ctx = LootContext { items: self, block: &block.name,