diff --git a/crates/horizon-client/examples/entity_anim_fixture.rs b/crates/horizon-client/examples/entity_anim_fixture.rs index 4864a680f..f03d91a21 100644 --- a/crates/horizon-client/examples/entity_anim_fixture.rs +++ b/crates/horizon-client/examples/entity_anim_fixture.rs @@ -370,6 +370,22 @@ fn main() -> horizon_client::Result<()> { }, &animations, ), + Species::CopperGolem => { + // CopperGolemRenderState's animation states, in the golem's slots. + for (slot, key) in [ + "idleAnimationState", + "interactionGetItem", + "interactionGetNoItem", + "interactionDropItem", + "interactionDropNoItem", + ] + .into_iter() + .enumerate() + { + mob.anim.states[slot] = started(key); + } + horizon_client::mobs::copper_golem::anim(&mob, s, p, &animations); + } Species::Rabbit => b_anim::rabbit( p, s, diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index 1afcd4f91..b0fa1cc3b 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -432,6 +432,17 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag { map.entry(key.into()).or_insert(value); } } + // CopperGolem.addAdditionalSaveData. + "minecraft:copper_golem" => { + map.insert( + "next_weather_age".into(), + Tag::Long(m.extra.vector[0] as i64), + ); + map.insert( + "weather_state".into(), + string(crate::mobs::copper_golem::WEATHER[m.extra.variant.min(3) as usize]), + ); + } _ => {} } crate::mobs::raider::write_nbt(m, map); @@ -739,6 +750,21 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - if m.species() == crate::mobs::Species::Sniffer { crate::mobs::sniffer::from_nbt(&mut m, tag); } + if m.species() == crate::mobs::Species::CopperGolem { + // CopperGolem.readAdditionalSaveData: -1 (unset) when missing. + m.extra.vector[0] = match tag.get("next_weather_age") { + Some(Tag::Long(v)) => *v as f64, + _ => -1.0, + }; + let weather = match tag.get("weather_state") { + Some(Tag::String(s)) => s.to_string_lossy(), + _ => String::new(), + }; + m.extra.variant = crate::mobs::copper_golem::WEATHER + .iter() + .position(|w| *w == weather) + .unwrap_or(0) as u8; + } m.extra.leash_pending = crate::mobs::leash::pending_from_nbt(tag.get("leash")); if m.species() == crate::mobs::Species::Warden { // The brain starts afresh: a minute before it digs back down. diff --git a/crates/horizon-client/src/game/copper_golems.rs b/crates/horizon-client/src/game/copper_golems.rs index 5c3798901..664be6672 100644 --- a/crates/horizon-client/src/game/copper_golems.rs +++ b/crates/horizon-client/src/game/copper_golems.rs @@ -689,14 +689,21 @@ impl Game<'_> { return false; }; set_held(&mut self.mobs[index], None); + // BehaviorUtils.throwItem: from 0.3 below the golem's eyes towards + // the player's feet at 0.3 blocks a tick, default pickup delay. let p = self.player.as_ref().map(|p| p.position); - let from = [at[0], at[1] + 0.9, at[2]]; + let eye = f64::from(self.mobs[index].eye_height()); + let from = [at[0], at[1] + eye - f64::from(0.3f32), at[2]]; let v = p.map_or([0.0; 3], |p| { - let d = [p.x - from[0], p.y + 1.0 - from[1], p.z - from[2]]; - let len = (d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt().max(1e-6); - [d[0] / len * 0.3, d[1] / len * 0.3 + 0.1, d[2] / len * 0.3] + let d = [p.x - at[0], p.y - at[1], p.z - at[2]]; + let len = (d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt(); + if len < 1.0e-5 { + return [0.0; 3]; + } + let k = f64::from(0.3f32); + [d[0] / len * k, d[1] / len * k, d[2] / len * k] }); - self.spawn_item(h, from, v, 40); + self.spawn_item(h, from, v, 10); return true; } let name = item; diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 27f11663d..03966f614 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -759,6 +759,13 @@ impl Game<'_> { } } }, + MobEvent::Gift { target, item } => { + if let Some(m) = self.mobs.iter_mut().find(|m| m.id == target) + && m.saddle_item().is_none() + { + m.set_saddle(Some(ItemStack::new(item, 1))); + } + } MobEvent::HurtSelf { mob, kind, amount } => { if let Some(m) = self.mobs.iter_mut().find(|m| m.id == mob) { m.damage(amount, horizon_client::mobs::Damage::of(kind)); diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 3763a3e5b..27a4a9db8 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -629,6 +629,12 @@ pub struct Mob { #[derive(Clone, Debug)] pub enum MobEvent { Sound(&'static str, [f64; 3], f32, f32), + /// `OfferFlowerGoal.stop`: the item goes to the target's antenna (saddle) + /// slot if it is empty, as a guaranteed drop. + Gift { + target: u32, + item: &'static str, + }, /// A sound event id that is not a static string (variant sounds). SoundId(String, [f64; 3], f32, f32), /// A level event's sound (`levelEvent`/`globalLevelEvent`): the client diff --git a/crates/horizon-client/src/mobs/copper_golem.rs b/crates/horizon-client/src/mobs/copper_golem.rs index 9b4792a1b..de037016c 100644 --- a/crates/horizon-client/src/mobs/copper_golem.rs +++ b/crates/horizon-client/src/mobs/copper_golem.rs @@ -14,8 +14,8 @@ use std::collections::HashMap; // Copper golem state: `variant` the weathering (0 unaffected .. 3 oxidized), // `variant3` the `CopperGolemState`, `main_hand` with `ints[1]` the carried -// stack, the saddle slot the antenna (`EQUIPMENT_SLOT_ANTENNA`), `egg_time` the next weathering tick (-1 -// unset, -2 waxed), `ints[0]` the idle animation start tick, `home` the chest +// stack, the saddle slot the antenna (`EQUIPMENT_SLOT_ANTENNA`), `vector[0]` +// the next weathering tick (-1 unset, -2 waxed), `ints[0]` the idle animation start tick, `home` the chest // being served with `positions` the visited chests, `point` where it walks, // `scratch` = [transport phase, ticks since reaching the target, interaction // state, transport cooldown ticks]. AnimationState slots: idle (0), getting an @@ -32,7 +32,8 @@ pub fn register(m: &mut Mob) { m.ai.nav.required_path_length = 48.0; m.ai.nav.can_open_doors = true; m.persistent = true; - m.extra.egg_time = -1; + // nextWeatheringTick starts unset (-1); waxed is -2. + m.extra.vector[0] = -1.0; m.extra.scratch[3] = 60 + m.random.next_int_bound(40).unwrap_or(0); let g = &mut m.ai.goals; g.add(0, Panic::new(1.5)); diff --git a/crates/horizon-client/src/mobs/golem.rs b/crates/horizon-client/src/mobs/golem.rs index 089f5f7fd..d4d67660b 100644 --- a/crates/horizon-client/src/mobs/golem.rs +++ b/crates/horizon-client/src/mobs/golem.rs @@ -142,9 +142,10 @@ impl Goal for OfferFlower { if !cx.w.daylight || m.random.next_int_bound(8000).unwrap_or(1) != 0 { return false; } + // The nearest of #candidate_for_iron_golem_gift: villagers and copper golems. self.villager = cx.w.nearby(m.position, 6.0, |s| { - s.species == Species::Villager && s.alive + matches!(s.species, Species::Villager | Species::CopperGolem) && s.alive }) .map(|s| s.id) .next(); @@ -157,8 +158,30 @@ impl Goal for OfferFlower { self.ticks = 400; m.extra.counter = 400; } - fn stop(&mut self, m: &mut Mob, _: &mut Cx) { + fn stop(&mut self, m: &mut Mob, cx: &mut Cx) { m.extra.counter = 0; + // A copper golem the offer ran out beside takes the poppy on its + // antenna (#accepts_iron_golem_gift) when it has none. + if self.ticks == 0 + && let Some(v) = self.villager.and_then(|v| cx.w.seen(v)) + && v.species == Species::CopperGolem + { + let b = m.bounds(); + let (lo, hi) = (b.min_position(), b.max_position()); + let (vlo, vhi) = (v.bounds.min_position(), v.bounds.max_position()); + if lo.x - 6.0 < vhi.x + && hi.x + 6.0 > vlo.x + && lo.y - 2.0 < vhi.y + && hi.y + 2.0 > vlo.y + && lo.z - 6.0 < vhi.z + && hi.z + 6.0 > vlo.z + { + cx.events.push(MobEvent::Gift { + target: v.id, + item: "minecraft:poppy", + }); + } + } self.villager = None; } fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rs index 7dce44559..cc8b24ead 100644 --- a/crates/horizon-client/src/mobs/render.rs +++ b/crates/horizon-client/src/mobs/render.rs @@ -292,6 +292,8 @@ pub fn body(m: &Mob) -> (String, String) { ) } } + // CopperGolemOxidationLevels: the texture of the weathering. + S::CopperGolem => (m.kind.model_key(), super::copper_golem::texture(m)), _ => (m.kind.model_key(), m.kind.texture.clone()), } } @@ -510,6 +512,11 @@ pub fn layers(m: &Mob) -> Vec { white, true, ), + // The copper golem's eyes glow (LivingEntityEmissiveLayer, eyes render type). + S::CopperGolem => { + let eyes = super::copper_golem::eye_texture(m); + push(&mut v, "copper_golem#eyes", &eyes, white, true); + } S::Spider | S::CaveSpider => push( &mut v, &m.kind.model_key(), diff --git a/tools/test_entity_death_loot_parity.py b/tools/test_entity_death_loot_parity.py index ecbd2c7c8..5f5e5cbdc 100644 --- a/tools/test_entity_death_loot_parity.py +++ b/tools/test_entity_death_loot_parity.py @@ -25,9 +25,9 @@ except ImportError: import test_rust_parity as base # Living entity types with an entity loot table that the corpus skips: players -# and stands are not mobs, the dragon dies over 200 ticks, and the giant and -# the copper golem are not Horizon mob types. -SKIPPED = {'player', 'mannequin', 'armor_stand', 'ender_dragon', 'giant', 'copper_golem'} +# and stands are not mobs, the dragon dies over 200 ticks, and the giant is +# not a Horizon mob type. +SKIPPED = {'player', 'mannequin', 'armor_stand', 'ender_dragon', 'giant'} # Types Horizon keeps body armour for in the head slot: their corpus wears # body items instead of helmets. BODY = {'horse', 'donkey', 'mule', 'skeleton_horse', 'zombie_horse', 'camel', 'camel_husk', 'llama', 'trader_llama', diff --git a/tools/test_entity_model_parity.py b/tools/test_entity_model_parity.py index 9f5d1090a..18ed6838f 100644 --- a/tools/test_entity_model_parity.py +++ b/tools/test_entity_model_parity.py @@ -58,7 +58,7 @@ EXTRAS = [ # Layers a renderer reuses for another entity under a different constant. SKIP_LAYERS = re.compile(r'(banner|bell|book|skull|head|chest|shulker_box|boat|cushion|conduit|leash|arrow|trident|' r'shield|elytra|spin_attack|ears|cape|decorated_pot|minecart|wind_charge|evoker_fangs|' - r'llama_spit|shulker_bullet|bee_stinger|end_crystal|armor_stand|copper_golem|#(helmet|chestplate|leggings|' + r'llama_spit|shulker_bullet|bee_stinger|end_crystal|armor_stand|copper_golem_\w+|#(helmet|chestplate|leggings|' r'boots|outer|armor|decor|saddle|collar|wool|wool_undercoat|eyes|wind|inner|pattern|tendrils|' r'heart|bioluminescent|pulsating_spots|water_patch|flag|cage|shell)$)') @@ -189,6 +189,10 @@ SPECIES = { {'tongueAnimationState': 3}, {'swimIdleAnimationState': 2, 'isSwimming': T}], 'rabbit': [{'hopAnimationState': 2}, {'idleHeadTiltAnimationState': 1}], 'fox': FOX, + # CopperGolemModel: the idle head spin and the four chest interactions (started N ticks ago). + 'copper_golem': [{'idleAnimationState': 4}, {'idleAnimationState': 37}, {'interactionGetItem': 3}, + {'interactionGetItem': 30}, {'interactionGetNoItem': 12}, {'interactionDropItem': 8}, + {'interactionDropItem': 45}, {'interactionDropNoItem': 20}], }