Render, save and gift copper golems as vanilla does

The copper golem takes its weathering's texture and glowing eyes, saves
and loads next_weather_age and weather_state, starts with its weathering
unset instead of weathering on its first tick, and throws what it carries
to the player as BehaviorUtils.throwItem does. Iron golems offer their
poppy to copper golems too (#candidate_for_iron_golem_gift) and put it on
an empty antenna when the offer runs out beside one.

The entity model harness now poses the copper golem with its idle and
chest interaction animations (44 cases), and the entity death loot harness
includes it (1,595 cases over 88 types); both match vanilla.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-12 17:31:52 +02:00
parent e664d2f7c4
commit 13102892c4
10 changed files with 111 additions and 14 deletions
@@ -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,
+26
View File
@@ -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<String, Arc<MobType>>, 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.
@@ -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;
@@ -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));
+6
View File
@@ -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
@@ -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));
+25 -2
View File
@@ -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) {
+7
View File
@@ -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<Layer> {
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(),
+3 -3
View File
@@ -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',
+5 -1
View File
@@ -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}],
}