use super::tests::opts;
use super::*;
use crate::common::JoinGame;
use crate::interest::Interests;
use crate::version::ClientVersion;
use ghast_protocol::RawPacket;
use ghast_protocol::frame::{FrameDecoder, FrameEncoder};
use ghast_protocol::packet::PacketFilter;
use serde_json::Value;
use std::io::BufRead;
fn f64v(v: &Value) -> f64 {
f64::from_bits(u64::from_str_radix(v[1].as_str().unwrap(), 16).unwrap())
}
fn f32v(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v[1].as_str().unwrap(), 16).unwrap())
}
fn unhex(s: &str) -> bytes::Bytes {
(0..s.len())
.step_by(2)
.map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap())
.collect::<Vec<u8>>()
.into()
}
fn hex(b: &[u8]) -> String {
use std::fmt::Write as _;
let mut s = String::with_capacity(b.len() * 2);
for x in b {
let _ = write!(s, "{x:02x}");
}
s
}
fn wire_of<V: ClientVersion>(out: &[Outbound], wire: &mut V::Wire) -> Vec<(i64, String)> {
let mut enc = FrameEncoder::new();
for o in out {
V::write_play(&mut enc, o, wire).unwrap();
}
let bytes = enc.take();
let mut dec = FrameDecoder::new();
dec.push(&bytes);
let mut v = Vec::new();
while let Some(p) = dec.next_packet().unwrap() {
v.push((i64::from(p.id), hex(&p.body)));
}
v
}
fn wire_want(rec: &Value) -> Vec<(i64, String)> {
rec["wire"]
.as_array()
.unwrap()
.iter()
.map(|p| (p[0].as_i64().unwrap(), p[1].as_str().unwrap().to_owned()))
.collect()
}
struct Hands {
controls: Controls,
buttons: Buttons,
hotbar: Option<u8>,
}
impl Behavior for Hands {
fn name(&self) -> &str {
"combat-replay"
}
fn tick(&mut self, ctx: &mut TickContext<'_>) {
if let Some(s) = self.hotbar.take() {
ctx.select_slot(s);
}
ctx.set_controls(self.controls);
ctx.set_buttons(self.buttons);
}
}
fn feed<V: ClientVersion, S: Sim>(
e: &mut Engine<S>,
filter: &PacketFilter,
wire: &mut V::Wire,
raw: &RawPacket,
) {
if !filter.contains(raw.id) {
return;
}
e.sim.world_packet(raw).unwrap();
if let Some(o) = V::inventory_packet(e.inventory_mut(), raw).unwrap() {
e.outbound().push(Outbound::Inventory(o));
}
if let Some(p) = V::decode_play(raw, wire).unwrap() {
e.handle(p);
}
}
fn filter_of<V: ClientVersion, S: Sim>(e: &mut Engine<S>, metadata: bool) -> PacketFilter {
let interests = if metadata {
Interests::ENTITY_TRACKING | Interests::ENTITIES
} else {
Interests::ENTITY_TRACKING
};
let tracked = std::env::var_os("GHAST_COMBAT_UNTRACKED").is_none();
e.sim
.set_entities(crate::client::entity_config(interests, V::GAME.caps()).filter(|_| tracked));
let mut filter = V::play_filter(interests);
for id in e.sim.entity_packet_ids() {
filter.insert(id);
}
for id in e.sim.world_packet_ids() {
filter.insert(id);
}
for &id in V::inventory_packet_ids(e.inventory_mut()) {
filter.insert(id);
}
filter
}
fn game_mode(setup: &Value) -> GameMode {
match setup["game_mode"].as_str().unwrap() {
"spectator" => GameMode::Spectator,
"creative" => GameMode::Creative,
"adventure" => GameMode::Adventure,
_ => GameMode::Survival,
}
}
fn abilities(mode: GameMode) -> crate::common::Abilities {
let flags = match mode {
GameMode::Creative => 0x01 | 0x04 | 0x08,
GameMode::Spectator => 0x01 | 0x02 | 0x04,
_ => 0,
};
crate::common::Abilities {
flags,
flying_speed: 0.05,
walking_speed: 0.1,
}
}
#[derive(Default, Debug)]
struct Summary {
cases: usize,
ticks: usize,
packets: usize,
failed: Vec<String>,
flagged: Vec<(String, usize)>,
}
#[derive(Clone, Copy)]
struct PistonIds {
action: i32,
change: i32,
time: Option<i32>,
}
fn piston_packet(ev: &Value, ids: PistonIds) -> RawPacket {
fn varint(b: &mut Vec<u8>, v: i32) {
let mut u = v as u32;
loop {
let x = (u & 0x7f) as u8;
u >>= 7;
if u == 0 {
b.push(x);
return;
}
b.push(x | 0x80);
}
}
let mut b = Vec::new();
let p = &ev["pos"];
let c = |k: usize| p[k].as_i64().unwrap();
let v = ((c(0) & 0x3FF_FFFF) << 38) | ((c(1) & 0xFFF) << 26) | (c(2) & 0x3FF_FFFF);
b.extend_from_slice(&v.to_be_bytes());
let n = |k: &str| ev[k].as_i64().unwrap() as i32;
let id = if ev["type"] == "block_action" {
b.push(n("action") as u8);
b.push(n("data") as u8);
varint(&mut b, n("block"));
ids.action
} else {
varint(&mut b, n("raw"));
ids.change
};
RawPacket::new(id, bytes::Bytes::from(b))
}
fn replay<V: ClientVersion, S: Sim>(
path: &std::path::Path,
mut setup: impl FnMut(&Value, &Value) -> Engine<S>,
vel: impl Fn(&Engine<S>) -> [f64; 3],
mut wire: V::Wire,
pistons: Option<PistonIds>,
) -> Summary
where
V::Wire: Clone,
{
let f = std::fs::File::open(path).unwrap_or_else(|e| panic!("{}: {e}", path.display()));
let mut lines = std::io::BufReader::new(flate2::read::GzDecoder::new(f))
.lines()
.map(|l| serde_json::from_str::<Value>(&l.unwrap()).unwrap())
.peekable();
let mut sum = Summary::default();
let fresh = wire.clone();
let only = std::env::var("GHAST_COMBAT_CASE").ok();
while let Some(sc) = lines.next() {
let name = sc["name"].as_str().unwrap().to_owned();
let mut ticks = Vec::new();
while let Some(t) = lines.next_if(|l| l["type"] == "tick") {
ticks.push(t);
}
if only.as_ref().is_some_and(|o| *o != name) {
continue;
}
sum.cases += 1;
wire = fresh.clone();
let mut e = setup(&sc, &ticks[0]);
let state = ["_sheared", "_red", "_baby", "_saddled", "_tamed"]
.iter()
.any(|k| name.starts_with("mob_") && name.ends_with(k))
|| name.contains("_shulker_");
let filter = filter_of::<V, S>(&mut e, state);
let mode = game_mode(&sc["setup"]);
if mode != GameMode::Survival {
e.handle(Inbound::Abilities(abilities(mode)));
}
for p in sc["setup"]["ext"]["packets"].as_array().unwrap() {
let raw = RawPacket::new(p[0].as_i64().unwrap() as i32, unhex(p[1].as_str().unwrap()));
feed::<V, S>(&mut e, &filter, &mut wire, &raw);
}
e.core.ready = true;
e.outbound().clear();
let t0 = Instant::now();
for (k, rec) in ticks.iter().enumerate().skip(1) {
let input = &rec["input"];
let mut hotbar = None;
for ev in input["events"].as_array().into_iter().flatten() {
match ev["type"].as_str().unwrap() {
"wire" => {
let raw = RawPacket::new(
ev["id"].as_i64().unwrap() as i32,
unhex(ev["hex"].as_str().unwrap()),
);
feed::<V, S>(&mut e, &filter, &mut wire, &raw);
}
"hotbar" => hotbar = Some(ev["slot"].as_u64().unwrap() as u8),
"block_action" | "block_change" if pistons.is_some() => {
let raw = piston_packet(ev, pistons.unwrap());
feed::<V, S>(&mut e, &filter, &mut wire, &raw);
}
"world_time" if pistons.is_some_and(|p| p.time.is_some()) => {
let t = ev["time"].as_i64().unwrap();
let mut b = t.to_be_bytes().to_vec();
b.extend_from_slice(&t.to_be_bytes());
let raw = RawPacket::new(pistons.unwrap().time.unwrap(), b.into());
feed::<V, S>(&mut e, &filter, &mut wire, &raw);
}
other => panic!("{name}: event {other}"),
}
}
let keys = input["keys"].as_str().unwrap();
let has = |k: &str| keys.split(',').any(|n| n == k);
let mut b = Hands {
controls: Controls {
forward: has("forward"),
back: has("back"),
left: has("left"),
right: has("right"),
jump: has("jump"),
sneak: has("sneak"),
sprint: has("sprint"),
},
buttons: Buttons {
left: has("attack"),
right: has("use"),
},
hotbar,
};
e.core.forced_look = Some((f32v(&input["yaw"]), f32v(&input["pitch"])));
e.note_inbound(t0);
e.tick(&mut b, t0);
if e.sim.piston_uncertain() {
sum.flagged.push((name.clone(), k));
break;
}
let out = std::mem::take(e.outbound());
let got = wire_of::<V>(&out, &mut wire);
let want = wire_want(rec);
if only.is_some() {
eprintln!(
"t{k} keys {keys} ours {out:?}\n got {got:?}\n want {want:?}\n swing {} speed {} using {} food {} vel {:?} oracle {}",
e.core.hands.ticks_since_swing,
e.core.attack_speed,
e.core.hands.using_item(),
e.core.health.food,
vel(&e),
rec["combat"]
);
}
if got != want {
sum.failed.push(format!(
"{name} tick {k}: packets {got:?} want {want:?} (ours {out:?}; oracle {})",
rec["combat"]
));
break;
}
let v = vel(&e);
let want_v: Vec<u64> = (0..3)
.map(|i| f64v(&rec["state"]["vel"][i]).to_bits())
.collect();
if v.iter().map(|x| x.to_bits()).collect::<Vec<_>>() != want_v {
sum.failed.push(format!(
"{name} tick {k}: velocity {v:?} want {:?}",
want_v
.iter()
.map(|b| f64::from_bits(*b))
.collect::<Vec<_>>()
));
break;
}
let inv_version = e.core.inv.version();
let mine = |st: Option<&ghast_inventory::Stack>| {
st.map(|st| {
let damage = if inv_version == ghast_inventory::Version::V1_16_5 {
i64::from(st.damage_value(inv_version))
} else {
i64::from(st.damage())
};
(i64::from(st.id()), i64::from(st.count()), damage)
})
};
let theirs = |v: &Value| {
v.as_array().map(|a| {
(
a[0].as_i64().unwrap(),
a[1].as_i64().unwrap(),
a[2].as_i64().unwrap(),
)
})
};
let hands = (mine(e.core.inv.held()), mine(e.core.inv.offhand()));
let want_hands = (
theirs(&rec["combat"]["held"]),
theirs(&rec["combat"]["off"]),
);
if rec["combat"].is_object() && hands != want_hands {
sum.failed.push(format!(
"{name} tick {k}: hands {hands:?} want {want_hands:?}"
));
break;
}
if let Some(d) = entities_differ(&e, rec) {
sum.failed.push(format!("{name} tick {k}: {d}"));
break;
}
if let Some(d) = piston_others_differ(&e, rec) {
sum.failed.push(format!("{name} tick {k}: {d}"));
break;
}
sum.packets += want.len();
sum.ticks += 1;
}
}
sum
}
fn entities_differ<S: Sim>(e: &Engine<S>, rec: &Value) -> Option<String> {
let list = rec["combat"]["entities"].as_array()?;
let view = Some(e.sim.entities()?);
for x in list {
if x[4].as_bool() == Some(true) {
continue;
}
let id = x[0].as_i64().unwrap() as i32;
let want = [f64v(&x[1]), f64v(&x[2]), f64v(&x[3])];
match view.and_then(|v| v.get(id)) {
Some(en) => {
let got = en.drawn_position();
if got.map(f64::to_bits) != want.map(f64::to_bits) {
return Some(format!(
"entity {id} ({:?}) drawn at {got:?} want {want:?}",
en.entity_type()
));
}
}
None => return Some(format!("entity {id} not tracked (want {want:?})")),
}
}
None
}
fn piston_others_differ<S: Sim>(e: &Engine<S>, rec: &Value) -> Option<String> {
let list = rec["pistons"]["others"].as_array()?;
let view = e.sim.entities()?;
for x in list {
let id = x[0].as_i64().unwrap() as i32;
let want: Vec<u64> = (1..7).map(|k| f64v(&x[k]).to_bits()).collect();
let Some(en) = view.get(id) else {
return Some(format!("entity {id} not tracked"));
};
if matches!(
en.entity_type(),
ghast_entity::EntityType::ExperienceOrb
| ghast_entity::EntityType::LegacyObject(
2 | 60 | 61 | 62 | 64 | 65 | 66 | 72 | 73 | 75 | 76 | 90
)
) {
continue;
}
let got: Vec<u64> = en
.drawn_bounding_box()
.map(|b| b.iter().map(|v| v.to_bits()).collect())
.unwrap_or_default();
let state = (en.drawn_on_ground(), en.drawn_in_web());
let want_state = (x[7].as_bool().unwrap(), x[8].as_bool().unwrap());
let section = en.search_order().map(|o| [o.0, o.2, o.1]);
let want_section = [
x[9].as_i64().unwrap() as i32,
x[10].as_i64().unwrap() as i32,
x[11].as_i64().unwrap() as i32,
];
if got != want || state != want_state || section.is_some_and(|s| s != want_section) {
let f = |v: &[u64]| v.iter().map(|b| f64::from_bits(*b)).collect::<Vec<_>>();
return Some(format!(
"entity {id} ({:?}) box {:?} ground/web {state:?} section {section:?}, want {:?} {want_state:?} {want_section:?}",
en.entity_type(),
f(&got),
f(&want)
));
}
}
None
}
fn golden(version: &str, file: &str) -> std::path::PathBuf {
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../tests/golden")
.join(version)
.join(file)
}
fn check(what: &str, s: &Summary, min_cases: usize) {
eprintln!(
"{what}: {} cases, {} ticks, {} packets identical, {} cases differ, {} flagged",
s.cases,
s.ticks,
s.packets,
s.failed.len(),
s.flagged.len()
);
let hand: Vec<_> = s
.flagged
.iter()
.filter(|(n, _)| !n.starts_with("fuzz_"))
.collect();
if !hand.is_empty() {
eprintln!("{what}: flagged hand cases {hand:?}");
}
assert!(
s.failed.is_empty(),
"{what}: {} of {} cases differ:\n{}",
s.failed.len(),
s.cases,
s.failed.join("\n")
);
assert!(s.cases >= min_cases, "{what}: {} cases", s.cases);
}
mod v1_8 {
use super::*;
use crate::phys_golden as golden;
use crate::sim::Sim18;
use ghast_protocol::v1_8::V1_8;
fn login_packet(mode: GameMode) -> RawPacket {
let gm = match mode {
GameMode::Survival => 0u8,
GameMode::Creative => 1,
GameMode::Adventure => 2,
GameMode::Spectator => 3,
GameMode::Other(m) => m,
};
let mut b = vec![0, 0, 0, 1, gm, 0, 1, 20, 4];
b.extend_from_slice(b"flat");
b.push(0);
RawPacket::new(
ghast_protocol::v1_8::play::clientbound::id::LOGIN,
bytes::Bytes::from(b),
)
}
fn setup(sc: &Value, t0: &Value) -> Engine<Sim18> {
let setup = &sc["setup"];
let mode = game_mode(setup);
let mut e = Engine::new(opts(GameVersion::V1_8_9), Sim18::new());
e.handle(Inbound::JoinGame(JoinGame {
entity_id: 1,
game_mode: mode,
dimension: "0".into(),
hardcore: false,
dimension_nbt: None,
respawn_screen: true,
}));
e.sim.world_packet(&login_packet(mode)).unwrap();
for r in sc["loaded_chunks"].as_array().unwrap() {
let r: Vec<i32> = (0..4).map(|k| r[k].as_i64().unwrap() as i32).collect();
for x in r[0]..=r[2] {
for z in r[1]..=r[3] {
e.sim
.world_packet(&crate::sim::test_chunks::v1_8(x, z))
.unwrap();
}
}
for x in r[0] * 16..r[2] * 16 + 16 {
for z in r[1] * 16..r[3] * 16 + 16 {
e.sim.predict_air(x, 63, z);
}
}
}
for fill in sc["fills"].as_array().unwrap() {
let v: Vec<i64> = (0..8).map(|k| fill[k].as_i64().unwrap()).collect();
let st = ghast_data::v1_8::BlockState::from_raw_vanilla(
((v[6] as u16) << 4) | (v[7] as u16 & 15),
);
for x in v[0]..=v[3] {
for y in v[1]..=v[4] {
for z in v[2]..=v[5] {
e.sim.test_set_block(x as i32, y as i32, z as i32, st);
}
}
}
}
e.handle(Inbound::Teleport(crate::common::Teleport {
x: f64v(&setup["pos"][0]),
y: f64v(&setup["pos"][1]),
z: f64v(&setup["pos"][2]),
yaw: f32v(&setup["yaw"]),
pitch: f32v(&setup["pitch"]),
teleport_id: None,
..Default::default()
}));
let p = golden::player_of(sc, t0);
let mut pose = e.core.pose;
e.sim.test_set_player(&mut pose, p);
e.core.pose = pose;
e
}
fn run(file: &str) -> Summary {
super::replay::<V1_8, Sim18>(
&super::golden("1.8.9", file),
setup,
|e| e.sim.test_player().vel,
(),
None,
)
}
#[test]
fn piston_entities_match_the_oracle_1_8_9() {
use ghast_protocol::v1_8::play::clientbound::id;
let s = super::replay::<V1_8, Sim18>(
&super::golden("1.8.9", "piston_entities.jsonl.gz"),
setup,
|e| e.sim.test_player().vel,
(),
Some(PistonIds {
action: id::BLOCK_ACTION,
change: id::BLOCK_CHANGE,
time: None,
}),
);
check("1.8.9 piston entities", &s, 80);
let flagged: Vec<&str> = s.flagged.iter().map(|f| f.0.as_str()).collect();
for n in [
"piston_entity_flagged_boat",
"piston_entity_flagged_minecart",
"piston_entity_flagged_rider",
] {
assert!(flagged.contains(&n), "{n} is not flagged");
}
}
#[test]
#[ignore = "needs the oracle cache"]
fn piston_entities_cache_1_8_9() {
use ghast_protocol::v1_8::play::clientbound::id;
let dir = std::env::var_os("GHAST_PISTON_ENTITIES_DIR").map_or_else(
|| {
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../oracle/cache/1.8.9/fuzz-piston-entities")
},
std::path::PathBuf::from,
);
let mut files: Vec<_> = std::fs::read_dir(&dir)
.unwrap()
.filter_map(|e| e.ok().map(|e| e.path()))
.filter(|p| p.to_string_lossy().ends_with(".jsonl.gz"))
.collect();
files.sort();
let mut all = Summary::default();
for f in files {
let s = super::replay::<V1_8, Sim18>(
&f,
setup,
|e| e.sim.test_player().vel,
(),
Some(PistonIds {
action: id::BLOCK_ACTION,
change: id::BLOCK_CHANGE,
time: None,
}),
);
all.cases += s.cases;
all.ticks += s.ticks;
all.packets += s.packets;
all.failed.extend(s.failed);
all.flagged.extend(s.flagged);
}
check("1.8.9 piston entities (cache)", &all, 1000);
}
#[test]
fn attacks_match_the_oracle_1_8_9() {
check("1.8.9 attacks", &run("attacks.jsonl.gz"), 80);
}
#[test]
fn item_use_matches_the_oracle_1_8_9() {
check("1.8.9 item use", &run("item_use.jsonl.gz"), 80);
}
}
mod v1_12 {
use super::*;
use crate::phys_golden::v112 as golden;
use crate::sim::Sim12;
use ghast_protocol::v1_12_2::V1_12_2;
fn login_packet(mode: GameMode) -> RawPacket {
let gm = match mode {
GameMode::Survival => 0u8,
GameMode::Creative => 1,
GameMode::Adventure => 2,
GameMode::Spectator => 3,
GameMode::Other(m) => m,
};
let mut b = vec![0, 0, 0, 1, gm, 0, 0, 0, 0, 1, 20, 4];
b.extend_from_slice(b"flat");
b.push(0);
RawPacket::new(
ghast_protocol::v1_12_2::play::clientbound::id::LOGIN,
bytes::Bytes::from(b),
)
}
fn setup(sc: &Value, t0: &Value) -> Engine<Sim12> {
let setup = &sc["setup"];
let mode = game_mode(setup);
let mut sim = Sim12::new();
sim.test_set_profile_name("oracle");
let mut e = Engine::new(opts(GameVersion::V1_12_2), sim);
e.handle(Inbound::JoinGame(JoinGame {
entity_id: 1,
game_mode: mode,
dimension: "0".into(),
hardcore: false,
dimension_nbt: None,
respawn_screen: true,
}));
e.sim.world_packet(&login_packet(mode)).unwrap();
for r in sc["loaded_chunks"].as_array().unwrap() {
let r: Vec<i32> = (0..4).map(|k| r[k].as_i64().unwrap() as i32).collect();
for x in r[0]..=r[2] {
for z in r[1]..=r[3] {
e.sim
.world_packet(&crate::sim::test_chunks::v1_12_2(x, z))
.unwrap();
}
}
for x in r[0] * 16..r[2] * 16 + 16 {
for z in r[1] * 16..r[3] * 16 + 16 {
e.sim.predict_air(x, 63, z);
}
}
}
for fill in sc["fills"].as_array().unwrap() {
let v: Vec<i64> = (0..8).map(|k| fill[k].as_i64().unwrap()).collect();
let st = ghast_data::v1_12::BlockState::from_raw_vanilla(
((v[6] as u16) << 4) | (v[7] as u16 & 15),
);
for x in v[0]..=v[3] {
for y in v[1]..=v[4] {
for z in v[2]..=v[5] {
e.sim.test_set_block(x as i32, y as i32, z as i32, st);
}
}
}
}
e.handle(Inbound::Teleport(crate::common::Teleport {
x: f64v(&setup["pos"][0]),
y: f64v(&setup["pos"][1]),
z: f64v(&setup["pos"][2]),
yaw: f32v(&setup["yaw"]),
pitch: f32v(&setup["pitch"]),
teleport_id: None,
..Default::default()
}));
let mut p = golden::player_of(sc, t0);
p.added_to_chunk = true;
e.sim.test_set_player(p);
e
}
fn run(file: &str) -> Summary {
super::replay::<V1_12_2, Sim12>(
&super::golden("1.12.2", file),
setup,
|e| e.sim.test_player().vel,
crate::version::Wire1_12::default(),
None,
)
}
fn run_pistons(path: &std::path::Path) -> Summary {
use ghast_protocol::v1_12_2::play::clientbound::id;
super::replay::<V1_12_2, Sim12>(
path,
setup,
|e| e.sim.test_player().vel,
crate::version::Wire1_12::default(),
Some(PistonIds {
action: id::BLOCK_ACTION,
change: id::BLOCK_CHANGE,
time: Some(id::UPDATE_TIME),
}),
)
}
#[test]
fn piston_entities_match_the_oracle_1_12_2() {
let s = run_pistons(&super::golden("1.12.2", "piston_entities.jsonl.gz"));
check("1.12.2 piston entities", &s, 80);
let flagged: Vec<&str> = s.flagged.iter().map(|f| f.0.as_str()).collect();
assert_eq!(flagged, ["piston_entity_flagged_rider"]);
assert!(s.ticks > 4000, "{} ticks compared", s.ticks);
}
#[test]
#[ignore = "needs the oracle cache"]
fn piston_entities_cache_1_12_2() {
let dir = std::env::var_os("GHAST_PISTON_ENTITIES_DIR").map_or_else(
|| {
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../oracle/cache/1.12.2/fuzz-piston-entities")
},
std::path::PathBuf::from,
);
let mut files: Vec<_> = std::fs::read_dir(&dir)
.unwrap()
.filter_map(|e| e.ok().map(|e| e.path()))
.filter(|p| p.to_string_lossy().ends_with(".jsonl.gz"))
.collect();
files.sort();
let mut all = Summary::default();
for f in files {
let s = run_pistons(&f);
all.cases += s.cases;
all.ticks += s.ticks;
all.packets += s.packets;
all.failed.extend(s.failed);
all.flagged.extend(s.flagged);
}
check("1.12.2 piston entities (cache)", &all, 1000);
}
#[test]
fn attacks_match_the_oracle_1_12_2() {
check("1.12.2 attacks", &run("attacks.jsonl.gz"), 80);
}
#[test]
fn item_use_matches_the_oracle_1_12_2() {
check("1.12.2 item use", &run("item_use.jsonl.gz"), 80);
}
}
mod v1_16_5 {
use super::*;
use crate::phys_golden::v116 as golden;
use crate::sim::Sim16;
use ghast_protocol::v1_16_5::V1_16_5;
fn login_packet(mode: GameMode) -> RawPacket {
let gm = match mode {
GameMode::Survival => 0u8,
GameMode::Creative => 1,
GameMode::Adventure => 2,
GameMode::Spectator => 3,
GameMode::Other(m) => m,
};
let name = b"minecraft:overworld";
let mut b = vec![0, 0, 0, 1, 0, gm, 0xff, 1, name.len() as u8];
b.extend_from_slice(name);
b.extend_from_slice(&[10, 0, 0, 0]);
b.extend_from_slice(&[10, 0, 0, 1, 0, 9]);
b.extend_from_slice(b"ultrawarm");
b.push(0);
b.extend_from_slice(&[1, 0, 12]);
b.extend_from_slice(b"has_skylight");
b.push(1);
b.push(0);
b.push(name.len() as u8);
b.extend_from_slice(name);
b.extend_from_slice(&[0; 8]);
b.extend_from_slice(&[20, 10, 0, 1, 0, 0]);
RawPacket::new(
ghast_protocol::v1_16_5::play::clientbound::id::LOGIN,
bytes::Bytes::from(b),
)
}
fn setup(sc: &Value, t0: &Value) -> Engine<Sim16> {
let setup = &sc["setup"];
let mode = game_mode(setup);
let mut sim = Sim16::new();
sim.test_set_profile_name("oracle");
let mut e = Engine::new(opts(GameVersion::V1_16_5), sim);
e.handle(Inbound::JoinGame(JoinGame {
entity_id: 1,
game_mode: mode,
dimension: "0".into(),
hardcore: false,
dimension_nbt: None,
respawn_screen: true,
}));
e.sim.world_packet(&login_packet(mode)).unwrap();
for r in sc["loaded_chunks"].as_array().unwrap() {
let r: Vec<i32> = (0..4).map(|k| r[k].as_i64().unwrap() as i32).collect();
for x in r[0]..=r[2] {
for z in r[1]..=r[3] {
e.sim
.world_packet(&crate::sim::test_chunks::v1_16_5(x, z))
.unwrap();
}
}
}
for fill in sc["fills"].as_array().unwrap() {
let v: Vec<i64> = (0..7).map(|k| fill[k].as_i64().unwrap()).collect();
let st = ghast_data::v1_16_5::BlockState::from_id(v[6] as u16).unwrap();
for x in v[0]..=v[3] {
for y in v[1]..=v[4] {
for z in v[2]..=v[5] {
e.sim.test_set_block(x as i32, y as i32, z as i32, st);
}
}
}
}
e.handle(Inbound::Teleport(crate::common::Teleport {
x: f64v(&setup["pos"][0]),
y: f64v(&setup["pos"][1]),
z: f64v(&setup["pos"][2]),
yaw: f32v(&setup["yaw"]),
pitch: f32v(&setup["pitch"]),
teleport_id: None,
..Default::default()
}));
let p = golden::player_of(sc, t0);
e.core.pose.pos = Vec3::new(p.pos[0], p.pos[1], p.pos[2]);
e.core.pose.yaw = p.yaw;
e.core.pose.pitch = p.pitch;
e.sim.test_set_player(p);
e
}
fn run(file: &str) -> Summary {
super::replay::<V1_16_5, Sim16>(
&super::golden("1.16.5", file),
setup,
|e| e.sim.test_player().vel,
(),
None,
)
}
#[test]
fn attacks_match_the_oracle_1_16_5() {
check("1.16.5 attacks", &run("attacks.jsonl.gz"), 80);
}
#[test]
fn item_use_matches_the_oracle_1_16_5() {
check("1.16.5 item use", &run("item_use.jsonl.gz"), 80);
}
}