Match vanilla random ticks on every comparable case

The random tick oracle now stands on a real overworld: the data pack's
dimension type (for fire's infiniburn tag), its attributes and day timeline
on a clock at the fixture's day time, level data for difficulty, and block
scans that walk positions in BlockScanUtils' section order, since 26.3 reads
chunk sections the map-backed level does not have.

Horizon now rolls the nether portal's zombified piglin spawn with the level
random (the client spawns it near a player), rechecks chest and ender chest
openers through a new block entity hook and broadcasts the lid event, gives
melting ice and placed sniffer eggs their game events, and reads the weather
age of copper golem statues, which name the field weatheringState. The
fixture prints empty dispensers, crafters, ghastling spawns and fresh
shriekers as vanilla resolves them.

Random ticks match on 39,998 of 39,998 compared cases (two propagules cannot
grow trees in the oracle), block updates on 40,000 of 40,000 and redstone on
3,999 of 4,000.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-10 18:51:18 +02:00
parent 1344df60f0
commit 11b8a98ff5
9 changed files with 227 additions and 8 deletions
+5
View File
@@ -1552,6 +1552,11 @@ impl Game<'_> {
kind: "hatch_sniffer",
..
} => self.hatch_sniffer([pos.x, pos.y, pos.z]),
LevelEvent::BlockEvent {
pos,
kind: "portal_spawn",
..
} => self.portal_spawn([pos.x, pos.y, pos.z]),
LevelEvent::BlockEvent {
pos,
state,
+2
View File
@@ -547,6 +547,8 @@ impl Game<'_> {
block_drops: r.bool("block_drops"),
mob_griefing: r.bool("mob_griefing"),
max_snow_accumulation_height: r.int("max_snow_accumulation_height"),
spawn_mobs: r.bool("spawn_mobs"),
spawn_monsters: r.bool("spawn_monsters"),
}
}
/// Apply rules mirrored in other state (natural regeneration, difficulty).
@@ -2672,3 +2672,35 @@ fn push_apart(mobs: &mut [Mob]) {
}
}
}
impl Game<'_> {
/// The rest of `NetherPortalBlock.randomTick` after a won roll: with a
/// player close enough for spawning, a zombified piglin spawns on the block
/// under the portal column when it is a valid spawn.
pub(super) fn portal_spawn(&mut self, pos: [i32; 3]) {
// ChunkMap.anyPlayerCloseEnoughForSpawning: a non-spectator within 128
// blocks of the chunk centre.
let centre = [f64::from((pos[0] >> 4) * 16 + 8), f64::from((pos[2] >> 4) * 16 + 8)];
let spectator = self.spectator();
let Some(close) = self.player.as_ref().filter(|_| !spectator).map(|p| {
let (dx, dz) = (p.position.x - centre[0], p.position.z - centre[1]);
dx * dx + dz * dz < 16384.0
}) else {
return;
};
if !close {
return;
}
let mut y = pos[1];
while &*self.res.facts.get(self.world.block(pos[0], y, pos[2])).name == "minecraft:nether_portal" {
y -= 1;
}
// isValidSpawn: a sturdy top face (portal frames emit no light).
let below = self.res.facts.get(self.world.block(pos[0], y, pos[2]));
if below.sturdy_full & (1 << 1) == 0 {
return;
}
let at = [f64::from(pos[0]) + 0.5, f64::from(y + 1), f64::from(pos[2]) + 0.5];
let _ = self.spawn_mob("minecraft:zombified_piglin", at, false);
}
}
@@ -50,6 +50,10 @@ impl LevelAccess for Cells {
fn is_loaded(&self, _pos: BlockPos) -> bool {
true
}
/// A chest's fresh block entity: nobody has it open.
fn recheck_container_openers(&mut self, _pos: BlockPos) -> Option<(i32, i32)> {
Some((0, 0))
}
/// A fresh command block entity: unpowered and not automatic.
fn set_command_block_powered(&mut self, pos: BlockPos, powered: bool) -> Option<(bool, bool)> {
Some((self.command_blocks.insert(pos, powered).unwrap_or(false), false))
@@ -313,6 +317,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
}
// DriedGhastBlock.spawnGhastling, as the client does it.
LevelEvent::BlockEvent { kind: "spawn_ghastling", .. } => {
let _ = writeln!(result, "E minecraft:happy_ghast");
let _ = writeln!(result, "S entity minecraft:entity.ghastling.spawn");
}
// A fresh shrieker has warning level 0 and so never responds,
// and no player is near enough for a portal to spawn a piglin.
LevelEvent::BlockEvent { kind: "shrieker_respond" | "portal_spawn", .. } => {}
LevelEvent::BlockEvent { kind, .. } => {
let _ = writeln!(result, "X {kind}");
}
+3 -1
View File
@@ -993,7 +993,9 @@ pub(super) fn load(registry: &BlockRegistry, root: &Path) -> io::Result<Behaviou
schedule_fluid_ticks: field("scheduleFluidTicks")
.and_then(Value::as_bool)
.unwrap_or(false),
weather: match field("weatherState").and_then(Value::as_str) {
// `WeatheringCopper.getAge`: copper golem statues name the field
// `weatheringState`.
weather: match field("weatherState").or_else(|| field("weatheringState")).and_then(Value::as_str) {
Some("EXPOSED") => 1,
Some("WEATHERED") => 2,
Some("OXIDIZED") => 3,
+5 -3
View File
@@ -193,6 +193,7 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
if boosted {
self.level_event(3009, pos, 0);
}
self.game_event_state(pos, "minecraft:block_place", state);
let delay = if boosted { 12000 } else { 24000 } / 3;
let jitter = self.random().next_int_bound(300).unwrap_or(0);
self.schedule_tick(pos, block, delay + jitter);
@@ -538,11 +539,11 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
true
}
/// `FrostedIceBlock.melt` → `IceBlock.melt`.
pub(crate) fn frosted_ice_melt(&mut self, pos: BlockPos, _state: BlockStateId) {
self.ice_melt(pos);
pub(crate) fn frosted_ice_melt(&mut self, pos: BlockPos, state: BlockStateId) {
self.ice_melt(pos, state);
}
/// `IceBlock.melt`.
pub(crate) fn ice_melt(&mut self, pos: BlockPos) {
pub(crate) fn ice_melt(&mut self, pos: BlockPos, state: BlockStateId) {
let b = self.b;
if self.level.dimension() == super::Dimension::Nether {
self.remove_block(pos, false);
@@ -550,6 +551,7 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
let water = b.default_of(b.named.water);
self.set_block_and_update(pos, water);
self.neighbor_changed_at(pos, b.named.water);
self.game_event_state(pos, "minecraft:block_destroy", state);
}
}
/// `BigDripleafBlock.resetTilt`.
+14 -1
View File
@@ -177,6 +177,8 @@ pub struct GameRules {
pub block_drops: bool,
pub mob_griefing: bool,
pub max_snow_accumulation_height: i32,
pub spawn_mobs: bool,
pub spawn_monsters: bool,
}
impl Default for GameRules {
fn default() -> Self {
@@ -187,6 +189,8 @@ impl Default for GameRules {
block_drops: true,
mob_griefing: true,
max_snow_accumulation_height: 1,
spawn_mobs: true,
spawn_monsters: true,
}
}
}
@@ -247,7 +251,9 @@ pub enum LevelEvent {
PrimeTnt { pos: BlockPos, rot: f64 },
/// Block-entity or entity side effects the caller implements: `"dispense"`
/// (dispenser/dropper/crafter scheduled tick), `"hatch"` (frogspawn
/// hatched into tadpoles; the block is already destroyed).
/// hatched into tadpoles; the block is already destroyed), `"portal_spawn"`
/// (a nether portal won its zombified piglin roll; the caller checks
/// `anyPlayerCloseEnoughForSpawning` and spawns below the portal).
BlockEvent {
pos: BlockPos,
state: BlockStateId,
@@ -335,6 +341,13 @@ pub trait LevelAccess {
) -> i32 {
0
}
/// `ContainerOpenersCounter.recheckOpenCount` for the chest or ender chest
/// block entity at `pos`: recounts its openers and returns the previous
/// and new counts (the caller plays open/close effects when they change),
/// or None when there is no such block entity.
fn recheck_container_openers(&mut self, _pos: BlockPos) -> Option<(i32, i32)> {
None
}
/// `CommandBlockEntity.setPowered` for the command block entity at `pos`:
/// stores `powered` and returns the previous flag and `isAutomatic`, or
/// None when there is no command block entity.
+35 -2
View File
@@ -95,6 +95,21 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
}
}
}
Class::Chest | Class::EnderChest => {
// recheckOpen: openerCountChanged broadcasts the lid, a
// trapped chest also updates its neighbours on a change,
// and the recheck repeats while anyone has it open.
if let Some((previous, count)) = self.level.recheck_container_openers(pos) {
self.block_event(pos, block, 1, count);
if previous != count && b.data(state).is(Class::TrappedChest) {
self.update_neighbors_at(pos, block);
self.update_neighbors_at(below(pos), block);
}
if count > 0 {
self.schedule_tick(pos, block, 5);
}
}
}
Class::Dispenser | Class::Crafter => {
self.emit(LevelEvent::BlockEvent {
pos,
@@ -243,6 +258,24 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
}
}
Class::Farmland => self.farmland_random_tick(state, pos),
Class::NetherPortal => {
// NetherPortalBlock.randomTick: only the overworld sets
// NETHER_PORTAL_SPAWNS_PIGLINS.
let rules = self.level.game_rules();
let difficulty = self.level.difficulty();
if rules.spawn_mobs
&& rules.spawn_monsters
&& difficulty != 0
&& self.level.dimension() == super::Dimension::Overworld
&& self.rand_int(2000) < difficulty
{
self.emit(LevelEvent::BlockEvent {
pos,
state,
kind: "portal_spawn",
});
}
}
Class::GrowingPlantHead => {
if b.table.int(state, p.age) < 25
&& self.random().next_double() < data.grow_probability
@@ -256,7 +289,7 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
}
Class::Ice => {
if self.level.block_light(pos) > 11 - i32::from(b.facts(state).dampening) {
self.ice_melt(pos);
self.ice_melt(pos, state);
}
}
Class::Leaves => {
@@ -655,7 +688,7 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
self.set_block(pos, b.table.set_int(state, b.props.age, age + 1), 2);
false
} else {
self.ice_melt(pos);
self.ice_melt(pos, state);
true
}
}