Level events on a server's clients: spawner bursts, bone meal sparks, waxing

A client of a server (single player on its server thread, a LAN guest, a
dedicated server's player) played only three of the level events the server
sent (a block broken, the dragon egg's and a consumable's teleport): a
spawner's burst, waxing and scraping copper, a composter filling and the rest
showed nothing. Every one now goes through the handler the in-frame game uses
(LevelEventHandler).

Bone meal's level event (1505) played its sound but never its growth
particles, in either mode: it now spawns them as BoneMealItem.
addGrowthParticles does (spread over a grass block's, nylium's, netherrack's
or moss's neighbourhood and water, inside a growing block, below rooted dirt
and mangrove leaves). The server also sends it to the player who used the
bone meal, as vanilla's levelEvent names no player.

Waxing copper with honeycomb and an axe or hoe's transforms (wax off, scrape,
strip, till) make their particles and sound on the clicker's own client, as
vanilla's client runs Item.useOn; the server sends them to the others only.
The transform's preview is shared with the in-frame use.

`horizon-ctl status` counts the particles made by type. lan_e2e's new
`sparks` check: the host and the guest each use bone meal on wheat, wax
copper and take the wax off, and a spawner spawns a zombie; both sides make
the particles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-23 08:08:42 +02:00
parent c5fe5d4bcf
commit 13772b4e5b
7 changed files with 245 additions and 68 deletions
+55 -37
View File
@@ -2573,6 +2573,17 @@ impl Game<'_> {
LevelEvent::LevelEvent { id: 2004, pos, .. } => {
self.spawner_burst([pos.x, pos.y, pos.z])
}
// LevelEventHandler 1505: the growth particles, then the sound.
LevelEvent::LevelEvent {
id: 1505,
pos,
data,
} => {
self.growth_particles(pos, data);
let at = [pos.x, pos.y, pos.z].map(|v| f64::from(v) + 0.5);
self.audio
.play("minecraft:item.bone_meal.use", Some(at), 1.0, 1.0);
}
LevelEvent::LevelEvent {
id: 2015,
pos,
@@ -2616,7 +2627,6 @@ impl Game<'_> {
1030 => Some(("minecraft:block.anvil.use", 1.0)),
1029 => Some(("minecraft:block.anvil.destroy", 1.0)),
1031 => Some(("minecraft:block.anvil.land", 0.3)),
1505 => Some(("minecraft:item.bone_meal.use", 1.0)),
1042 => Some(("minecraft:block.grindstone.use", 1.0)),
1044 => Some(("minecraft:block.smithing_table.use", 1.0)),
// LevelEvent.SOUND_PAGE_TURN (a lectern's page).
@@ -8090,13 +8100,15 @@ impl Game<'_> {
}
Ok(true)
}
/// `BlockTransformer.transformBlock` for a held axe, hoe or shovel.
fn use_block_transformer(
&mut self,
/// What `BlockTransformer.transformBlock` would do with a held axe, hoe
/// or shovel on the block at `pos`, without doing it: the new state, its
/// sound, loot table, the durability it costs and its particle.
pub(super) fn block_transform(
&self,
stack: &ItemStack,
pos: [i32; 3],
face: [i32; 3],
) -> Result<bool> {
) -> Option<(BlockStateId, String, Option<String>, u32, String)> {
use horizon_client::block_transform::Around;
struct Column<'w> {
world: &'w World,
@@ -8116,14 +8128,11 @@ impl Game<'_> {
})
}
}
let Some(id) = self
let id = self
.res
.items()
.get(&stack.item)
.and_then(|i| i.block_transformer.clone())
else {
return Ok(false);
};
.and_then(|i| i.block_transformer.clone())?;
// playerHasBlockingItemUseIntent: a shield in the off hand is raised
// instead, unless sneaking.
let shield = self
@@ -8132,7 +8141,7 @@ impl Game<'_> {
.and_then(|s| self.res.items().get(&s.item))
.is_some_and(|i| i.blocks_attacks.is_some());
if shield && !self.keys.contains(&KeyCode::ShiftLeft) {
return Ok(false);
return None;
}
let face_name = match face {
[0, -1, 0] => "down",
@@ -8143,38 +8152,47 @@ impl Game<'_> {
_ => "east",
};
let registry = self.pack.assets.registry;
let (state, sound, loot, damage, particle) = {
let around = Column {
world: &self.world,
registry,
pos,
};
let Some((_, t, state)) =
self.res
.transformers()
.apply(self.res.items(), registry, &id, face_name, &around)
else {
return Ok(false);
};
(
state,
t.sound.clone(),
t.loot.clone(),
t.damage,
t.particle.clone(),
)
let around = Column {
world: &self.world,
registry,
pos,
};
let Ok(new) = registry.resolve(&state) else {
return Ok(false);
};
self.level_set(pos, new)?;
// BlockTransformer.TransformParticle.send.
match particle.as_str() {
let (_, t, state) =
self.res
.transformers()
.apply(self.res.items(), registry, &id, face_name, &around)?;
let new = registry.resolve(&state).ok()?;
Some((
new,
t.sound.clone(),
t.loot.clone(),
t.damage,
t.particle.clone(),
))
}
/// `BlockTransformer.TransformParticle.send`: its level event.
pub(super) fn transform_particle(&mut self, particle: &str, pos: [i32; 3]) {
match particle {
"scrape" => self.level_event_at(3005, pos, 0),
"wax_on" => self.level_event_at(3003, pos, 0),
"wax_off" => self.level_event_at(3004, pos, 0),
_ => {}
}
}
/// `BlockTransformer.transformBlock` for a held axe, hoe or shovel.
fn use_block_transformer(
&mut self,
stack: &ItemStack,
pos: [i32; 3],
face: [i32; 3],
) -> Result<bool> {
let Some((new, sound, loot, damage, particle)) = self.block_transform(stack, pos, face)
else {
return Ok(false);
};
self.level_set(pos, new)?;
// BlockTransformer.TransformParticle.send.
self.transform_particle(&particle, pos);
if loot.as_deref() == Some("minecraft:till/rooted_dirt") {
self.pop_resource(
[pos[0] + face[0], pos[1] + face[1], pos[2] + face[2]],
@@ -971,6 +971,8 @@ impl Game<'_> {
"flashes": self.lightning_seen[1], "flash": self.flash});
// Primed TNT, falling blocks, projectiles, tridents and end crystals.
status["projectiles"] = json!(self.projectiles_status());
// The particles made so far, by type.
status["particles"] = json!(self.particles.made());
status
}
}
+8 -2
View File
@@ -1087,8 +1087,14 @@ impl Game<'_> {
}
for e in events {
if let horizon_world::level::LevelEvent::LevelEvent { id, pos, data } = e {
// The acting guest does not predict the egg's teleport particles.
let except = if *id == 2015 { None } else { self.lan_acting };
// The acting guest does not predict the egg's teleport
// particles, nor bone meal's growth (BoneMealItem.useOn's
// levelEvent names no player).
let except = if matches!(*id, 2015 | 1505) {
None
} else {
self.lan_acting
};
self.lan_events
.push((*id, [pos.x, pos.y, pos.z], *data, except));
}
@@ -1,10 +1,10 @@
//! Level events whose client handler (`LevelEventHandler`) spawns particles
//! on a block: dragon egg teleportation (2015), a consumable's teleport
//! (2017), electric sparks (3002), waxing (3003), wax off (3004) and
//! scraping (3005).
//! on a block: bone meal's growth (1505), dragon egg teleportation (2015), a
//! consumable's teleport (2017), electric sparks (3002), waxing (3003), wax
//! off (3004) and scraping (3005).
use super::Game;
use horizon_client::particles::{self, ParticleOptions, ParticleType};
use horizon_core::position::BlockPos;
use horizon_core::{position::BlockPos, random::RandomSource};
use horizon_world::level::LevelEvent;
impl Game<'_> {
@@ -42,6 +42,65 @@ impl Game<'_> {
self.particles.add(&options, p, v);
}
}
/// `BoneMealItem.addGrowthParticles` (event 1505, `count` the data):
/// happy villager sparks over a spreading block's neighbourhood (grass,
/// nylium, netherrack, moss) or water, or inside a growing block.
pub(super) fn growth_particles(&mut self, pos: BlockPos, count: i32) {
let p = [pos.x, pos.y, pos.z];
let state = self.world.block(p[0], p[1], p[2]);
let facts = self.res.facts();
// ParticleUtils.spawnParticles(level, pos, count, xzSpread, ySpread,
// allowFloatingParticles, particle).
let (at, count, xz, height, floating) = match self.res.behaviours().bone_meal_spreads(state)
{
Some(spreads) => {
// BonemealableBlock.getParticlePos: below for rooted dirt
// (its hanging roots) and mangrove leaves (their propagule).
let at = match &*facts.get(state).name {
"minecraft:rooted_dirt" | "minecraft:mangrove_leaves" => [p[0], p[1] - 1, p[2]],
_ => p,
};
if spreads {
(at, count * 3, 3.0, 1.0, false)
} else {
// ParticleUtils.spawnParticleInBlock: up to the
// block's shape (a full block when air).
let inside = self.world.block(at[0], at[1], at[2]);
let height = if facts.is_air(inside) {
1.0
} else {
facts
.get(inside)
.outline
.iter()
.map(|b| b[4])
.fold(0.0, f64::max)
};
(at, count, 0.5, height, true)
}
}
None if &*facts.get(state).name == "minecraft:water" => (p, count * 3, 3.0, 1.0, false),
None => return,
};
let options = ParticleOptions::simple(ParticleType::HappyVillager);
for _ in 0..count.max(0) {
let r = self.particles.level_random();
let v = [0.0; 3].map(|_: f64| r.next_gaussian() * 0.02);
let start = 0.5 - xz;
let x = f64::from(at[0]) + start + r.next_double() * xz * 2.0;
let y = f64::from(at[1]) + r.next_double() * height;
let z = f64::from(at[2]) + start + r.next_double() * xz * 2.0;
let below = [x.floor() as i32, y.floor() as i32 - 1, z.floor() as i32];
if floating
|| !self
.res
.facts()
.is_air(self.world.block(below[0], below[1], below[2]))
{
self.particles.add(&options, [x, y, z], v);
}
}
}
/// Queue and play level event `id` at `pos` (`Level.levelEvent`).
pub(super) fn level_event_at(&mut self, id: i32, pos: [i32; 3], data: i32) {
self.level_events.push(LevelEvent::LevelEvent {
+38 -23
View File
@@ -1725,29 +1725,10 @@ impl Game<'_> {
self.block_entity_event(p.pos, i32::from(p.b0), i32::from(p.b1));
}
}
C::LevelEvent(p) if p.kind == 2015 => {
self.dragon_egg_particles(p.pos, p.data);
}
C::LevelEvent(p) if p.kind == 2017 => {
self.consume_teleport_particles(p.pos, p.data);
}
C::LevelEvent(p) if p.kind == 2001 => {
// LevelEvent.PARTICLES_DESTROY_BLOCK: someone else broke a block.
let state = BlockStateId(p.data.max(0) as u32);
let s = self.res.facts().get(state).sounds.clone();
let at = [
f64::from(p.pos[0]) + 0.5,
f64::from(p.pos[1]) + 0.5,
f64::from(p.pos[2]) + 0.5,
];
self.audio.play(
&s.break_sound,
Some(at),
(s.volume + 1.0) / 2.0,
s.pitch * 0.8,
);
self.destroy_particles(p.pos, state);
}
// ClientLevel.levelEvent: LevelEventHandler, as this client's own
// level plays them (particles and sounds: a spawner's burst, bone
// meal, waxing, a block broken by someone else).
C::LevelEvent(p) => self.level_event_at(p.kind, p.pos, p.data),
C::Sound(p) => {
let name = match &p.sound.1 {
Some((location, _)) => Some(location.clone()),
@@ -3821,6 +3802,8 @@ impl Game<'_> {
}
if reacts {
self.predict_use(&changes, seq);
} else if let Some(stack) = held.as_ref() {
self.predict_item_on_block(stack, &hit);
}
if held_block {
if reacts
@@ -3839,6 +3822,38 @@ impl Game<'_> {
false
}
/// `Item.useOn` on this client's level for the items whose effects are
/// the clicker's own (`Level.levelEvent(player, ...)` and
/// `playSound(player, ...)`: the server sends them to the others only):
/// honeycomb waxing copper, and an axe, hoe or shovel transforming a
/// block (stripping, scraping, removing wax, tilling, making a path).
fn predict_item_on_block(&mut self, stack: &ItemStack, hit: &super::Hit) {
let at = [
f64::from(hit.pos[0]) + 0.5,
f64::from(hit.pos[1]) + 0.5,
f64::from(hit.pos[2]) + 0.5,
];
if &*stack.item == "minecraft:honeycomb" {
// HoneycombItem.useOn.
let registry = self.pack.assets.registry;
let clicked = self.world.block(hit.pos[0], hit.pos[1], hit.pos[2]);
let waxes = registry
.state(clicked)
.and_then(|old| self.res.transformers().waxed(registry, old))
.is_some();
if waxes {
self.level_event_at(3003, hit.pos, 0);
self.audio
.play("minecraft:item.honeycomb.wax_on", Some(at), 1.0, 1.0);
}
} else if let Some((_, sound, _, _, particle)) =
self.block_transform(stack, hit.pos, hit.face)
{
self.transform_particle(&particle, hit.pos);
self.audio.play(&sound, Some(at), 1.0, 1.0);
}
}
/// MultiPlayerGameMode.useItemOn inside startPrediction: the blocks the
/// use changed on this client's level at once, each kept as predicted
/// under the use's sequence until the server acknowledges it (a use the
+8
View File
@@ -1158,6 +1158,8 @@ pub struct ParticleEngine {
starters: Vec<Starter>,
/// Local sounds requested by particles (dripstone drips): (event, position, volume, pitch).
pub sounds: Vec<(&'static str, [f64; 3], f32, f32)>,
/// How many of each type were made, for `horizon-ctl status`.
made: std::collections::BTreeMap<&'static str, u64>,
/// The item particles' sprites (`BreakingItemParticle`'s slime ball, snowball
/// and cobweb models, resolved for the ground), one per model layer.
pub item_sprites: HashMap<ParticleType, Vec<String>>,
@@ -1183,6 +1185,7 @@ impl ParticleEngine {
starters: Vec::new(),
camera: [0.0; 3],
sounds: Vec::new(),
made: Default::default(),
item_sprites: HashMap::new(),
};
let dir = root.join("assets/minecraft/particles");
@@ -1449,9 +1452,14 @@ impl ParticleEngine {
pub fn create(&mut self, options: &ParticleOptions, p: [f64; 3], v: [f64; 3]) {
let seed = self.seeds.next_long();
if let Some(particle) = self.make(options, p, v, seed) {
*self.made.entry(options.ty.name()).or_default() += 1;
self.pending.push(particle);
}
}
/// How many particles of each type were made so far.
pub fn made(&self) -> &std::collections::BTreeMap<&'static str, u64> {
&self.made
}
/// Parity probes: seed the provider (`ParticleEngine.random`), level and
/// `SpellParticle.RANDOM` generators.
pub fn seed_randoms(&mut self, provider: i64, level: i64, spell: i64) {
+71 -2
View File
@@ -109,6 +109,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
the host has them; a falling block lands on both sides.
- thrown: a splash potion and an eye of ender the host and the guest each throw fly on both
sides (#1363, #1391);
- sparks: level events' particles on both sides: the host's and the guest's bone meal on wheat
(growth sparks), honeycomb on copper and an axe taking the wax off, and a spawner's
burst when it spawns (#1395, #1401, #1402);
- fireball: a fire charge a dispenser shoots onto stone lights a fire both sides see, and the fire
goes out on its own within a minute (it ticks: FireBlock.tick on a floor that doesn't burn)
@@ -210,7 +213,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', 'looks', 'leads', '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', 'thrown', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'worldspawn', 'beds', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels', 'drops', 'underwater']
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'looks', 'leads', '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', 'thrown', 'sparks', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'worldspawn', 'beds', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels', 'drops', 'underwater']
class Game:
@@ -2643,6 +2646,71 @@ def check_thrown(host, guest, out):
return result
def made(game, kind):
"""How many `kind` particles `game` has made so far."""
return game('status').get('particles', {}).get(kind, 0)
def sparked(player, other, kinds, act, ticks=20):
"""The `kinds` particles each side makes while `act` runs and for up to `ticks` after."""
before = {(side, k): made(g, k) for side, g in (('own', player), ('other', other)) for k in kinds}
act()
seen = {}
for _ in range(ticks // 2):
player.wait(2)
seen = {f'{side} {k}': made(g, k) - before[(side, k)]
for side, g in (('own', player), ('other', other)) for k in kinds}
if all(seen.values()):
break
return seen
def check_sparks(host, guest, out):
spots = apart(host, guest)
result = {}
for label, player, other in (('host', host, guest), ('guest', guest, host)):
x, y, z = spots[label]
at = (x, y, z + 2)
player('command', command='gamemode survival')
try:
player('command', command=f'setblock {at[0]} {at[1] - 1} {at[2]} minecraft:farmland')
player('command', command=f'setblock {at[0]} {at[1]} {at[2]} minecraft:wheat')
player('command', command='item replace entity @s weapon.mainhand with minecraft:bone_meal 8')
player.wait(10)
def click(height):
player.raw('look-at', f'{at[0] + 0.5:.2f}', f'{at[1] + height:.2f}', f'{at[2] + 0.5:.2f}')
player.raw('mouse', 'right', 'click')
result[f'{label} bone meal'] = sparked(player, other, ['happy_villager'], lambda: click(0.1))
player('command', command=f'setblock {at[0]} {at[1]} {at[2]} minecraft:copper_block')
player('command', command='item replace entity @s weapon.mainhand with minecraft:honeycomb')
player.wait(10)
result[f'{label} wax'] = sparked(player, other, ['wax_on'], lambda: click(0.5))
player('command', command='item replace entity @s weapon.mainhand with minecraft:iron_axe')
player.wait(10)
result[f'{label} wax off'] = sparked(player, other, ['wax_off'], lambda: click(0.5))
block = player.raw('block', *at).get('block', '')
result[f'{label} copper'] = block
finally:
player('command', command=f'fill {at[0]} {at[1] - 1} {at[2]} {at[0]} {at[1]} {at[2]} minecraft:air')
player('command', command=f'setblock {at[0]} {at[1] - 1} {at[2]} minecraft:stone')
player('command', command='clear @s')
# A spawner beside the host, at night: its burst when the zombie comes.
x, y, z = spots['host']
host('command', command='time set midnight')
try:
host('command', command=f'setblock {x} {y} {z + 3} minecraft:spawner{{Delay:20s,SpawnCount:1s,'
'SpawnData:{entity:{id:"minecraft:zombie",NoAI:1b}}}')
result['spawner'] = sparked(host, guest, ['flame', 'smoke'], lambda: None, ticks=200)
finally:
host('command', command=f'setblock {x} {y} {z + 3} minecraft:air')
host('command', command=f'kill @e[type=minecraft:zombie,x={x},y={y},z={z},distance=..12]')
host('command', command='time set day')
wrong = {k: v for k, v in result.items() if isinstance(v, dict) and not all(n > 0 for n in v.values())}
assert not wrong, f'no particles: {wrong}\n{result}'
return result
def check_blast(host, guest, out):
guest('command', command='gamemode survival')
guest('command', command='clear @s')
@@ -3977,7 +4045,8 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour,
'underwater': check_underwater,
'looks': check_looks,
'leads': check_leads,
'thrown': check_thrown}
'thrown': check_thrown,
'sparks': check_sparks}
def run(ctl, out, resources, checks):