Contact damage: magma, cactus, lit campfires and sweet berry bushes hurt in both modes
Entity.applyEffectsFromBlocks: MagmaBlock.stepOn burns a player standing on it who is not sneaking (hot_floor, 1), CactusBlock and CampfireBlock.entityInside hurt what touches them (cactus 1, campfire 1, soul campfire 2, lit only). A server's players (LAN guests, and the host on the server thread) now get these and the grown sweet berry bush prick along the moves their client sent that tick: the server rebuilds the tick's movement history and runs the damage half of the block effects. lan_e2e `contacts`: magma, sneaking on magma, a lit campfire, a cactus, grown and young berry bushes, for the host and the guest. Fixes #1305, #1311, #1312, #1313. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1765,6 +1765,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;
|
||||
@@ -1783,6 +1784,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 {
|
||||
@@ -1808,6 +1829,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);
|
||||
|
||||
@@ -1029,9 +1029,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();
|
||||
@@ -1056,6 +1069,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 {
|
||||
@@ -1081,6 +1107,7 @@ impl MotionWorld<'_, '_, '_> {
|
||||
&mut visited,
|
||||
&mut entered,
|
||||
budget,
|
||||
damage_only,
|
||||
)?;
|
||||
from = to;
|
||||
}
|
||||
@@ -1093,11 +1120,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
|
||||
@@ -1137,6 +1172,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),
|
||||
@@ -1213,6 +1249,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)?;
|
||||
@@ -1261,6 +1324,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(());
|
||||
}
|
||||
|
||||
+62
-2
@@ -131,6 +131,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).
|
||||
- flight: a player in creative double-taps jump and flies, stays up, and stops flying in survival:
|
||||
the guest, and on the server thread the host's window too, take what may fly from the
|
||||
server's abilities (ClientPacketListener.handlePlayerAbilities).
|
||||
@@ -172,7 +175,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']
|
||||
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']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -2297,6 +2300,62 @@ def check_flight(host, guest, out):
|
||||
|
||||
|
||||
|
||||
def own(game):
|
||||
"""The player's own state, as its client has it."""
|
||||
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
|
||||
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 = (['shift'] if case == 'sneaking' else []) + (['w'] if walk else [])
|
||||
for k in keys:
|
||||
game.raw('key', k, 'down')
|
||||
game.wait(60)
|
||||
for k in keys:
|
||||
game.raw('key', k, 'up')
|
||||
game.wait(10)
|
||||
seen[f'{game.name}-{case}'] = (before, own(game)['health'])
|
||||
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 check_ladder(host, guest, out):
|
||||
"""#1255: climbing down a ladder doesn't hurt where the guest lands."""
|
||||
x, y, z = (int(v // 1) for v in pos_of(guest))
|
||||
@@ -3075,7 +3134,8 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'xp': check_xp, 'objects': check_objects, 'projectiles': check_projectiles, 'blast': check_blast,
|
||||
'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}
|
||||
'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,
|
||||
'contacts': check_contacts}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
Reference in New Issue
Block a user