Merge pull request #1408 from ludovic111/fix/contact-damage
🤖 Agent: merged after verify passed; lan_e2e (absorption breath lava contacts shield deathmining worldspawn drops underwater beds minecarts levels) passes in both single-player modes on the top of the chain, plus clippy and the client tests.
This commit is contained in:
@@ -1792,6 +1792,7 @@ impl Game<'_> {
|
||||
}
|
||||
let in_wall = !g.sleeping && self.in_wall(g.position, g.eye_height());
|
||||
let at = g.position;
|
||||
let sneaking = g.sneaking;
|
||||
let sounds = self.as_guest(host, conn, |game| {
|
||||
let (rules, motion) = (game.world.health_rules, game.motion);
|
||||
let health = &motion.health;
|
||||
@@ -1810,6 +1811,26 @@ impl Game<'_> {
|
||||
let _ = w.fluid_base_tick();
|
||||
w.player.ground.on_ground = from_ground;
|
||||
let travelled: Vec<[f64; 3]> = moves.iter().map(|m| m.0).collect();
|
||||
// Entity.move's movementThisTick: each move, from where the
|
||||
// tick's first one started.
|
||||
let end = w.player.position;
|
||||
let start = travelled
|
||||
.iter()
|
||||
.fold(end, |p, d| p.subtract(Vec3::new(d[0], d[1], d[2])));
|
||||
w.player.history.clear();
|
||||
let mut from = start;
|
||||
for d in &travelled {
|
||||
let delta = Vec3::new(d[0], d[1], d[2]);
|
||||
let to = from.add_vector(delta);
|
||||
w.player
|
||||
.history
|
||||
.add(horizon_world::entity_move::MovementRecord {
|
||||
from,
|
||||
to,
|
||||
original: Some(delta),
|
||||
});
|
||||
from = to;
|
||||
}
|
||||
for (moved, on_ground) in moves {
|
||||
let movement = Vec3::new(moved[0], moved[1], moved[2]);
|
||||
if w.player.ground.on_ground && !on_ground && moved[1] > 0.0 {
|
||||
@@ -1835,6 +1856,10 @@ impl Game<'_> {
|
||||
if w.climbable().unwrap_or(false) {
|
||||
w.player.fall_distance = 0.0;
|
||||
}
|
||||
// Entity.applyEffectsFromBlocks along those moves: magma, cactus,
|
||||
// lit campfires and grown sweet berry bushes hurt (#1305).
|
||||
w.player.shift_key_down = sneaking;
|
||||
let _ = w.server_block_damage(start);
|
||||
let _ = w.tick_environment_damage();
|
||||
let _ = w.apply_fire_contact();
|
||||
let _ = w.server_hazards_tick(in_wall);
|
||||
|
||||
@@ -1031,9 +1031,22 @@ impl MotionWorld<'_, '_, '_> {
|
||||
}
|
||||
/// `Entity.applyEffectsFromBlocks` for the blocks Horizon's player reacts
|
||||
/// to inside its movement path: powder snow (`PowderSnowBlock.entityInside`
|
||||
/// and the FREEZE / EXTINGUISH effects), cobwebs and sweet berry bushes. Pressure plates, tripwires and
|
||||
/// rails are the world tick's scan.
|
||||
/// and the FREEZE / EXTINGUISH effects), cobwebs, sweet berry bushes,
|
||||
/// cactus and lit campfires, and the magma block it stands on
|
||||
/// (`stepOn`). Pressure plates, tripwires and rails are the world tick's
|
||||
/// scan.
|
||||
pub fn apply_effects_from_blocks(&mut self) -> Result<()> {
|
||||
self.effects_from_blocks(false)
|
||||
}
|
||||
/// What `applyEffectsFromBlocks` does to a server's player along the
|
||||
/// moves its client sent since `from` (in its history): the damage of
|
||||
/// magma, cactus, lit campfires and grown sweet berry bushes. Its client
|
||||
/// moves it, so the slowing and the rest are the client's.
|
||||
pub fn server_block_damage(&mut self, from: Vec3) -> Result<()> {
|
||||
self.player.old_position = from;
|
||||
self.effects_from_blocks(true)
|
||||
}
|
||||
fn effects_from_blocks(&mut self, damage_only: bool) -> Result<()> {
|
||||
use horizon_world::entity_move::MovementRecord;
|
||||
let mut movements: Vec<MovementRecord> =
|
||||
self.player.history.records().iter().copied().collect();
|
||||
@@ -1058,6 +1071,19 @@ impl MotionWorld<'_, '_, '_> {
|
||||
if self.player.spectator {
|
||||
return Ok(());
|
||||
}
|
||||
// Block.stepOn for the block under an entity on the ground:
|
||||
// MagmaBlock's hot floor hurts unless it steps carefully (sneaks).
|
||||
if self.player.ground.on_ground {
|
||||
let on = self.legacy_on_position()?;
|
||||
let magma = self
|
||||
.assets
|
||||
.registry
|
||||
.state(self.block(on))
|
||||
.is_some_and(|s| s.name == "minecraft:magma_block");
|
||||
if magma && !self.player.shift_key_down {
|
||||
self.environment_hurt("minecraft:hot_floor", 1.0)?;
|
||||
}
|
||||
}
|
||||
let mut visited = std::collections::HashSet::new();
|
||||
let mut entered = Vec::new();
|
||||
for movement in &movements {
|
||||
@@ -1083,6 +1109,7 @@ impl MotionWorld<'_, '_, '_> {
|
||||
&mut visited,
|
||||
&mut entered,
|
||||
budget,
|
||||
damage_only,
|
||||
)?;
|
||||
from = to;
|
||||
}
|
||||
@@ -1095,11 +1122,19 @@ impl MotionWorld<'_, '_, '_> {
|
||||
&mut visited,
|
||||
&mut entered,
|
||||
16,
|
||||
damage_only,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
if budget <= 0 {
|
||||
self.check_inside_blocks(movement.to, movement.to, &mut visited, &mut entered, 1)?;
|
||||
self.check_inside_blocks(
|
||||
movement.to,
|
||||
movement.to,
|
||||
&mut visited,
|
||||
&mut entered,
|
||||
1,
|
||||
damage_only,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
// InsideBlockEffectApplier.StepBasedCollector: the blocks entered
|
||||
@@ -1139,6 +1174,7 @@ impl MotionWorld<'_, '_, '_> {
|
||||
visited: &mut std::collections::HashSet<i64>,
|
||||
entered: &mut Vec<(i32, BlockPos)>,
|
||||
max_iterations: i32,
|
||||
damage_only: bool,
|
||||
) -> Result<i32> {
|
||||
let deflated = self.player.dimensions.bounds(to).deflate(Vec3::new(
|
||||
f64::from(1.0e-5_f32),
|
||||
@@ -1215,6 +1251,33 @@ impl MotionWorld<'_, '_, '_> {
|
||||
}
|
||||
};
|
||||
if inside && visited.insert(p.pack()) {
|
||||
// CactusBlock and CampfireBlock.entityInside (`entity.hurt`).
|
||||
match name {
|
||||
"minecraft:cactus" => self.environment_hurt("minecraft:cactus", 1.0)?,
|
||||
"minecraft:campfire" | "minecraft:soul_campfire" => {
|
||||
let lit = self
|
||||
.assets
|
||||
.registry
|
||||
.state(state)
|
||||
.and_then(|s| s.properties.get("lit"))
|
||||
.is_some_and(|v| v == "true");
|
||||
let damage = if name == "minecraft:campfire" {
|
||||
1.0
|
||||
} else {
|
||||
2.0
|
||||
};
|
||||
if lit {
|
||||
self.environment_hurt("minecraft:campfire", damage)?;
|
||||
}
|
||||
}
|
||||
"minecraft:sweet_berry_bush" if damage_only => {
|
||||
self.sweet_berry_bush_damage(state)?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if damage_only {
|
||||
continue;
|
||||
}
|
||||
match name {
|
||||
"minecraft:powder_snow" => {
|
||||
self.powder_snow_inside(p)?;
|
||||
@@ -1263,6 +1326,10 @@ impl MotionWorld<'_, '_, '_> {
|
||||
/// is at least 0.003 on X or Z.
|
||||
fn sweet_berry_bush_inside(&mut self, state: BlockStateId) -> Result<()> {
|
||||
self.make_stuck_in_block(Vec3::new(f64::from(0.8_f32), 0.75, f64::from(0.8_f32)));
|
||||
self.sweet_berry_bush_damage(state)
|
||||
}
|
||||
/// The server's half of `SweetBerryBushBlock.entityInside`: the prick.
|
||||
fn sweet_berry_bush_damage(&mut self, state: BlockStateId) -> Result<()> {
|
||||
let age = self
|
||||
.assets
|
||||
.registry
|
||||
|
||||
@@ -6,7 +6,7 @@ use horizon_world::{
|
||||
living_fluid::{LivingFluidWorld, TravelFluidTag},
|
||||
};
|
||||
impl MotionWorld<'_, '_, '_> {
|
||||
fn environment_hurt(&mut self, source: &str, damage: f32) -> Result<()> {
|
||||
pub(super) fn environment_hurt(&mut self, source: &str, damage: f32) -> Result<()> {
|
||||
if self.player.invulnerable || self.player.spectator {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
+64
-3
@@ -138,6 +138,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
get off by sneaking; the other side sees the animal move.
|
||||
- lightning: a bolt summoned beside the host, then the guest: both sides get the bolt and flash the
|
||||
sky (on its server thread the host's window is a client of it too).
|
||||
- contacts: the host and the guest each stand on magma (and sneak on it), stand on a lit campfire,
|
||||
walk against a cactus and through grown sweet berry bushes: the server hurts them, but
|
||||
not the sneaking player or young bushes (#1305, #1311, #1312, #1313).
|
||||
- absorption: the host and the guest each take Absorption II and a hit of 3: their own HUD has the
|
||||
server's golden hearts, 8 then 5 (#1306).
|
||||
- breath: the host and the guest each stay underwater for 15 s in a Respiration III helmet: their
|
||||
@@ -185,7 +188,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', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'absorption', 'breath', 'lava', 'levels']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'contacts', 'absorption', 'breath', 'lava', 'levels']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -2602,6 +2605,64 @@ def own(game):
|
||||
return game('state')['player']
|
||||
|
||||
|
||||
def check_contacts(host, guest, out):
|
||||
"""Blocks that hurt what touches them, on the server: standing on magma (but not sneaking on it)
|
||||
and on a lit campfire, walking against a cactus and through grown sweet berry bushes, for the
|
||||
host and the guest (#1305, #1311, #1312, #1313); a young bush pricks no one."""
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
host('command', command='gamerule natural_health_regeneration false')
|
||||
seen = {}
|
||||
try:
|
||||
for game, dz in ((host, -4), (guest, 4)):
|
||||
x, y, z = hx + 2, hy, hz + dz
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='effect clear @s')
|
||||
for case, blocks, walk in (
|
||||
('magma', [(0, -1, 'minecraft:magma_block')], False),
|
||||
('sneaking', [(0, -1, 'minecraft:magma_block')], False),
|
||||
('campfire', [(0, 0, 'minecraft:campfire[lit=true]')], False),
|
||||
('cactus', [(2, -1, 'minecraft:sand'), (2, 0, 'minecraft:cactus')], True),
|
||||
('berries', [(k, -1, 'minecraft:grass_block') for k in range(1, 4)]
|
||||
+ [(k, 0, 'minecraft:sweet_berry_bush[age=3]') for k in range(1, 4)], True),
|
||||
('young', [(k, -1, 'minecraft:grass_block') for k in range(1, 4)]
|
||||
+ [(k, 0, 'minecraft:sweet_berry_bush[age=0]') for k in range(1, 4)], True)):
|
||||
game('command', command='effect give @s minecraft:instant_health 1 5 true')
|
||||
game('command', command=f'fill {x - 1} {y - 2} {z - 1} {x + 4} {y - 1} {z + 1} minecraft:stone')
|
||||
game('command', command=f'fill {x - 1} {y} {z - 1} {x + 4} {y + 2} {z + 1} minecraft:air')
|
||||
# A wall ends the walk before the player leaves the floor.
|
||||
game('command', command=f'fill {x + 5} {y - 1} {z - 1} {x + 5} {y + 2} {z + 1} minecraft:stone')
|
||||
for dx, dy, block in blocks:
|
||||
game('command', command=f'setblock {x + dx} {y + dy} {z} {block}')
|
||||
stand = 0.5 if case == 'campfire' else 0.0
|
||||
# Sneaking from before the player lands on the magma.
|
||||
held = ['shift'] if case == 'sneaking' else []
|
||||
for k in held:
|
||||
game.raw('key', k, 'down')
|
||||
game.wait(5)
|
||||
game('command', command=f'tp @s {x + 0.5} {y + stand} {z + 0.5}')
|
||||
game.raw('look-at', f'{x + 10:.2f}', f'{y + 1.6:.2f}', f'{z + 0.5:.2f}')
|
||||
game.wait(30)
|
||||
before = own(game)['health']
|
||||
keys = ['w'] if walk else []
|
||||
for k in keys:
|
||||
game.raw('key', k, 'down')
|
||||
game.wait(60)
|
||||
# Read before letting go: standing up on the magma would hurt.
|
||||
after = own(game)['health']
|
||||
for k in keys + held:
|
||||
game.raw('key', k, 'up')
|
||||
game.wait(10)
|
||||
seen[f'{game.name}-{case}'] = (before, after)
|
||||
game.shot(out, f'contacts-{case}')
|
||||
host('command', command=f'fill {x - 1} {y} {z - 1} {x + 5} {y + 2} {z + 1} minecraft:air')
|
||||
finally:
|
||||
host('command', command='gamerule natural_health_regeneration true')
|
||||
for case, (before, after) in seen.items():
|
||||
safe = case.endswith(('sneaking', 'young'))
|
||||
assert (after == before) if safe else (after < before), f'{case}: {before} -> {after} (all: {seen})'
|
||||
return seen
|
||||
|
||||
|
||||
def server_player(host, game):
|
||||
"""The player's entry on the server: the guest's in the host's `lan status`, on the server
|
||||
thread the host's too; the host's own world otherwise."""
|
||||
@@ -3487,8 +3548,8 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'light': check_light, 'plates': check_plates,
|
||||
'swings': check_swings, 'cracks': check_cracks,
|
||||
'time': check_time, 'growth': check_growth, 'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict, 'ladder': check_ladder, 'boats': check_boats, 'minecarts': check_minecarts, 'frames': check_frames, 'lightning': check_lightning, 'riding': check_riding, 'mounts': check_mounts,
|
||||
'absorption': check_absorption, 'breath': check_breath, 'lava': check_lava,
|
||||
'levels': check_levels}
|
||||
'contacts': check_contacts, 'absorption': check_absorption, 'breath': check_breath,
|
||||
'lava': check_lava, 'levels': check_levels}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
Reference in New Issue
Block a user