Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

Mobs and dropped items at the top of a bubble column send its surface particles

Akirabane3df30d4d8418
diff --git a/crates/horizon-client/src/entities.rs b/crates/horizon-client/src/entities.rs
index 398149827..84739264a 100644
--- a/crates/horizon-client/src/entities.rs
+++ b/crates/horizon-client/src/entities.rs
@@ -1915,6 +1915,53 @@ mod honey_slide_tests {
);
}
+ /// `Entity.sendBubbleColumnParticles` is for the top of a column only: an item
+ /// inside the column shows nothing, one in its surface block shows the block.
+ #[test]
+ fn an_item_at_the_top_of_a_bubble_column_is_at_its_surface() {
+ let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("../../.local/horizon-client")
+ .join(horizon_core::VANILLA_VERSION);
+ if !root.join("movement-properties.nbt").exists() {
+ return;
+ }
+ let assets = crate::assets::Assets::load(&root).unwrap();
+ let render = assets.reload(&root).unwrap();
+ let facts = crate::blocks::BlockFacts::load(&root, assets.registry).unwrap();
+ let collision = crate::collisions::load(&root, assets.registry).unwrap();
+ let mut world = World::test_scene(&assets, &render, 3).unwrap();
+ let mut column = assets
+ .registry
+ .state(
+ assets
+ .registry
+ .default_state("minecraft:bubble_column")
+ .unwrap(),
+ )
+ .unwrap()
+ .clone();
+ column.properties.insert("drag".into(), "false".into());
+ let column = assets.registry.resolve(&column).unwrap();
+ for y in 4..=8 {
+ world.set(20, y, 20, column).unwrap();
+ }
+ let surfaces = |y: f64| {
+ let item = falling_item(20.5, y, 20.5, 0.0, 0.0, 0.0);
+ crate::motion::bubble_column_surfaces(
+ &world,
+ assets.registry,
+ &facts,
+ &collision,
+ item.bounds(),
+ )
+ };
+ assert_eq!(surfaces(8.2), vec![BlockPos::new(20, 8, 20)]);
+ assert_eq!(surfaces(5.0), Vec::new());
+ // Straddling the two top blocks, it is still at the top of one column.
+ assert_eq!(surfaces(7.9), vec![BlockPos::new(20, 8, 20)]);
+ assert_eq!(surfaces(9.0), Vec::new());
+ }
+
pub(super) fn falling_item(x: f64, y: f64, z: f64, vx: f64, vy: f64, vz: f64) -> ItemEntity {
let at = Vec3::new(x, y, z);
ItemEntity {
diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs
index 61916910c..39fbe9079 100644
--- a/crates/horizon-client/src/game.rs
+++ b/crates/horizon-client/src/game.rs
@@ -3809,6 +3809,7 @@ impl Game<'_> {
let merging = self.remote.is_none();
let obstacles = horizon_client::entities::ObstacleGrid::new(self.item_entity_collisions());
let mut nearby = Vec::new();
+ let mut bubble_tops = Vec::new();
for i in 0..items.len() {
if removed[i] {
// Merged into an earlier item before its own tick: it never ticked.
@@ -3854,6 +3855,17 @@ impl Game<'_> {
&nearby,
);
cells.moved(i, item.previous, item.position);
+ // Entity.handleOnAboveBubbleColumn: the server sends the particles of
+ // the surface of a bubble column the item is at the top of.
+ if merging {
+ bubble_tops.extend(horizon_client::motion::bubble_column_surfaces(
+ &self.world,
+ self.pack.assets.registry,
+ self.res.facts(),
+ self.collision,
+ item.bounds(),
+ ));
+ }
// ItemEntity.tick: merge every 2 ticks while moving between
// blocks, every 40 otherwise, before the lifetime check.
let block = |v: Vec3| (v.x.floor(), v.y.floor(), v.z.floor());
@@ -3901,6 +3913,9 @@ impl Game<'_> {
cells.remove(i, item.position);
}
}
+ for pos in bubble_tops {
+ self.bubble_column_particles(pos);
+ }
let mut removed = removed.into_iter();
items.retain(|_| !removed.next().unwrap_or(false));
let Some(p) = self.player.as_ref() else {
diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs
index b923b862b..f73ee6c80 100644
--- a/crates/horizon-client/src/game/creatures.rs
+++ b/crates/horizon-client/src/game/creatures.rs
@@ -1709,9 +1709,38 @@ impl Game<'_> {
}
self.creatures.projectiles.push(p);
}
+ /// `Entity.sendBubbleColumnParticles` at the top of the column block `pos`: two
+ /// splashes and two bubbles over it, which the level random places, shown here
+ /// and to the players within range.
+ pub(super) fn bubble_column_particles(&mut self, pos: BlockPos) {
+ for _ in 0..2 {
+ let r = &mut self.world.random;
+ let splash = [
+ f64::from(pos.x) + r.next_double(),
+ f64::from(pos.y + 1),
+ f64::from(pos.z) + r.next_double(),
+ ];
+ let bubble = [
+ f64::from(pos.x) + r.next_double(),
+ f64::from(pos.y + 1),
+ f64::from(pos.z) + r.next_double(),
+ ];
+ let splash_options = ParticleOptions::simple(ParticleType::Splash);
+ self.particles
+ .send_particles(&splash_options, splash, [0.0; 3], 1.0, 1);
+ self.lan_level_particles(&splash_options, splash, [0.0; 3], 1.0, 1, None);
+ let bubble_options = ParticleOptions::simple(ParticleType::Bubble);
+ self.particles
+ .send_particles(&bubble_options, bubble, [0.0, 0.01, 0.0], 0.2, 1);
+ self.lan_level_particles(&bubble_options, bubble, [0.0, 0.01, 0.0], 0.2, 1, None);
+ }
+ }
pub(super) fn handle_mob_events(&mut self, events: Vec<MobEvent>) -> Result<()> {
for e in events {
match e {
+ MobEvent::BubbleColumnParticles { pos } => {
+ self.bubble_column_particles(BlockPos::new(pos[0], pos[1], pos[2]))
+ }
MobEvent::SquidCycle { mob, at } => self.lan_entity_event(mob as i32, 19, at),
MobEvent::RabbitHop { mob, at } => self.lan_entity_event(mob as i32, 1, at),
MobEvent::Drown { mob, at } => {
@@ -3881,36 +3910,7 @@ impl Game<'_> {
self.audio
.play(name, Some([at.x, at.y, at.z]), volume, pitch);
}
- ArrowEvent::BubbleColumnParticles { pos } => {
- // Entity.sendBubbleColumnParticles: the level random places them.
- for _ in 0..2 {
- let r = &mut self.world.random;
- let splash = [
- f64::from(pos.x) + r.next_double(),
- f64::from(pos.y + 1),
- f64::from(pos.z) + r.next_double(),
- ];
- let bubble = [
- f64::from(pos.x) + r.next_double(),
- f64::from(pos.y + 1),
- f64::from(pos.z) + r.next_double(),
- ];
- self.particles.send_particles(
- &ParticleOptions::simple(ParticleType::Splash),
- splash,
- [0.0; 3],
- 1.0,
- 1,
- );
- self.particles.send_particles(
- &ParticleOptions::simple(ParticleType::Bubble),
- bubble,
- [0.0, 0.01, 0.0],
- 0.2,
- 1,
- );
- }
- }
+ ArrowEvent::BubbleColumnParticles { pos } => self.bubble_column_particles(pos),
ArrowEvent::Block { pos, reaction } => match reaction {
BlockReaction::PrimeTnt => {
self.spawn_primed_tnt(pos, false, None, None);
diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs
index d1d9b541b..ceabcb82c 100644
--- a/crates/horizon-client/src/mobs.rs
+++ b/crates/horizon-client/src/mobs.rs
@@ -1283,6 +1283,11 @@ pub enum MobEvent {
count: u32,
},
Sound(&'static str, [f64; 3], f32, f32),
+ /// `Entity.sendBubbleColumnParticles`: a mob at the top of the bubble column
+ /// block at `pos` (the splash and bubble particles over it).
+ BubbleColumnParticles {
+ pos: [i32; 3],
+ },
/// `UseBonemeal`: the villager's bone meal grows the crop at `pos`
/// (`BoneMealItem.growCrop`, then level event 1505).
Bonemeal {
diff --git a/crates/horizon-client/src/mobs/living.rs b/crates/horizon-client/src/mobs/living.rs
index 8ed523a3f..85cbc7773 100644
--- a/crates/horizon-client/src/mobs/living.rs
+++ b/crates/horizon-client/src/mobs/living.rs
@@ -630,17 +630,25 @@ impl Mob {
// Entity.checkSupportingBlock
self.supporting = self.supporting_block(w, moved);
self.movement_emission(w, moved, events);
- // Entity.applyEffectsFromBlocks: bubble columns push the mob.
- if crate::motion::bubble_column_push(
+ // Entity.applyEffectsFromBlocks: bubble columns push the mob, and the
+ // server shows the surface of one it is at the top of.
+ let mut tops = Vec::new();
+ if crate::motion::bubble_column_push_over(
w.world,
w.registry,
w.facts,
w.collision,
self.bounds(),
&mut self.velocity,
+ |pos| tops.push(pos),
) {
self.fall_distance = 0.0;
}
+ for pos in tops {
+ events.push(MobEvent::BubbleColumnParticles {
+ pos: [pos.x, pos.y, pos.z],
+ });
+ }
}
/// LivingEntity.checkFallDamage: the fluid state refreshed out of water
/// (touching water resets the fall), then Entity.checkFallDamage.
diff --git a/crates/horizon-client/src/motion.rs b/crates/horizon-client/src/motion.rs
index 2e8de99ca..a3a7b69d6 100644
--- a/crates/horizon-client/src/motion.rs
+++ b/crates/horizon-client/src/motion.rs
@@ -47,7 +47,7 @@ pub(crate) mod environment;
mod fluids;
pub use fluids::{
BubbleColumn, FluidResources, FluidTags, LAVA, PlayerFluids, RiddenBoat, WATER,
- bubble_column_at, bubble_column_push,
+ bubble_column_at, bubble_column_push, bubble_column_push_over, bubble_column_surfaces,
};
pub struct MotionResources {
diff --git a/crates/horizon-client/src/motion/fluids.rs b/crates/horizon-client/src/motion/fluids.rs
index 469f96876..ea6ee5a68 100644
--- a/crates/horizon-client/src/motion/fluids.rs
+++ b/crates/horizon-client/src/motion/fluids.rs
@@ -144,25 +144,71 @@ pub fn bubble_column_push(
bounds: Aabb,
velocity: &mut Vec3,
) -> bool {
+ bubble_column_push_over(world, registry, facts, collision, bounds, velocity, |_| {})
+}
+/// [`bubble_column_push`], telling `surface` the position of each column block
+/// the entity is at the top of: `handleOnAboveBubbleColumn` sends the splash and
+/// bubble particles over it (`Entity.sendBubbleColumnParticles`).
+pub fn bubble_column_push_over(
+ world: &World,
+ registry: &horizon_world::registry::BlockRegistry,
+ facts: &crate::blocks::BlockFacts,
+ collision: &horizon_world::block_collision::BlockCollisionRegistry<'_>,
+ bounds: Aabb,
+ velocity: &mut Vec3,
+ mut surface: impl FnMut(BlockPos),
+) -> bool {
+ let mut reset_fall = false;
+ bubble_columns_touching(world, registry, facts, collision, bounds, |pos, column| {
+ reset_fall |= column.push(velocity);
+ if column.surface {
+ surface(pos);
+ }
+ });
+ reset_fall
+}
+/// The column blocks `bounds` touches that it is at the top of: where the
+/// particles of `Entity.sendBubbleColumnParticles` start.
+pub fn bubble_column_surfaces(
+ world: &World,
+ registry: &horizon_world::registry::BlockRegistry,
+ facts: &crate::blocks::BlockFacts,
+ collision: &horizon_world::block_collision::BlockCollisionRegistry<'_>,
+ bounds: Aabb,
+) -> Vec<BlockPos> {
+ let mut surfaces = Vec::new();
+ bubble_columns_touching(world, registry, facts, collision, bounds, |pos, column| {
+ if column.surface {
+ surfaces.push(pos);
+ }
+ });
+ surfaces
+}
+/// Every bubble column block the box touches (`Entity.getInsideBlockPoints`).
+fn bubble_columns_touching(
+ world: &World,
+ registry: &horizon_world::registry::BlockRegistry,
+ facts: &crate::blocks::BlockFacts,
+ collision: &horizon_world::block_collision::BlockCollisionRegistry<'_>,
+ bounds: Aabb,
+ mut each: impl FnMut(BlockPos, BubbleColumn),
+) {
let b = bounds.deflate(Vec3::new(
f64::from(1.0e-5f32),
f64::from(1.0e-5f32),
f64::from(1.0e-5f32),
));
let (lo, hi) = (b.min_position(), b.max_position());
- let mut reset_fall = false;
for x in lo.x.floor() as i32..=(hi.x.ceil() as i32 - 1) {
for y in lo.y.floor() as i32..=(hi.y.ceil() as i32 - 1) {
for z in lo.z.floor() as i32..=(hi.z.ceil() as i32 - 1) {
- if let Some(column) =
- bubble_column_at(world, registry, facts, collision, BlockPos::new(x, y, z))
- {
- reset_fall |= column.push(velocity);
+ let pos = BlockPos::new(x, y, z);
+ if let Some(column) = bubble_column_at(world, registry, facts, collision, pos) {
+ each(pos, column);
}
}
}
}
- reset_fall
}
/// A bubble column block as `BubbleColumnBlock.entityInside` sees it: whether
/// it drags down (`DRAG_DOWN`), and whether it is the surface (nothing above it