A LAN guest's worn armour protects it
The hub's players are server players too, and in vanilla the armour they wear counts against every hit (LivingEntity.collectEquipmentChanges puts each piece's attribute modifiers on the player, getDamageAfterArmorAbsorb reads them). Horizon only put them on the host: a guest who put armour on in its inventory menu (the hub moves it), joined wearing it, respawned with it kept or came through a portal (a new body each time) was hurt as if it wore nothing. Iron armour, 15 points, should take a 10-damage blow down to 6; a guest took the full 10. Each guest now keeps its own list of applied equipment modifiers, swapped in with the rest of its state for its turn, and its armour and main hand are put on its attributes whenever they differ from what they were put on for (a new body starts with none). lan_e2e `worn`: the guest shift-clicks iron armour on in its inventory and takes 10 mob-attack damage: 6 with it, 10 without (failed before: 10 and 10). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit e0549f88cebfe20625f66dd04348252cef6cea6c)
This commit is contained in:
@@ -64,6 +64,12 @@ pub(super) struct GuestPlay {
|
||||
xp_delay: u32,
|
||||
/// What last killed the guest outright (`/kill`): the death message's key.
|
||||
death_cause: Option<String>,
|
||||
/// The equipment modifiers on the guest's attributes (`apply_equipment`)
|
||||
/// and the armour and main hand they were put on for: the hub's player
|
||||
/// is a `ServerPlayer` too, whose worn armour counts
|
||||
/// (`LivingEntity.collectEquipmentChanges`).
|
||||
modifiers: Vec<(String, String)>,
|
||||
equipped: Option<Vec<Option<ItemStack>>>,
|
||||
}
|
||||
|
||||
/// A guest's command waiting for the hub (`LanHost::commands`).
|
||||
@@ -130,6 +136,8 @@ pub(super) struct GuestSwap {
|
||||
swings: u32,
|
||||
/// How many projectiles there were: those added since are the guest's.
|
||||
projectiles: usize,
|
||||
/// The host's equipment modifiers.
|
||||
modifiers: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
impl GuestPlay {
|
||||
@@ -193,7 +201,8 @@ impl Game<'_> {
|
||||
return None;
|
||||
}
|
||||
let i = host.hub.guests.iter().position(|g| g.conn == conn)?;
|
||||
if host.hub.guests[i].motion.is_none() {
|
||||
let fresh = host.hub.guests[i].motion.is_none();
|
||||
if fresh {
|
||||
let p = Vec3::new(
|
||||
host.hub.guests[i].position[0],
|
||||
host.hub.guests[i].position[1],
|
||||
@@ -207,6 +216,10 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
let mut play = host.play.remove(&conn).unwrap_or_default();
|
||||
if fresh {
|
||||
// A new body (joined, respawned, changed level): nothing on it yet.
|
||||
play.equipped = None;
|
||||
}
|
||||
let g = &mut host.hub.guests[i];
|
||||
// The guest's body.
|
||||
let Some(mut motion) = g.motion.take() else {
|
||||
@@ -310,6 +323,17 @@ impl Game<'_> {
|
||||
let packets = std::mem::take(&mut self.guest_packets);
|
||||
let swings = self.swings_started;
|
||||
let projectiles = self.creatures.projectiles.len();
|
||||
let modifiers = std::mem::replace(
|
||||
&mut self.applied_modifiers,
|
||||
std::mem::take(&mut play.modifiers),
|
||||
);
|
||||
// Its worn armour on its attributes, when it changed.
|
||||
let mut equipped: Vec<Option<ItemStack>> = self.armor.to_vec();
|
||||
equipped.push(self.inventory.get(self.selected).cloned().flatten());
|
||||
if play.equipped.as_ref() != Some(&equipped) {
|
||||
self.apply_equipment();
|
||||
play.equipped = Some(equipped);
|
||||
}
|
||||
Some(GuestSwap {
|
||||
conn,
|
||||
i,
|
||||
@@ -355,6 +379,7 @@ impl Game<'_> {
|
||||
packets,
|
||||
swings,
|
||||
projectiles,
|
||||
modifiers,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -406,7 +431,9 @@ impl Game<'_> {
|
||||
packets,
|
||||
swings,
|
||||
projectiles,
|
||||
modifiers,
|
||||
} = swap;
|
||||
play.modifiers = std::mem::replace(&mut self.applied_modifiers, modifiers);
|
||||
// What the guest shot is theirs (Projectile.setOwner).
|
||||
for p in self.creatures.projectiles.iter_mut().skip(projectiles) {
|
||||
if p.owner == Some(horizon_client::mobs::Who::Player) && p.guest.is_none() {
|
||||
|
||||
+61
-2
@@ -64,6 +64,8 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
guest as the host has them (kind, place, rotation, what they hold or wear, the variant).
|
||||
- projectiles: primed TNT (one falling), an end crystal and an arrow that lands reach the guest where
|
||||
the host has them; a falling block lands on both sides.
|
||||
- worn: iron armour the guest puts on in its inventory protects it: a 10-damage blow takes 6
|
||||
(armour 15, LivingEntity.getDamageAfterArmorAbsorb), and the full 10 without it.
|
||||
- plates: a stone pressure plate the guest steps on is pressed on both sides, and comes up once
|
||||
the guest steps off (#848).
|
||||
- swings: each side sees the other's arm swing while it mines a block, and the guest sees its own
|
||||
@@ -111,7 +113,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
GUEST_NAME = 'Guest'
|
||||
# The host plays single player on its server thread (--server-thread).
|
||||
SERVER_THREAD = False
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'trials', 'clicks', 'sleep', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'trials', 'clicks', 'sleep', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -1697,6 +1699,63 @@ def check_light(host, guest, out):
|
||||
return results
|
||||
|
||||
|
||||
def check_worn(host, guest, out):
|
||||
pieces = ['iron_helmet', 'iron_chestplate', 'iron_leggings', 'iron_boots']
|
||||
guest('command', command='gamemode survival')
|
||||
taken = {}
|
||||
try:
|
||||
for worn in (False, True):
|
||||
guest('command', command='clear @s')
|
||||
if remote(guest)['health'] <= 0:
|
||||
guest.raw('respawn')
|
||||
guest.wait(40)
|
||||
if worn:
|
||||
for piece in pieces:
|
||||
guest('command', command=f'give @s minecraft:{piece}')
|
||||
guest.wait(10)
|
||||
# Shift-clicked from the hotbar onto the body in the inventory menu (the hub moves them).
|
||||
guest.raw('key', 'e', 'tap')
|
||||
guest.raw('wait-for', 'screen', 'inventory')
|
||||
for piece in pieces:
|
||||
guest.raw('click-slot', hotbar_slot(guest, f'minecraft:{piece}'), 'shift')
|
||||
guest.wait(2)
|
||||
guest.raw('key', 'esc', 'tap')
|
||||
guest.wait(5)
|
||||
guest('command', command='effect give @s minecraft:instant_health 1 5')
|
||||
guest.wait(30)
|
||||
before = remote(guest)['health']
|
||||
if not SERVER_THREAD:
|
||||
host.raw('hurtlog')
|
||||
# A mob's blow (no attacker: no difficulty scaling); armour counts against it.
|
||||
guest('command', command='damage @s 10 minecraft:mob_attack')
|
||||
if SERVER_THREAD:
|
||||
# The server's hurt log isn't on a control socket here: the health the guest is
|
||||
# sent, read as soon as it drops (natural regeneration heals it again after).
|
||||
health = before
|
||||
for _ in range(40):
|
||||
guest.wait(1)
|
||||
health = remote(guest)['health']
|
||||
if health < before:
|
||||
break
|
||||
taken['worn' if worn else 'bare'] = [round(before - health, 2)]
|
||||
continue
|
||||
guest.wait(10)
|
||||
log = [h for p in host.raw('hurtlog')['players'] if p['name'] == GUEST_NAME for h in p['hurts']]
|
||||
taken['worn' if worn else 'bare'] = [(h['amount'], h['armor'], round(h['taken'], 2)) for h in log]
|
||||
finally:
|
||||
guest('command', command='clear @s')
|
||||
guest('command', command='effect give @s minecraft:instant_health 1 5')
|
||||
if SERVER_THREAD:
|
||||
# Natural regeneration may heal up to a point before the health arrives.
|
||||
assert len(taken['bare']) == 1 and 9.0 <= taken['bare'][0] <= 10.0, f'10 damage on no armour: {taken}'
|
||||
assert len(taken['worn']) == 1 and 5.0 <= taken['worn'][0] <= 6.0, \
|
||||
f'10 damage through iron armour (15) should take 6: {taken}'
|
||||
return taken
|
||||
assert taken['bare'] == [(10.0, 0.0, 10.0)], f'10 damage on no armour: {taken}'
|
||||
assert taken['worn'] == [(10.0, 15.0, 6.0)], f'10 damage through iron armour (15) should take 6: {taken}'
|
||||
return taken
|
||||
|
||||
|
||||
CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'nametags': check_nametags,
|
||||
'chest': check_chest, 'crafting': check_crafting, 'sign': check_sign, 'damage': check_damage,
|
||||
'mobs': check_mobs, 'hazards': check_hazards, 'pvp': check_pvp,
|
||||
@@ -1712,7 +1771,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'xp': check_xp, 'objects': check_objects, 'projectiles': check_projectiles,
|
||||
'light': check_light, 'plates': check_plates,
|
||||
'swings': check_swings, 'cracks': check_cracks,
|
||||
'time': check_time, 'growth': check_growth}
|
||||
'time': check_time, 'growth': check_growth, 'worn': check_worn}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
Reference in New Issue
Block a user