Track shulker, bell, conduit, skull and pot animation state as vanilla ticks it
block_entity_anim ports ShulkerBoxBlockEntity.updateAnimation and its open-count events, BellBlockEntity triggerEvent/tick with resonation, ConduitBlockEntity.clientTick (shape check, hunting, rotation, nautilus particles), SkullBlockEntity.animation and DecoratedPotBlockEntity wobbles, and maps the state to the renderer's BlockAnim. tools/test_block_entity_anim_parity.py runs the real vanilla block entities on a stand-in client level (VanillaBlockEntityAnimOracle) against examples/block_entity_anim_fixture: 172/172 cases, 12720 ticked steps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
use horizon_client::{
|
||||
assets::Assets,
|
||||
block_entity_anim::{
|
||||
Bell, BellEntity, BlockEntityAnims, Conduit, ConduitTarget, DIRECTIONS, PotWobble,
|
||||
Shulker, ShulkerStatus, Skull, WobbleStyle, direction_index,
|
||||
Bell, BellEntity, BlockEntityAnims, Conduit, ConduitTarget, DIRECTIONS, PotWobble, Shulker,
|
||||
ShulkerStatus, Skull, WobbleStyle, direction_index,
|
||||
},
|
||||
blocks::{BlockFacts, Fluid},
|
||||
items::Items,
|
||||
@@ -126,7 +126,7 @@ fn main() -> Result<()> {
|
||||
// The neighbourhood as block states (conduits).
|
||||
let mut blocks: HashMap<[i32; 3], String> = HashMap::new();
|
||||
blocks.insert(pos, block.clone());
|
||||
let mut place = |blocks: &mut HashMap<[i32; 3], String>, set: &Value| {
|
||||
let place = |blocks: &mut HashMap<[i32; 3], String>, set: &Value| {
|
||||
for (k, v) in set.as_object().into_iter().flatten() {
|
||||
let o = offset(k);
|
||||
blocks.insert(
|
||||
@@ -154,7 +154,9 @@ fn main() -> Result<()> {
|
||||
let mut random = LegacyRandom::new(case["seed"].as_i64().unwrap_or(0));
|
||||
let name = block.split('[').next().unwrap_or_default().to_owned();
|
||||
let mut anims = BlockEntityAnims::default();
|
||||
let facing = prop(&block, "facing").and_then(direction_index).unwrap_or(1);
|
||||
let facing = prop(&block, "facing")
|
||||
.and_then(direction_index)
|
||||
.unwrap_or(1);
|
||||
let mut text = String::new();
|
||||
for step in case["steps"].as_array().into_iter().flatten() {
|
||||
let time = step["time"].as_i64().unwrap_or(0);
|
||||
@@ -251,10 +253,14 @@ fn main() -> Result<()> {
|
||||
} else if name == "minecraft:conduit" {
|
||||
let c = anims.conduits.entry(pos).or_insert_with(Conduit::default);
|
||||
let state_of = |p: [i32; 3]| -> Option<u32> {
|
||||
find_state(registry, blocks.get(&p).map_or("minecraft:air", String::as_str))
|
||||
find_state(
|
||||
registry,
|
||||
blocks.get(&p).map_or("minecraft:air", String::as_str),
|
||||
)
|
||||
};
|
||||
let is_water = |p: [i32; 3]| {
|
||||
state_of(p).is_some_and(|s| facts.get(BlockStateId(s)).fluid == Fluid::Water)
|
||||
};
|
||||
let is_water =
|
||||
|p: [i32; 3]| state_of(p).is_some_and(|s| facts.get(s).fluid == Fluid::Water);
|
||||
let is_frame = |p: [i32; 3]| {
|
||||
let spec = blocks.get(&p).map_or("minecraft:air", String::as_str);
|
||||
frames.contains(spec.split('[').next().unwrap_or_default())
|
||||
|
||||
@@ -136,12 +136,13 @@ public final class VanillaBlockEntityAnimOracle {
|
||||
@Override public net.minecraft.world.item.crafting.RecipeAccess recipeAccess(){throw new UnsupportedOperationException();}
|
||||
@Override public void sendBlockUpdated(net.minecraft.core.BlockPos p0,net.minecraft.world.level.block.state.BlockState p1,net.minecraft.world.level.block.state.BlockState p2,int p3){throw new UnsupportedOperationException();}
|
||||
@Override public void setRespawnData(net.minecraft.world.level.storage.LevelData.RespawnData p0){throw new UnsupportedOperationException();}
|
||||
@Override public net.minecraft.world.TickRateManager tickRateManager(){throw new UnsupportedOperationException();}
|
||||
}
|
||||
|
||||
static Mob mob(JsonObject e, World world) throws Exception {
|
||||
Mob m = make(Mob.class);
|
||||
m.living = !e.has("alive") || e.get("alive").getAsBoolean();
|
||||
put(m, Entity.class, "type", e.has("raider") && e.get("raider").getAsBoolean() ? EntityType.PILLAGER : EntityType.COW);
|
||||
put(m, Entity.class, "type", e.has("raider") && e.get("raider").getAsBoolean() ? EntityTypes.PILLAGER : EntityTypes.COW);
|
||||
var p = e.getAsJsonArray("pos");
|
||||
put(m, Entity.class, "position", new Vec3(p.get(0).getAsDouble(), p.get(1).getAsDouble(), p.get(2).getAsDouble()));
|
||||
if (e.has("removed") && e.get("removed").getAsBoolean()) put(m, Entity.class, "removalReason", Entity.RemovalReason.KILLED);
|
||||
|
||||
@@ -92,8 +92,9 @@ def cases():
|
||||
p = pos()
|
||||
entities = []
|
||||
for _ in range(rng.choice([0, 1, 2, 5, 12, 25])):
|
||||
# Multiples of 1/1024: serde_json parses other decimals approximately (1 ulp off).
|
||||
spread = rng.choice([10, 33, 50, 70])
|
||||
entities.append({'pos': [p[k] + 0.5 + rng.uniform(-spread, spread) for k in range(3)],
|
||||
entities.append({'pos': [p[k] + 0.5 + round(rng.uniform(-spread, spread) * 1024) / 1024 for k in range(3)],
|
||||
'raider': rng.random() < 0.5, 'alive': rng.random() < 0.85, 'removed': rng.random() < 0.08})
|
||||
steps = []
|
||||
start = rng.randint(-50, 10 ** 6)
|
||||
@@ -128,7 +129,7 @@ def cases():
|
||||
waterlogged = 'true' if rng.random() < 0.9 else 'false'
|
||||
extra = {'world': world, 'seed': rng.randint(0, 2 ** 40)}
|
||||
if rng.random() < 0.3:
|
||||
extra['target'] = {'pos': [rng.uniform(-8, 8) for _ in range(3)], 'width': round(rng.uniform(0.3, 2), 3),
|
||||
extra['target'] = {'pos': [round(rng.uniform(-8, 8) * 1024) / 1024 for _ in range(3)], 'width': round(rng.uniform(0.3, 2), 3),
|
||||
'height': round(rng.uniform(0.5, 3), 3), 'eye': round(rng.uniform(0.2, 2.5), 3)}
|
||||
add('conduit', f'minecraft:conduit[waterlogged={waterlogged}]', steps, **extra)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user