Merge pull request #1156 from ludovic111/fix/sulfur-bubbles
🤖 Agent: merged. Verify passes; local parity --changed origin/main passes (101 harnesses; #1159's one online_mode diff reran clean and passes on main). Screenshots and tick-by-tick results in the body.
This commit is contained in:
@@ -112,21 +112,26 @@ fn state(s: &ParticleSnapshot) -> String {
|
||||
}
|
||||
out
|
||||
}
|
||||
fn world(assets: &Assets, facts: &BlockFacts, floor: bool) -> Result<World> {
|
||||
fn world(assets: &Assets, facts: &BlockFacts, floor: bool, water: bool) -> Result<World> {
|
||||
let mut world = World::new(facts.air, 0);
|
||||
let stone = assets
|
||||
.registry
|
||||
.default_state("minecraft:stone")
|
||||
.ok_or("missing stone")?;
|
||||
let state = |name: &str| assets.registry.default_state(name).ok_or("missing block");
|
||||
let (stone, still) = (state("minecraft:stone")?, state("minecraft:water")?);
|
||||
for cz in -3..=2 {
|
||||
for cx in -3..=2 {
|
||||
world
|
||||
.chunks
|
||||
.insert((cx, cz), Arc::new(Chunk::empty(cx, cz)));
|
||||
if floor {
|
||||
for z in 0..16 {
|
||||
for x in 0..16 {
|
||||
world.set(cx * 16 + x, 63, cz * 16 + z, stone)?;
|
||||
for z in 0..16 {
|
||||
for x in 0..16 {
|
||||
let (x, z) = (cx * 16 + x, cz * 16 + z);
|
||||
if floor {
|
||||
world.set(x, 63, z, stone)?;
|
||||
}
|
||||
// The oracle's water: still sources from y 64 to 67.
|
||||
if water {
|
||||
for y in 64..=67 {
|
||||
world.set(x, y, z, still)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,8 +147,10 @@ fn main() -> Result<()> {
|
||||
let facts = BlockFacts::load(root, assets.registry)?;
|
||||
let collision = collisions::load(root, assets.registry)?;
|
||||
let worlds = [
|
||||
world(&assets, &facts, false)?,
|
||||
world(&assets, &facts, true)?,
|
||||
world(&assets, &facts, false, false)?,
|
||||
world(&assets, &facts, true, false)?,
|
||||
world(&assets, &facts, false, true)?,
|
||||
world(&assets, &facts, true, true)?,
|
||||
];
|
||||
let mut engine = ParticleEngine::new(root, &HashMap::new());
|
||||
for (ty, item) in [
|
||||
@@ -174,7 +181,8 @@ fn main() -> Result<()> {
|
||||
engine.requested = Some(Vec::new());
|
||||
engine.sounds.clear();
|
||||
let level = ParticleLevel {
|
||||
world: &worlds[usize::from(case["floor"].as_bool() == Some(true))],
|
||||
world: &worlds[usize::from(case["floor"].as_bool() == Some(true))
|
||||
+ 2 * usize::from(case["water"].as_bool() == Some(true))],
|
||||
facts: &facts,
|
||||
collision: &collision,
|
||||
player: None,
|
||||
|
||||
@@ -61,6 +61,8 @@ enum Animate {
|
||||
Fire,
|
||||
/// An active sculk sensor.
|
||||
SculkSensor,
|
||||
/// Potent sulfur that is not dry.
|
||||
PotentSulfur,
|
||||
}
|
||||
fn step(facing: &str) -> [i32; 3] {
|
||||
match facing {
|
||||
@@ -128,6 +130,9 @@ fn classify(name: &str, prop: &dyn Fn(&str) -> Option<String>) -> Animate {
|
||||
}
|
||||
}
|
||||
"respawn_anchor" if prop("charges").is_some_and(|c| c != "0") => Animate::RespawnAnchor,
|
||||
"potent_sulfur" if prop("potent_sulfur_state").is_some_and(|s| s != "dry") => {
|
||||
Animate::PotentSulfur
|
||||
}
|
||||
"bubble_column" => Animate::BubbleColumn {
|
||||
drag: prop("drag").as_deref() == Some("true"),
|
||||
},
|
||||
@@ -819,6 +824,26 @@ fn block_animate_tick(
|
||||
}
|
||||
}
|
||||
}
|
||||
Animate::PotentSulfur => {
|
||||
// PotentSulfurBlock.animateTick: under a water source, two
|
||||
// bubbles and, one time in ten, the noxious gas.
|
||||
let above = ctx.facts.get(ctx.state([pos[0], pos[1] + 1, pos[2]]));
|
||||
if above.fluid == Fluid::Water && above.fluid_level == 8 && !above.fluid_falling {
|
||||
for _ in 0..2 {
|
||||
let r = engine.random();
|
||||
let p = [
|
||||
fx + f64::from(r.next_float()),
|
||||
fy + 1.0 + f64::from(r.next_float()),
|
||||
fz + f64::from(r.next_float()),
|
||||
];
|
||||
add(engine, T::SulfurBubbles, p, [0.0; 3]);
|
||||
}
|
||||
if next_int(engine.random(), 10) == 0 {
|
||||
let name = "minecraft:block.potent_sulfur.noxious_gas";
|
||||
sound(engine, name, [fx, fy, fz], 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Animate::Mycelium => {
|
||||
let r = engine.random();
|
||||
if next_int(r, 10) == 0 {
|
||||
|
||||
@@ -73,6 +73,7 @@ particle_types! {
|
||||
Splash = "splash",
|
||||
Rain = "rain",
|
||||
Bubble = "bubble",
|
||||
SulfurBubbles = "sulfur_bubbles",
|
||||
BubblePop = "bubble_pop",
|
||||
BubbleColumnUp = "bubble_column_up",
|
||||
CurrentDown = "current_down",
|
||||
@@ -352,6 +353,14 @@ enum Behaviour {
|
||||
},
|
||||
WaterDrop,
|
||||
Bubble,
|
||||
/// `SulfurBubbleParticle`: rises three blocks through still water,
|
||||
/// growing to 0.15.
|
||||
SulfurBubble {
|
||||
y_start: f64,
|
||||
y_end: f64,
|
||||
size_start: f32,
|
||||
y_prev: f64,
|
||||
},
|
||||
BubblePop,
|
||||
BubbleColumnUp,
|
||||
CurrentDown {
|
||||
@@ -1099,6 +1108,11 @@ impl ParticleLevel<'_> {
|
||||
};
|
||||
(s.fluid, height)
|
||||
}
|
||||
/// The fluid at a block and whether it is a source (`FluidState.isSource`).
|
||||
fn fluid_source(&self, b: [i32; 3]) -> (Fluid, bool) {
|
||||
let s = self.facts.get(self.world.block(b[0], b[1], b[2]));
|
||||
(s.fluid, s.fluid_level == 8 && !s.fluid_falling)
|
||||
}
|
||||
/// `getCollisionShape(...).max(Y, x, z)` for cached shapes.
|
||||
fn collision_top(&self, b: [i32; 3], fx: f64, fz: f64) -> f64 {
|
||||
let state = self.world.block(b[0], b[1], b[2]);
|
||||
@@ -1933,6 +1947,27 @@ impl ParticleEngine {
|
||||
}
|
||||
q
|
||||
}
|
||||
T::SulfurBubbles => {
|
||||
let mut q = Particle::at(r, ty, p);
|
||||
q.gravity = -0.04;
|
||||
q.friction = 0.85;
|
||||
q.set_size(0.02, 0.02);
|
||||
q.velocity[0] =
|
||||
v[0] * f64::from(0.2f32) + f64::from((r.next_float() * 2.0 - 1.0) * 0.02);
|
||||
// The provider passes `yAux` as `za`, so the Z speed comes from Y.
|
||||
q.velocity[2] =
|
||||
v[1] * f64::from(0.2f32) + f64::from((r.next_float() * 2.0 - 1.0) * 0.02);
|
||||
let size_start = 0.02 + 0.02 * r.next_float();
|
||||
q.size = size_start;
|
||||
q.lifetime = i32::MAX;
|
||||
q.behaviour = Behaviour::SulfurBubble {
|
||||
y_start: p[1],
|
||||
y_end: p[1] + 4.0 - 1.0,
|
||||
size_start,
|
||||
y_prev: p[1],
|
||||
};
|
||||
q
|
||||
}
|
||||
T::BubblePop => {
|
||||
let mut q = Particle::at(r, ty, p);
|
||||
q.lifetime = 4;
|
||||
@@ -3172,6 +3207,40 @@ impl ParticleEngine {
|
||||
p.removed = true;
|
||||
}
|
||||
}
|
||||
Behaviour::SulfurBubble {
|
||||
y_start,
|
||||
y_end,
|
||||
size_start,
|
||||
y_prev,
|
||||
} => {
|
||||
p.base_tick(level);
|
||||
let (fluid, source) = level.fluid_source(ParticleLevel::block_at(p.position));
|
||||
if !p.removed && !(fluid == Fluid::Water && source) {
|
||||
p.removed = true;
|
||||
}
|
||||
if !p.removed && p.position[1] >= y_end {
|
||||
p.removed = true;
|
||||
}
|
||||
if !p.removed && p.position[1] <= y_prev {
|
||||
p.removed = true;
|
||||
}
|
||||
// randomHorizontalWiggling, then a second, horizontal move.
|
||||
let wiggle = |r: &mut LegacyRandom| {
|
||||
let f = r.next_float() * 0.003;
|
||||
f64::from(if r.next_boolean() { f } else { -f }) * 0.5
|
||||
};
|
||||
p.velocity[0] += wiggle(&mut p.random);
|
||||
p.velocity[2] += wiggle(&mut p.random);
|
||||
p.move_by(level, [p.velocity[0], 0.0, p.velocity[2]]);
|
||||
let progress = ((p.position[1] - y_start) / (y_end - y_start)) as f32;
|
||||
p.size = size_start + progress * (0.15 - size_start);
|
||||
p.behaviour = Behaviour::SulfurBubble {
|
||||
y_start,
|
||||
y_end,
|
||||
size_start,
|
||||
y_prev: p.position[1],
|
||||
};
|
||||
}
|
||||
Behaviour::BubbleColumnUp => {
|
||||
p.base_tick(level);
|
||||
if !p.removed && level.fluid(ParticleLevel::block_at(p.position)).0 != Fluid::Water
|
||||
|
||||
@@ -48,7 +48,10 @@ pub fn sound_source(event: &str) -> usize {
|
||||
"zombified_piglin",
|
||||
"wither_skeleton",
|
||||
];
|
||||
if e.starts_with("music_disc.") {
|
||||
if e == "block.potent_sulfur.noxious_gas" {
|
||||
// PotentSulfurBlock.animateTick, its only caller, plays it as AMBIENT.
|
||||
index("ambient")
|
||||
} else if e.starts_with("music_disc.") {
|
||||
index("record")
|
||||
} else if e.starts_with("music.") {
|
||||
index("music")
|
||||
|
||||
+11
-4
@@ -48,8 +48,9 @@ import org.jspecify.annotations.Nullable;
|
||||
/** Builds each particle through its real registered ParticleProvider (the real
|
||||
* ParticleResources, sprite sets bound to stand-in sprites named after the
|
||||
* vanilla particles/*.json textures) in a stand-in ClientLevel (air, an
|
||||
* optional stone floor at y 63, no fluids), then ticks it and records its
|
||||
* state, the particles and sounds it asks the level for, tick by tick.
|
||||
* optional stone floor at y 63, optionally still water from y 64 to 67),
|
||||
* then ticks it and records its state, the particles and sounds it asks the
|
||||
* level for, tick by tick.
|
||||
*
|
||||
* Each vanilla Particle owns a RandomSource.create() random seeded from the
|
||||
* clock; its seed is recovered after construction (the SEED_UNIQUIFIER value
|
||||
@@ -67,13 +68,18 @@ public final class VanillaParticleProvidersOracle {
|
||||
static <T> T make(Class<T> type) throws Exception { return type.cast(allocate.invoke(unsafe, type)); }
|
||||
|
||||
static final class Level0 extends ClientLevel {
|
||||
boolean floor;
|
||||
boolean floor, water;
|
||||
List<String> events;
|
||||
Level0() { super(null, null, null, null, 0, 0, null, false, 0L, 0); }
|
||||
// Water: still water sources from y 64 to 67 (above the floor, below the open air).
|
||||
boolean wet(BlockPos p) { return water && p.getY() >= 64 && p.getY() <= 67; }
|
||||
@Override public BlockState getBlockState(BlockPos p) {
|
||||
if (wet(p)) return Blocks.WATER.defaultBlockState();
|
||||
return floor && p.getY() == 63 ? Blocks.STONE.defaultBlockState() : Blocks.AIR.defaultBlockState();
|
||||
}
|
||||
@Override public FluidState getFluidState(BlockPos p) { return Fluids.EMPTY.defaultFluidState(); }
|
||||
@Override public FluidState getFluidState(BlockPos p) {
|
||||
return wet(p) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState();
|
||||
}
|
||||
@Override public @Nullable BlockGetter getChunkForCollisions(int x, int z) { return this; }
|
||||
@Override public boolean hasChunkAt(BlockPos p) { return false; }
|
||||
@Override public void addParticle(ParticleOptions o, double x, double y, double z, double xd, double yd, double zd) {
|
||||
@@ -258,6 +264,7 @@ public final class VanillaParticleProvidersOracle {
|
||||
long seed = c.get("seed").getAsLong();
|
||||
RandomSource random = null;
|
||||
level.floor = c.get("floor").getAsBoolean();
|
||||
level.water = c.has("water") && c.get("water").getAsBoolean();
|
||||
level.events.clear();
|
||||
var p = c.getAsJsonArray("pos"); var v = c.getAsJsonArray("vel");
|
||||
Particle particle = null;
|
||||
|
||||
@@ -35,7 +35,7 @@ spore_blossom_air totem_of_undying underwater vault_connection warped_spore whit
|
||||
sweep_attack glow wax_on wax_off electric_spark scrape squid_ink glow_squid_ink item_slime item_snowball item_cobweb
|
||||
sulfur_cube_goo firefly trial_spawner_detection trial_spawner_detection_ominous trial_omen raid_omen ominous_spawning
|
||||
spit fishing dust_plume red_poplar_leaves orange_poplar_leaves yellow_poplar_leaves pause_mob_growth
|
||||
reset_mob_growth""".split()
|
||||
reset_mob_growth sulfur_bubbles""".split()
|
||||
|
||||
|
||||
def options(kind, rng):
|
||||
@@ -78,6 +78,12 @@ def cases(rng):
|
||||
for vel in velocities:
|
||||
yield dict(type=kind, options=options(kind, rng), pos=pos, vel=vel, floor=floor,
|
||||
seed=rng.randrange(-2**63, 2**63), ticks=80)
|
||||
# In still water (sources from y 64 to 67): the bubbles rise until they leave it.
|
||||
for kind in ['sulfur_bubbles', 'bubble', 'bubble_column_up']:
|
||||
for (pos, floor) in [([0.3125, 64.046875, -0.40625], True), ([-5.75, 66.59375, 3.125], False)]:
|
||||
for vel in velocities:
|
||||
yield dict(type=kind, options={}, pos=pos, vel=vel, floor=floor, water=True,
|
||||
seed=rng.randrange(-2**63, 2**63), ticks=80)
|
||||
|
||||
|
||||
def make_cases(build):
|
||||
@@ -215,10 +221,10 @@ def main():
|
||||
client_jar_sha256=lab.digest(jars['client'], 'sha256'), matched_output_lines=matched,
|
||||
output_sha256=lab.digest(build / 'rust.txt', 'sha256'), libm_tolerated_lines=tolerance,
|
||||
scope=('Real ParticleResources providers for every type Horizon implements, ticked in an air level with an optional '
|
||||
'stone floor: construction (provider, level, SpellParticle and particle-local random draws), per-tick '
|
||||
'stone floor and, for the bubbles, still water: construction (provider, level, SpellParticle and particle-local random draws), per-tick '
|
||||
'position, previous position, motion, age, lifetime, removal, onGround, quad size at partial 0 and 0.5, '
|
||||
'colour, alpha, roll, sprite, UVs and light at partial 0.5 (unloaded chunk), and the particles and sounds '
|
||||
'requested from the level. Fluids, block light, render layers/facing and the ParticleEngine group limits '
|
||||
'requested from the level. Flowing fluids, block light, render layers/facing and the ParticleEngine group limits '
|
||||
'are not exercised.')))
|
||||
print(f'{units:,} particle cases match the pinned client ({matched:,} output lines, {tolerance} within '
|
||||
f'the libm tolerance): {report}', flush=True)
|
||||
|
||||
Reference in New Issue
Block a user