Wolf armor: check the acting player's UUID and keep the armor's components
This commit is contained in:
@@ -551,6 +551,7 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
{
|
||||
let mut stack = crate::items::ItemStack::new(id, 1);
|
||||
stack.damage = m.extra.body_damage.max(0) as u32;
|
||||
stack.extra = m.extra.body_extra.clone();
|
||||
equipment.insert(slot.into(), crate::save::item_to_nbt(&stack));
|
||||
continue;
|
||||
}
|
||||
@@ -790,11 +791,12 @@ 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
|
||||
let armor = tag
|
||||
.get("equipment")
|
||||
.and_then(|e| e.get("body"))
|
||||
.and_then(crate::save::item_from_nbt)
|
||||
.map_or(0, |s| s.damage as i32);
|
||||
.and_then(crate::save::item_from_nbt);
|
||||
m.extra.body_damage = armor.as_ref().map_or(0, |s| s.damage as i32);
|
||||
m.extra.body_extra = armor.and_then(|s| s.extra);
|
||||
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,10 +2559,11 @@ 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 me = self.acting_owner();
|
||||
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 held_extra = held.as_ref().and_then(|h| h.extra.clone());
|
||||
let m = &mut self.mobs[index];
|
||||
if !m.alive() {
|
||||
return Ok(false);
|
||||
@@ -2653,6 +2654,7 @@ impl Game<'_> {
|
||||
{
|
||||
let mut stack = ItemStack::new("minecraft:wolf_armor", 1);
|
||||
stack.damage = m.extra.body_damage.max(0) as u32;
|
||||
stack.extra = m.extra.body_extra.take();
|
||||
armor_drop = Some(stack);
|
||||
m.extra.head = None;
|
||||
m.extra.body_damage = 0;
|
||||
@@ -2682,6 +2684,7 @@ impl Game<'_> {
|
||||
{
|
||||
m.extra.head = Some(item.as_str().into());
|
||||
m.extra.body_damage = held_damage;
|
||||
m.extra.body_extra = held_extra;
|
||||
consume = true;
|
||||
eat = Some(("item.armor.equip_wolf", 1.0, 1.0));
|
||||
}
|
||||
@@ -2745,7 +2748,7 @@ impl Game<'_> {
|
||||
let tamed = m.random.next_int_bound(3).unwrap_or(1) == 0;
|
||||
if tamed {
|
||||
horizon_client::mobs::tame::set_tame(m, true);
|
||||
m.extra.owner = self.level.player_uuid.or(Some([0, 0, 0, 1]));
|
||||
m.extra.owner = me;
|
||||
m.persistent = true;
|
||||
m.nav_stop();
|
||||
m.ai.target = None;
|
||||
@@ -2821,7 +2824,7 @@ impl Game<'_> {
|
||||
let tamed = m.random.next_int_bound(3).unwrap_or(1) == 0;
|
||||
if tamed {
|
||||
m.extra.tame = true;
|
||||
m.extra.owner = self.level.player_uuid.or(Some([0, 0, 0, 1]));
|
||||
m.extra.owner = me;
|
||||
m.extra.sitting = true;
|
||||
}
|
||||
eat = eating_sound(m, &mut self.world.random);
|
||||
@@ -2877,7 +2880,7 @@ impl Game<'_> {
|
||||
let tamed = m.random.next_int_bound(10).unwrap_or(1) == 0;
|
||||
if tamed {
|
||||
m.extra.tame = true;
|
||||
m.extra.owner = self.level.player_uuid.or(Some([0, 0, 0, 1]));
|
||||
m.extra.owner = me;
|
||||
}
|
||||
let kind = if tamed { "heart" } else { "smoke" };
|
||||
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
|
||||
|
||||
@@ -385,7 +385,11 @@ fn mob_equipment(
|
||||
} else {
|
||||
0
|
||||
},
|
||||
extra: None,
|
||||
extra: if slot == 5 && m.species() == horizon_client::mobs::Species::Wolf {
|
||||
e.body_extra.clone()
|
||||
} else {
|
||||
None
|
||||
},
|
||||
};
|
||||
out.push((slot, hub.stack(&Some(stack))));
|
||||
}
|
||||
|
||||
@@ -328,6 +328,14 @@ impl Game<'_> {
|
||||
.collect()
|
||||
}
|
||||
/// The UUID of the player acting: the guest `as_guest` runs, else the host.
|
||||
/// The owner a wolf, cat or parrot gets when the acting player tames it
|
||||
/// (a host with no UUID yet owns under `[0, 0, 0, 1]`).
|
||||
pub(super) fn acting_owner(&self) -> Option<[i32; 4]> {
|
||||
self.lan_acting_uuid
|
||||
.map(horizon_client::lan::playerdata::uuid_ints)
|
||||
.or(self.level.player_uuid)
|
||||
.or(Some([0, 0, 0, 1]))
|
||||
}
|
||||
pub(super) fn acting_uuid(&self) -> [i32; 4] {
|
||||
self.lan_acting_uuid
|
||||
.map(horizon_client::lan::playerdata::uuid_ints)
|
||||
|
||||
@@ -663,6 +663,8 @@ pub struct Extra {
|
||||
pub saddled: bool,
|
||||
/// The durability a wolf's body armor (`extra.head`) has lost.
|
||||
pub body_damage: i32,
|
||||
/// The components (dye, name...) of that armor stack.
|
||||
pub body_extra: Option<Box<crate::item_data::StackData>>,
|
||||
/// 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>,
|
||||
@@ -1858,6 +1860,7 @@ impl Mob {
|
||||
if after >= WOLF_ARMOR_DURABILITY {
|
||||
self.extra.head = None;
|
||||
self.extra.body_damage = 0;
|
||||
self.extra.body_extra = None;
|
||||
self.outbox
|
||||
.push(MobEvent::Sound("item.wolf_armor.break", at, 1.0, 1.0));
|
||||
} else {
|
||||
|
||||
@@ -286,6 +286,7 @@ pub fn clear_slot(m: &mut Mob, slot: &str) {
|
||||
"body" if body => {
|
||||
m.extra.head = None;
|
||||
m.extra.body_damage = 0;
|
||||
m.extra.body_extra = None;
|
||||
return;
|
||||
}
|
||||
"saddle" => {
|
||||
|
||||
Reference in New Issue
Block a user