Wolf armor: put it on, repair it, shear it off, and let it take the damage
This commit is contained in:
@@ -544,6 +544,16 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
equipment.insert(slot.into(), crate::save::item_to_nbt(&stack));
|
||||
continue;
|
||||
}
|
||||
// A wolf's armor keeps the durability it lost.
|
||||
if slot == "body"
|
||||
&& m.species() == crate::mobs::Species::Wolf
|
||||
&& let Some(id) = item
|
||||
{
|
||||
let mut stack = crate::items::ItemStack::new(id, 1);
|
||||
stack.damage = m.extra.body_damage.max(0) as u32;
|
||||
equipment.insert(slot.into(), crate::save::item_to_nbt(&stack));
|
||||
continue;
|
||||
}
|
||||
match item {
|
||||
Some(id) => {
|
||||
let keep = matches!(
|
||||
@@ -780,6 +790,11 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
crate::mobs::tame::set_tame(&mut m, tame);
|
||||
m.health = health;
|
||||
m.extra.sitting = flag(tag, "Sitting");
|
||||
m.extra.body_damage = tag
|
||||
.get("equipment")
|
||||
.and_then(|e| e.get("body"))
|
||||
.and_then(crate::save::item_from_nbt)
|
||||
.map_or(0, |s| s.damage as i32);
|
||||
m.extra.color =
|
||||
number(tag.get("CollarColor")).map_or(crate::mobs::tame::RED, |c| (c as u8) & 15);
|
||||
if let Some(Tag::String(v)) = tag.get("variant") {
|
||||
|
||||
@@ -2559,12 +2559,18 @@ impl Game<'_> {
|
||||
.items()
|
||||
.get(&item)
|
||||
.is_some_and(|i| i.max_damage > 0);
|
||||
let me = self.level.player_uuid.or(Some([0, 0, 0, 1]));
|
||||
let sneaking = self.keys.contains(&winit::keyboard::KeyCode::ShiftLeft)
|
||||
|| self.keys.contains(&winit::keyboard::KeyCode::ShiftRight);
|
||||
let held_damage = held.as_ref().map_or(0, |h| h.damage as i32);
|
||||
let m = &mut self.mobs[index];
|
||||
if !m.alive() {
|
||||
return Ok(false);
|
||||
}
|
||||
let species = m.species();
|
||||
let center = m.center();
|
||||
// Wolf armor the owner takes off with shears or leaves a dropped stack of.
|
||||
let mut armor_drop: Option<ItemStack> = None;
|
||||
let mut consume = false;
|
||||
let mut give: Option<&str> = None;
|
||||
let mut sound: Option<&str> = None;
|
||||
@@ -2637,6 +2643,22 @@ impl Game<'_> {
|
||||
handled = false;
|
||||
}
|
||||
}
|
||||
// Entity.interact: shears take a tamed wolf's armor off for its owner.
|
||||
Species::Wolf
|
||||
if item == "minecraft:shears"
|
||||
&& m.extra.tame
|
||||
&& m.extra.owner == me
|
||||
&& m.extra.head.is_some()
|
||||
&& !sneaking =>
|
||||
{
|
||||
let mut stack = ItemStack::new("minecraft:wolf_armor", 1);
|
||||
stack.damage = m.extra.body_damage.max(0) as u32;
|
||||
armor_drop = Some(stack);
|
||||
m.extra.head = None;
|
||||
m.extra.body_damage = 0;
|
||||
eat = Some(("item.armor.unequip_wolf", 1.0, 1.0));
|
||||
self.damage_held_tool();
|
||||
}
|
||||
// Wolf.mobInteract: heal, dye the collar or sit/stand when tame;
|
||||
// a bone tames a wild one a third of the time.
|
||||
Species::Wolf if m.extra.tame && is_food && m.health < m.attrs.max_health => {
|
||||
@@ -2650,6 +2672,35 @@ impl Game<'_> {
|
||||
m.health = (m.health + heal).min(m.attrs.max_health);
|
||||
consume = true;
|
||||
}
|
||||
// Wolf.mobInteract: the owner puts wolf armor on a tamed adult.
|
||||
Species::Wolf
|
||||
if item == "minecraft:wolf_armor"
|
||||
&& m.extra.tame
|
||||
&& m.extra.owner == me
|
||||
&& m.extra.head.is_none()
|
||||
&& !m.is_baby() =>
|
||||
{
|
||||
m.extra.head = Some(item.as_str().into());
|
||||
m.extra.body_damage = held_damage;
|
||||
consume = true;
|
||||
eat = Some(("item.armor.equip_wolf", 1.0, 1.0));
|
||||
}
|
||||
// Wolf.mobInteract: an armadillo scute repairs a sitting wolf's
|
||||
// armor by an eighth of its durability.
|
||||
Species::Wolf
|
||||
if item == "minecraft:armadillo_scute"
|
||||
&& m.extra.tame
|
||||
&& m.extra.owner == me
|
||||
&& m.extra.sitting
|
||||
&& m.extra.head.is_some()
|
||||
&& m.extra.body_damage > 0 =>
|
||||
{
|
||||
m.extra.body_damage = (m.extra.body_damage
|
||||
- (horizon_client::mobs::WOLF_ARMOR_DURABILITY as f32 * 0.125) as i32)
|
||||
.max(0);
|
||||
consume = true;
|
||||
eat = Some(("item.wolf_armor.repair", 1.0, 1.0));
|
||||
}
|
||||
Species::Wolf
|
||||
if m.extra.tame
|
||||
&& item.ends_with("_dye")
|
||||
@@ -2897,6 +2948,9 @@ impl Game<'_> {
|
||||
self.spawn_item(rest, at, [0.0, 0.0, 0.0], 40);
|
||||
}
|
||||
}
|
||||
if let Some(stack) = armor_drop {
|
||||
self.spawn_item(stack, [center[0], center[1] + 0.5, center[2]], [0.0; 3], 10);
|
||||
}
|
||||
for (item, count) in drops {
|
||||
for _ in 0..count {
|
||||
let v = [
|
||||
|
||||
@@ -379,7 +379,12 @@ fn mob_equipment(
|
||||
let stack = ItemStack {
|
||||
item: item.clone(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
// A wolf's armor shows its cracks.
|
||||
damage: if slot == 5 && m.species() == horizon_client::mobs::Species::Wolf {
|
||||
e.body_damage.max(0) as u32
|
||||
} else {
|
||||
0
|
||||
},
|
||||
extra: None,
|
||||
};
|
||||
out.push((slot, hub.stack(&Some(stack))));
|
||||
|
||||
@@ -2011,13 +2011,19 @@ impl Game<'_> {
|
||||
// player holds and wears (EquipmentSlot ordinals).
|
||||
C::SetEquipment(p) => {
|
||||
self.remote_object_equipment(p.id, &p.slots);
|
||||
let items: Vec<(u8, Option<Arc<str>>)> = p
|
||||
let items: Vec<(u8, Option<Arc<str>>, i32)> = p
|
||||
.slots
|
||||
.iter()
|
||||
.map(|(slot, stack)| (*slot, stack.as_ref().map(|s| self.item_name(s.item))))
|
||||
.map(|(slot, stack)| {
|
||||
(
|
||||
*slot,
|
||||
stack.as_ref().map(|s| self.item_name(s.item)),
|
||||
self.to_stack(stack).map_or(0, |s| s.damage as i32),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
|
||||
for (slot, item) in items {
|
||||
for (slot, item, damage) in items {
|
||||
let e = &mut m.extra;
|
||||
match slot {
|
||||
0 => e.main_hand = item,
|
||||
@@ -2025,7 +2031,10 @@ impl Game<'_> {
|
||||
2 => e.feet = item,
|
||||
3 => e.legs = item,
|
||||
4 => e.chest = item,
|
||||
5 => e.head = item,
|
||||
5 => {
|
||||
e.head = item;
|
||||
e.body_damage = damage;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,6 +631,8 @@ pub struct Attrs {
|
||||
pub spawn_reinforcements: f64,
|
||||
pub jump_strength: f64,
|
||||
}
|
||||
/// `minecraft:wolf_armor`'s maximum damage.
|
||||
pub const WOLF_ARMOR_DURABILITY: i32 = 64;
|
||||
/// Species-specific persistent state (variants, colours, taming, ageing...).
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Extra {
|
||||
@@ -659,6 +661,8 @@ pub struct Extra {
|
||||
/// `Mob.canPickUpLoot` (also lets dispensers equip it).
|
||||
pub pick_up_loot: bool,
|
||||
pub saddled: bool,
|
||||
/// The durability a wolf's body armor (`extra.head`) has lost.
|
||||
pub body_damage: i32,
|
||||
/// The saddle's components (name, enchantments...) when it is not a bare
|
||||
/// one; `saddled` stays the gameplay flag.
|
||||
pub saddle_stack: Option<crate::items::ItemStack>,
|
||||
@@ -1752,18 +1756,29 @@ impl Mob {
|
||||
if epf > 0.0 {
|
||||
amount *= 1.0 - epf / 25.0;
|
||||
}
|
||||
// Wolf.actuallyHurt: wolf armor takes the damage instead of the wolf.
|
||||
let absorbed = self.wolf_armor_absorbs(&source);
|
||||
let mut knock = true;
|
||||
if self.invulnerable as f32 > 10.0 {
|
||||
if amount <= self.last_hurt {
|
||||
return false;
|
||||
}
|
||||
self.health -= amount - self.last_hurt;
|
||||
let dealt = amount - self.last_hurt;
|
||||
if absorbed {
|
||||
self.hurt_wolf_armor(dealt);
|
||||
} else {
|
||||
self.health -= dealt;
|
||||
}
|
||||
self.last_hurt = amount;
|
||||
knock = false;
|
||||
} else {
|
||||
self.last_hurt = amount;
|
||||
self.invulnerable = 20;
|
||||
self.health -= amount;
|
||||
if absorbed {
|
||||
self.hurt_wolf_armor(amount);
|
||||
} else {
|
||||
self.health -= amount;
|
||||
}
|
||||
self.hurt_time = 10;
|
||||
}
|
||||
// Animal.actuallyHurt: damage taken ends love mode (`resetLove`).
|
||||
@@ -1794,7 +1809,12 @@ impl Mob {
|
||||
// playHurtSound (Mob: also resets the ambient sound clock) or the
|
||||
// death sound: makeSound draws the voice pitch whenever there is a sound.
|
||||
let dead = !self.alive();
|
||||
let sound = ai::voice_sounds(self)[if dead { 2 } else { 1 }];
|
||||
// Wolf.getHurtSound: the armor's own sound when it takes the hit.
|
||||
let sound = if absorbed {
|
||||
"item.wolf_armor.damage"
|
||||
} else {
|
||||
ai::voice_sounds(self)[if dead { 2 } else { 1 }]
|
||||
};
|
||||
if !dead {
|
||||
self.ambient_timer = -self.kind.ambient_interval;
|
||||
}
|
||||
@@ -1809,6 +1829,45 @@ impl Mob {
|
||||
}
|
||||
true
|
||||
}
|
||||
/// `Wolf.canArmorAbsorb`: it wears wolf armor and the damage type is not
|
||||
/// in `#bypasses_wolf_armor` (drowning, magic, thorns, in a wall, out of
|
||||
/// the world and the untyped kills).
|
||||
fn wolf_armor_absorbs(&self, source: &Damage) -> bool {
|
||||
self.species() == Species::Wolf
|
||||
&& self.extra.head.as_deref() == Some("minecraft:wolf_armor")
|
||||
&& !matches!(
|
||||
source.kind,
|
||||
DamageKind::Drown
|
||||
| DamageKind::Magic
|
||||
| DamageKind::InWall
|
||||
| DamageKind::Thorns
|
||||
| DamageKind::OutOfWorld
|
||||
| DamageKind::Generic
|
||||
)
|
||||
}
|
||||
/// `Wolf.actuallyHurt`: the armor loses `ceil(damage)` durability, cracks
|
||||
/// at `Crackiness.WOLF_ARMOR` steps and breaks at its maximum.
|
||||
fn hurt_wolf_armor(&mut self, damage: f32) {
|
||||
let crack = |lost: i32| {
|
||||
let left = (WOLF_ARMOR_DURABILITY - lost) as f32 / WOLF_ARMOR_DURABILITY as f32;
|
||||
[0.95_f32, 0.69, 0.32].iter().filter(|t| left < **t).count()
|
||||
};
|
||||
let before = self.extra.body_damage;
|
||||
let after = before + damage.ceil() as i32;
|
||||
let at = [self.position.x, self.position.y, self.position.z];
|
||||
if after >= WOLF_ARMOR_DURABILITY {
|
||||
self.extra.head = None;
|
||||
self.extra.body_damage = 0;
|
||||
self.outbox
|
||||
.push(MobEvent::Sound("item.wolf_armor.break", at, 1.0, 1.0));
|
||||
} else {
|
||||
self.extra.body_damage = after;
|
||||
if crack(before) != crack(after) {
|
||||
self.outbox
|
||||
.push(MobEvent::Sound("item.wolf_armor.crack", at, 1.0, 1.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
/// LivingEntity.knockback(power, xd, zd) towards the negative direction.
|
||||
pub fn knockback(&mut self, power: f64, mut xd: f64, mut zd: f64) {
|
||||
let power = power * (1.0 - self.attrs.knockback_resistance);
|
||||
|
||||
@@ -245,6 +245,9 @@ pub fn slot_item(m: &Mob, slot: &str) -> Option<LootStack> {
|
||||
_ => (None, None),
|
||||
};
|
||||
let mut stack = loot_stack(item?, 1);
|
||||
if slot == "body" && m.species() == Species::Wolf {
|
||||
stack.damage = m.extra.body_damage;
|
||||
}
|
||||
if let (Some(index), Some(g)) = (index, gear::gear(m)) {
|
||||
for (e, l) in &g.slots[index] {
|
||||
stack.enchantments.push((e.to_string(), *l as i32));
|
||||
@@ -282,6 +285,7 @@ pub fn clear_slot(m: &mut Mob, slot: &str) {
|
||||
}
|
||||
"body" if body => {
|
||||
m.extra.head = None;
|
||||
m.extra.body_damage = 0;
|
||||
return;
|
||||
}
|
||||
"saddle" => {
|
||||
|
||||
@@ -352,13 +352,37 @@ pub fn layers(m: &Mob) -> Vec<Layer> {
|
||||
})
|
||||
};
|
||||
match m.species() {
|
||||
// WolfCollarLayer.
|
||||
// WolfArmorLayer, then WolfCollarLayer.
|
||||
S::Wolf if m.extra.tame => {
|
||||
let (model, texture) = if m.is_baby() {
|
||||
("wolf_baby#main", "entity/wolf/wolf_collar_baby")
|
||||
} else {
|
||||
("wolf#main", "entity/wolf/wolf_collar")
|
||||
};
|
||||
// The armor, then the cracks of its damage (`Crackiness.WOLF_ARMOR`).
|
||||
if !m.is_baby() && m.extra.head.as_deref() == Some("minecraft:wolf_armor") {
|
||||
let left = (super::WOLF_ARMOR_DURABILITY - m.extra.body_damage) as f32
|
||||
/ super::WOLF_ARMOR_DURABILITY as f32;
|
||||
push(
|
||||
&mut v,
|
||||
"wolf_armor#main",
|
||||
"entity/equipment/wolf_body/armadillo_scute",
|
||||
white,
|
||||
false,
|
||||
);
|
||||
let crack = [(0.32, "high"), (0.69, "medium"), (0.95, "low")]
|
||||
.iter()
|
||||
.find(|(t, _)| left < *t);
|
||||
if let Some((_, level)) = crack {
|
||||
push(
|
||||
&mut v,
|
||||
"wolf_armor#main",
|
||||
&format!("entity/wolf/wolf_armor_crackiness_{level}"),
|
||||
white,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
push(
|
||||
&mut v,
|
||||
model,
|
||||
|
||||
@@ -1690,10 +1690,15 @@ impl Def {
|
||||
}
|
||||
}
|
||||
/// Mobs whose `body` equipment slot Horizon keeps in `Extra::head` (a
|
||||
/// happy ghast's harness, nautilus armour, a sulfur cube's swallowed block).
|
||||
/// happy ghast's harness, nautilus armour, a sulfur cube's swallowed block,
|
||||
/// a wolf's armor).
|
||||
pub fn body_slot(s: Species) -> bool {
|
||||
matches!(
|
||||
s,
|
||||
Species::HappyGhast | Species::Nautilus | Species::ZombieNautilus | Species::SulfurCube
|
||||
Species::HappyGhast
|
||||
| Species::Nautilus
|
||||
| Species::ZombieNautilus
|
||||
| Species::SulfurCube
|
||||
| Species::Wolf
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user