Build golems and withers from dispensers as vanilla does

Golems and the wither come from EntityType.create (no spawn finalization,
no level random), after clearPatternBlocks sets every pattern cell to air
with flags 2 and a destroy event, and updatePatternBlocks follows. A
dispensed pumpkin that completes a golem skips setBlock's neighbour
updates as vanilla's does, and pumpkins and skulls post block_place.
Dispensed skulls face RotationSegment.convertToSegment(facing). Destroy
events for air play no break sound. The dispenser fixture plays on normal
difficulty like the oracle level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-11 15:53:37 +02:00
parent 1b4c3dec6b
commit 894113d7f4
5 changed files with 95 additions and 39 deletions
+5 -1
View File
@@ -1390,10 +1390,14 @@ impl Game<'_> {
pos,
data,
} => {
// LevelRenderer: destroy particles and the block's break sound.
// LevelEventHandler: destroy particles and the block's
// break sound (none for air).
let state = BlockStateId(data as u32);
let p = [pos.x, pos.y, pos.z];
self.destroy_particles(p, state);
if self.res.facts.is_air(state) {
continue;
}
let sounds = self.res.facts.get(state).sounds.clone();
let c = [
f64::from(pos.x) + 0.5,
@@ -115,6 +115,8 @@ impl Game<'_> {
self.orbs.clear();
self.falling.clear();
self.ui.rules = Default::default();
// The oracle level plays on normal difficulty.
self.ui.difficulty = 2;
// The oracle level has world seed 0 and fresh random sequences.
self.level.seed = 0;
self.rand_sequences = Default::default();
+17 -4
View File
@@ -1353,8 +1353,8 @@ impl Game<'_> {
let rotation = match facing {
Direction::Up | Direction::Down => 0,
other => {
// RotationSegment.convertToSegment: opposite 2D data value * 4.
(match other.opposite() {
// RotationSegment.convertToSegment: the 2D data value * 4.
(match other {
Direction::South => 0,
Direction::West => 1,
Direction::North => 2,
@@ -1373,6 +1373,7 @@ impl Game<'_> {
if let Some(entity) = BlockEntity::for_block("minecraft:wither_skeleton_skull") {
self.world.block_entities.insert(target, entity);
}
self.post_block_game_event("minecraft:block_place", [target.0, target.1, target.2], None, None);
self.check_wither_spawn([target.0, target.1, target.2])?;
return Ok((shrink(stack), CLICK));
}
@@ -1425,8 +1426,20 @@ impl Game<'_> {
.registry
.default_state("minecraft:carved_pumpkin")
{
self.level_set([target.0, target.1, target.2], pumpkin)?;
self.check_golem_spawn([target.0, target.1, target.2])?;
let head = [target.0, target.1, target.2];
if self.completes_golem(head) {
// CarvedPumpkinBlock.onPlace builds the golem inside
// setBlock; the spot is air again by the time setBlock
// would update neighbours, so it skips them.
let at = Self::pos_of(target);
self.with_level(|b, level, ticks| b.set_block(level, ticks, at, pumpkin, 2 | 16));
self.process_level_events()?;
self.check_golem_spawn(head)?;
} else {
self.level_set(head, pumpkin)?;
self.check_golem_spawn(head)?;
}
self.post_block_game_event("minecraft:block_place", head, None, None);
}
return Ok((shrink(stack), CLICK));
}
+60 -18
View File
@@ -24,6 +24,7 @@ impl Game<'_> {
if self.golem_block(below(1)) == "minecraft:snow_block"
&& self.golem_block(below(2)) == "minecraft:snow_block"
{
// The pattern ("^", "#", "#") is one column.
return Some((
"minecraft:snow_golem",
vec![head, below(1), below(2)],
@@ -38,9 +39,11 @@ impl Game<'_> {
&& self.golem_block(side(0, 2)) == "minecraft:iron_block"
&& [-1, 1].iter().all(|&s| air(side(s, 0)) && air(side(s, 2)))
{
let mut blocks = vec![head];
blocks.extend((-1..=1).map(|s| side(s, 1)));
blocks.push(side(0, 2));
// Every cell of ("~^~", "###", "~#~"), the air ones included.
let blocks = (-1..=1)
.flat_map(|s| (0..3).map(move |row| (s, row)))
.map(|(s, row)| side(s, row))
.collect();
return Some(("minecraft:iron_golem", blocks, side(0, 2)));
}
}
@@ -58,27 +61,66 @@ impl Game<'_> {
let Some((kind, blocks, base)) = self.find_golem(head) else {
return self.try_spawn_copper_golem(head);
};
for p in blocks {
let state = self.world.block(p[0], p[1], p[2]);
self.destroy_particles(p, state);
self.level_set(p, self.world.air)?;
}
// CarvedPumpkinBlock.spawnGolemInWorld
self.clear_pattern_blocks(&blocks)?;
let at = [
f64::from(base[0]) + 0.5,
f64::from(base[1]) + 0.05,
f64::from(base[2]) + 0.5,
];
if let Some(id) = self.spawn_mob(kind, at, false)
&& let Some(m) = self.mobs.iter_mut().find(|m| m.id == id)
{
m.yaw = 0.0;
m.body_yaw = 0.0;
m.head_yaw = 0.0;
m.previous_yaw = 0.0;
m.previous_body_yaw = 0.0;
m.previous_head_yaw = 0.0;
self.create_triggered(kind, at, 0.0);
self.update_pattern_blocks(&blocks)
}
/// Whether placing a golem head at `head` completes a snow or iron golem.
pub(super) fn completes_golem(&self, head: [i32; 3]) -> bool {
self.find_golem(head).is_some()
}
/// `EntityType.create(level, TRIGGERED)` and `snapTo`: a built golem or
/// wither has no spawn finalization and draws nothing from the level.
pub(super) fn create_triggered(&mut self, kind: &str, at: [f64; 3], yaw: f32) -> Option<u32> {
let t = self.res.mob_types.get(kind).cloned()?;
self.next_entity += 1;
let mut mob = horizon_client::mobs::Mob::new(
self.next_entity,
t,
horizon_core::geometry::Vec3::new(at[0], at[1], at[2]),
yaw,
);
mob.head_yaw = yaw;
mob.body_yaw = yaw;
mob.previous_yaw = yaw;
mob.previous_body_yaw = yaw;
mob.previous_head_yaw = yaw;
let id = mob.id;
self.mobs.push(mob);
Some(id)
}
/// `CarvedPumpkinBlock.clearPatternBlocks`: every cell of the match
/// becomes air (flags 2) with its destroy event (2001).
pub(super) fn clear_pattern_blocks(&mut self, cells: &[[i32; 3]]) -> Result<()> {
let air = self.world.air;
for &p in cells {
let state = self.world.block(p[0], p[1], p[2]);
let pos = horizon_core::position::BlockPos::new(p[0], p[1], p[2]);
self.with_level(|b, level, ticks| b.set_block(level, ticks, pos, air, 2));
self.level_events
.push(horizon_world::level::LevelEvent::LevelEvent {
id: 2001,
pos,
data: state.0 as i32,
});
}
Ok(())
self.process_level_events()
}
/// `CarvedPumpkinBlock.updatePatternBlocks`: neighbours of every cell
/// hear that air arrived.
pub(super) fn update_pattern_blocks(&mut self, cells: &[[i32; 3]]) -> Result<()> {
let air = self.world.air;
for &p in cells {
let pos = horizon_core::position::BlockPos::new(p[0], p[1], p[2]);
self.with_level(|b, level, ticks| b.update_neighbors_at(level, ticks, pos, b.block(air)));
}
self.process_level_events()
}
/// A pumpkin on a copper block: the block turns into the matching copper
/// chest (facing the pumpkin's way) and a copper golem appears where the
+11 -16
View File
@@ -40,35 +40,30 @@ impl Game<'_> {
if !ok {
continue;
}
for row in 0..3 {
for c in 0..3 {
let p = at(c, row);
let state = self.world.block(p[0], p[1], p[2]);
if !self.res.facts.is_air(state) {
self.destroy_particles(p, state);
self.world.set(p[0], p[1], p[2], self.world.air)?;
}
}
}
// WitherSkullBlock.checkSpawn: clear the pattern, the wither
// appears on the middle of the bottom row, then neighbours update.
let cells: Vec<[i32; 3]> = (0..3)
.flat_map(|c| (0..3).map(move |row| (c, row)))
.map(|(c, row)| at(c, row))
.collect();
self.clear_pattern_blocks(&cells)?;
let base = at(1, 2);
let at = [
f64::from(base[0]) + 0.5,
f64::from(base[1]) + 0.55,
f64::from(base[2]) + 0.5,
];
if let Some(id) = self.spawn_mob("minecraft:wither", at, true)
let yaw = if ax == 1 { 0.0 } else { 90.0 };
if let Some(id) = self.create_triggered("minecraft:wither", at, yaw)
&& let Some(m) = self.mobs.iter_mut().find(|m| m.id == id)
{
let yaw = if ax == 1 { 0.0 } else { 90.0 };
m.yaw = yaw;
m.body_yaw = yaw;
m.previous_body_yaw = yaw;
m.head_yaw = yaw;
m.persistent = true;
horizon_client::mobs::wither::make_invulnerable(m);
let view =
self.mob_entity(&self.mobs.iter().find(|m| m.id == id).cloned().unwrap());
self.trigger_entity("minecraft:summoned_entity", "entity", &view);
}
self.update_pattern_blocks(&cells)?;
return Ok(());
}
}