use super::Rules;
use super::data::BlockState;
use ghast_physics::modern::{self, AttributeKind, ModifierId};
use ghast_protocol::{BlockPos, RawPacket};
use crate::common::{Abilities, AttributeUpdate, Controls, Outbound, Pose, Teleport, Vec3};
use crate::hands::{BlockQuery, HeldItem};
use crate::sim::shared::aabb;
use crate::sim::*;
use super::{
GAME, SLEEP_ON_BED_ONLY, TEAM_LAYOUT, data, effects, entity, exact_dig, inv,
inv_trident_strength, pick, pistons, proto,
};
mod blocks;
mod elytra;
mod entities;
mod fishing;
mod hooks;
mod nonliving;
mod piston;
mod records;
#[cfg(test)]
mod tests;
mod vehicles;
pub(crate) struct ModernSim {
world: super::world::World,
player: modern::PlayerState,
packets: ghast_physics::Packets,
piston_step: bool,
send_due: bool,
updates: BlockUpdates,
mining: [modern::Attribute; 3],
conduit_power: Option<i32>,
ranges: [modern::Attribute; 2],
old_pos: [f64; 3],
entities: Option<super::entity::Tracker>,
session: SessionPackets,
gate: modern::LoadGate,
use_effects: Option<(bool, f32)>,
ext: modern::PlayerExt,
own: OwnEntity,
rain_level: f32,
ext_active: bool,
riptide: [f32; 2],
around: Around,
teams: Option<Box<crate::sim::teams::Teams>>,
profile_name: Box<str>,
riding: Option<Riding>,
vehicles: Option<Box<super::entity::Tracker>>,
parked: Option<Parked>,
left_mount: Option<Box<modern::Mount>>,
reply: Option<Outbound>,
force_step: ForceStepPosition,
rec: Option<Box<crate::record::Recorder>>,
movement_attributes: bool,
filter_dirty: bool,
entity_push: bool,
predictions: crate::sim::predict::Sequenced<BlockState>,
snapped: bool,
server_flags: Option<u8>,
absorption: f32,
absorption_dirty: bool,
sleep: Option<Option<ghast_protocol::BlockPos>>,
pistons: super::pistons::Pistons,
piston_edits: super::pistons::Edits,
piston_uncertain_at: Option<i32>,
piston_clock: (i64, i32),
piston_carry: Vec<(i32, super::pistons::PistonCarry)>,
player_section: Option<((i32, u64), (u64, u64))>,
section_moves: Vec<SectionMove>,
section_moves_n: u64,
nonliving: Option<Box<nonliving::NonLiving>>,
fishing: crate::fishing::Fishing,
}
type SectionMove = (i32, (i32, u64), (u64, u64));
#[derive(Debug)]
enum Riding {
Boat { id: i32, boat: Box<modern::Boat> },
Seat { id: i32 },
Mount {
id: i32,
mount: Box<modern::Mount>,
tracked: Option<[f64; 3]>,
},
}
impl Riding {
fn id(&self) -> i32 {
match self {
Riding::Boat { id, .. } | Riding::Seat { id } | Riding::Mount { id, .. } => *id,
}
}
}
#[derive(Debug, Clone, Copy)]
struct Parked {
id: i32,
pos: [f64; 3],
bb: [f64; 6],
tracked: Option<[f64; 3]>,
living: bool,
}
impl Parked {
fn of(this: Option<&Parked>, e: &ghast_entity::Entity) -> Option<([f64; 3], [f64; 6])> {
let p = this?;
(p.id == e.id() && p.tracked == Some(e.position())).then_some((p.pos, p.bb))
}
}
fn vehicle_kind(name: &str) -> Option<VehicleKind> {
if let Some(k) = modern::BoatKind::from_entity_name(name) {
Some(VehicleKind::Boat(k))
} else if let Some(k) = modern::MountKind::from_entity_name(name) {
Some(VehicleKind::Mount(k))
} else if name.ends_with("minecart") {
Some(VehicleKind::Cart)
} else {
None
}
}
#[derive(Debug, Clone, Copy)]
enum VehicleKind {
Boat(modern::BoatKind),
Mount(modern::MountKind),
Cart,
}
#[derive(Debug, Default)]
struct Around {
boxes: Vec<ghast_physics::math::Aabb>,
pushers: Vec<(i64, modern::Pusher, Option<i32>)>,
player_ticked: bool,
pre: Vec<i32>,
}
const COLLIDES: u8 = 1;
const PUSH_LIVING: u8 = 2;
const PUSH_BOAT: u8 = 4;
fn entity_bits(e: &ghast_entity::Entity) -> u8 {
static BITS: std::sync::OnceLock<Box<[u8]>> = std::sync::OnceLock::new();
let bits = BITS.get_or_init(|| {
let types = super::data::entity_types();
let mut v = vec![
0u8;
types
.iter()
.map(|t| usize::from(t.id) + 1)
.max()
.unwrap_or(0)
];
for t in types {
let mut b = 0;
if super::collides(t.name) {
b |= COLLIDES;
}
match super::push_kind(t.name, t.is_living()) {
Some(modern::PushKind::Living) => b |= PUSH_LIVING,
Some(modern::PushKind::Boat) => b |= PUSH_BOAT,
_ => {}
}
v[usize::from(t.id)] = b;
}
v.into_boxed_slice()
});
super::entity::entity_type(e).map_or(0, |t| bits.get(usize::from(t.id)).copied().unwrap_or(0))
}
#[inline(never)]
#[allow(clippy::too_many_arguments)]
fn collect_colliders(
t: Option<&super::entity::Tracker>,
parked: Option<&Parked>,
p: &modern::PlayerState,
vehicle: Option<i32>,
boxes: &mut Vec<ghast_physics::math::Aabb>,
boat_boxes: &mut Vec<ghast_physics::math::Aabb>,
mounts: &[Mount],
) {
boxes.clear();
boat_boxes.clear();
let extra = if vehicle.is_some() { 4.0 } else { 3.0 };
let reach = |v: f64| v.abs() + extra;
let (rx, ry, rz) = (reach(p.vel[0]), reach(p.vel[1]), reach(p.vel[2]));
let mut found: Vec<((i32, u64), [f64; 6], bool)> = Vec::new();
if let Some(k) = parked
&& t.is_none_or(|t| t.get(k.id).is_none())
{
found.push((section_order(k.pos), k.bb, !k.living));
}
let ghast_ty = EntityIds::get().happy_ghast;
let ghasts = mounts.iter().any(|m| m.ty == ghast_ty);
let on_ghast =
ghasts && vehicle.is_some_and(|v| mounts.iter().any(|m| m.id == v && m.ty == ghast_ty));
for e in t.into_iter().flat_map(|t| t.iter()) {
let bits = entity_bits(e);
let living =
vehicle.is_some() && super::entity::entity_type(e).is_some_and(|t| t.is_living());
let ghast = if ghasts {
mounts
.iter()
.find(|m| m.id == e.id() && m.ty == ghast_ty && !m.baby)
} else {
None
};
if bits & COLLIDES == 0 && !living && ghast.is_none() {
continue;
}
if Some(e.id()) == vehicle {
continue;
}
let Some((pos, b)) = Parked::of(parked, e).or_else(|| entity_box(e)) else {
continue;
};
if b[3] < p.bb.min_x - rx
|| b[0] > p.bb.max_x + rx
|| b[4] < p.bb.min_y - ry
|| b[1] > p.bb.max_y + ry
|| b[5] < p.bb.min_z - rz
|| b[2] > p.bb.max_z + rz
{
continue;
}
if !super::entity::alive(e) {
continue;
}
let collides = bits & COLLIDES != 0
|| ghast.is_some_and(|g| {
if vehicle.is_some() {
g.stays_still || on_ghast && !e.passengers().is_empty()
} else {
modern::happy_ghast_collides(g.stays_still, &aabb(b), p.pos[1])
}
});
if !collides && !living {
continue;
}
found.push((section_order(pos), b, collides));
}
found.sort_by_key(|f| f.0);
for (_, b, collides) in found {
if collides {
boxes.push(aabb(b));
}
if vehicle.is_some() {
boat_boxes.push(aabb(b));
}
}
}
fn block_free(
world: &super::world::World,
level: &modern::LevelInfo,
e: &ghast_entity::Entity,
bb: [f64; 6],
) -> bool {
let pos = e.position();
modern::no_block_collision::<Rules, _>(
world,
level,
pos,
bb,
&modern::CollisionContext {
feet_y: pos[1],
..Default::default()
},
)
}
#[cold]
fn sleep_height(world: &super::world::World, pos: [i32; 3]) -> Option<f64> {
use super::data::Property;
let s = world.block_state(pos[0], pos[1], pos[2])?;
let b = s.block();
let shape_of = if b.data().flags & ghast_data::modern::block_flags::BED != 0 {
s
} else if b.name() == "straw_bed" {
if s.get(Property::Part) == Some("head") {
let [dx, dz] = match s.get(Property::Facing)? {
"north" => [0, 1],
"south" => [0, -1],
"west" => [1, 0],
"east" => [-1, 0],
_ => return None,
};
let foot = world.block_state(pos[0] + dx, pos[1], pos[2] + dz)?;
if foot.block() != b || foot.get(Property::Part) != Some("foot") {
return None;
}
foot
} else {
s
}
} else {
return None;
};
let shape = shape_of.outline_shape();
if shape.sizes == [0, 0, 0] {
return None;
}
shape.ys.last().copied()
}
fn section_order(pos: [f64; 3]) -> (i32, u64) {
let b = |v: f64| (v.floor() as i32) >> 4;
let (x, y, z) = (b(pos[0]), b(pos[1]), b(pos[2]));
(
x,
(u64::from(z as u32 & 0x3F_FFFF) << 20) | u64::from(y as u32 & 0xF_FFFF),
)
}
fn entity_box(e: &ghast_entity::Entity) -> Option<([f64; 3], [f64; 6])> {
if let Some(b) = e.bounding_box() {
return Some((e.position(), b));
}
let t = super::entity::entity_type(e)?;
(t.name == "shulker" && e.vehicle().is_none()).then(|| {
let [x, y, z] = e.position();
let (x, y, z) = (x.floor() + 0.5, (y + 0.5).floor(), z.floor() + 0.5);
([x, y, z], [x - 0.5, y, z - 0.5, x + 0.5, y + 1.0, z + 0.5])
})
}
#[derive(Debug, Default)]
struct OwnEntity {
id: i32,
main_arm_left: bool,
rockets: Vec<(i32, [f64; 3])>,
mounts: Vec<Mount>,
sticks: (bool, bool),
hands: [Option<i32>; 2],
dash_watch: bool,
}
#[derive(Debug, Clone)]
struct Mount {
id: i32,
ty: i32,
baby: bool,
flags: u8,
saddled: bool,
attrs: Vec<AttributeUpdate>,
boost: Option<i32>,
stays_still: bool,
camel_pose: (bool, i64),
spawned: i32,
dash: (i32, bool, i32),
grounded: bool,
}
impl OwnEntity {
#[cold]
fn dash_synced(&mut self, k: usize, dashing: bool, now: i32, grounded: bool) {
let m = &mut self.mounts[k];
if !(m.dash.0 > 0 || m.dash.1) {
m.grounded = grounded;
}
let state = m.dash_now(now);
let Some(kind) = u16::try_from(m.ty)
.ok()
.and_then(super::data::entity_type)
.and_then(|t| modern::MountKind::from_entity_name(t.name))
else {
return;
};
let (cd, on) = modern::Mount::dash_synced(kind, state, dashing, now != m.spawned);
m.dash = (cd, on, now);
self.dash_watch = true;
}
#[cold]
fn mount_moved(&mut self, id: i32, on_ground: bool, now: i32) {
if let Some(m) = self.mounts.iter_mut().find(|m| m.id == id)
&& m.grounded != on_ground
{
let (cd, on) = m.dash_now(now);
m.dash = (cd, on, now);
m.grounded = on_ground;
}
self.dash_watch = self.mounts.iter().any(|m| m.dash.0 > 0 || m.dash.1);
}
}
impl Mount {
fn dash_now(&self, now: i32) -> (i32, bool) {
let Some(kind) = u16::try_from(self.ty)
.ok()
.and_then(super::data::entity_type)
.and_then(|t| modern::MountKind::from_entity_name(t.name))
else {
return (self.dash.0, self.dash.1);
};
let ticks = u32::try_from(now.wrapping_sub(self.dash.2)).unwrap_or(0);
modern::Mount::dash_clock(kind, (self.dash.0, self.dash.1), ticks, self.grounded)
}
}
#[derive(Debug, Clone, Copy)]
struct EntityIds {
horses: [i32; 7],
llamas: [i32; 2],
nautili: [i32; 2],
steered: [i32; 2],
happy_ghast: i32,
firework_rocket: i32,
}
impl EntityIds {
fn get() -> &'static EntityIds {
static IDS: std::sync::OnceLock<EntityIds> = std::sync::OnceLock::new();
IDS.get_or_init(|| {
let id = |name: &str| super::data::entity_by_name(name).map_or(-1, |t| i32::from(t.id));
EntityIds {
horses: [
"horse",
"donkey",
"mule",
"skeleton_horse",
"zombie_horse",
"camel",
"camel_husk",
]
.map(id),
llamas: ["llama", "trader_llama"].map(id),
nautili: ["nautilus", "zombie_nautilus"].map(id),
steered: ["pig", "strider"].map(id),
happy_ghast: id("happy_ghast"),
firework_rocket: id("firework_rocket"),
}
})
}
#[cfg(test)]
fn tuple(&self) -> ([i32; 7], [i32; 2], [i32; 2], i32) {
(self.horses, self.llamas, self.nautili, self.firework_rocket)
}
fn is_mount(&self, ty: i32) -> bool {
self.horses.contains(&ty)
|| self.llamas.contains(&ty)
|| self.nautili.contains(&ty)
|| self.steered.contains(&ty)
|| ty == self.happy_ghast
}
fn motion_types() -> &'static [u16] {
static TYPES: std::sync::OnceLock<Box<[u16]>> = std::sync::OnceLock::new();
TYPES.get_or_init(|| {
let ids = EntityIds::get();
let mut v: Vec<u16> = ids
.horses
.iter()
.chain(&ids.llamas)
.chain(&ids.nautili)
.chain(&ids.steered)
.chain(std::iter::once(&ids.happy_ghast))
.filter_map(|&t| u16::try_from(t).ok())
.collect();
v.extend(
(0..=u16::MAX)
.map_while(super::data::entity_type)
.filter_map(|t| {
matches!(vehicle_kind(t.name), Some(VehicleKind::Boat(_))).then_some(t.id)
}),
);
v.sort_unstable();
v.into_boxed_slice()
})
}
}
fn teleport_values(
t: &super::proto::play::clientbound::EntityTeleport,
vel: [f64; 3],
pos: [f64; 3],
) -> ([f64; 3], [f64; 3]) {
let has = |bit: u32| t.flags.0 & (1 << bit) != 0;
let delta = [
if has(5) { vel[0] + t.dx } else { t.dx },
if has(6) { vel[1] + t.dy } else { t.dy },
if has(7) { vel[2] + t.dz } else { t.dz },
];
let to = [
if has(0) { pos[0] + t.x } else { t.x },
if has(1) { pos[1] + t.y } else { t.y },
if has(2) { pos[2] + t.z } else { t.z },
];
(delta, to)
}
fn far(a: [f64; 3], b: [f64; 3]) -> bool {
let d: f64 = (0..3).map(|k| (a[k] - b[k]) * (a[k] - b[k])).sum();
d > 4096.0
}
fn level_time(clock: (i64, i32), age: i32) -> i64 {
clock.0.wrapping_add(i64::from(age.wrapping_sub(clock.1)))
}
const MAX_MOUNTS: usize = 128;
impl Mount {
fn slots(&self, ids: &EntityIds) -> (bool, bool) {
if ids.llamas.contains(&self.ty) {
(true, true)
} else if ids.nautili.contains(&self.ty) {
let ok = !self.baby && self.flags & 4 != 0;
(ok, ok)
} else {
(!self.baby && self.flags & 2 != 0, true)
}
}
}
use super::meta::{
ATTACHED_TO_TARGET as DATA_ATTACHED_TO_TARGET, BABY as DATA_BABY,
BOOST_TIME as DATA_BOOST_TIME, CAMEL_DASH as DATA_CAMEL_DASH,
CAMEL_LAST_POSE as DATA_CAMEL_LAST_POSE, LIVING_FLAGS as DATA_LIVING_FLAGS,
MOUNT_FLAGS as DATA_MOUNT_FLAGS, PLAYER_MAIN_HAND as DATA_PLAYER_MAIN_HAND, POSE as DATA_POSE,
SHARED_FLAGS as DATA_SHARED_FLAGS, SLEEPING_POS as DATA_SLEEPING_POS,
};
use super::meta::{NAUTILUS_DASH as DATA_NAUTILUS_DASH, STAYS_STILL as DATA_STAYS_STILL};
const MAX_PENDING_ROCKETS: usize = 32;
fn range_attributes() -> [modern::Attribute; 2] {
[
modern::Attribute::new(4.5, 0.0, 64.0),
modern::Attribute::new(3.0, 0.0, 64.0),
]
}
fn mining_attributes() -> [modern::Attribute; 3] {
[
modern::Attribute::new(0.0, 0.0, 1024.0),
modern::Attribute::new(1.0, 0.0, 1024.0),
modern::Attribute::new(0.2, 0.0, 20.0),
]
}
impl std::fmt::Debug for ModernSim {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ModernSim")
.field("world", &self.world)
.field("pos", &self.player.pos)
.finish_non_exhaustive()
}
}
fn glider_equipped(inv: &ghast_inventory::Inventory) -> bool {
use super::inv::{Equip, can_glide_using};
let slots = [
(inv.held(), Equip::MainHand),
(inv.offhand(), Equip::Offhand),
(inv.armor(0), Equip::Head),
(inv.armor(1), Equip::Chest),
(inv.armor(2), Equip::Legs),
(inv.armor(3), Equip::Feet),
];
slots
.into_iter()
.any(|(s, slot)| s.is_some_and(|s| can_glide_using(s, slot)))
}
fn new_world(c: ghast_world::WorldConfig) -> super::world::World {
#[cfg_attr(not(test), allow(unused_mut))]
let mut w = super::world::World::new(c);
#[cfg(test)]
if std::env::var_os("GHAST_TEST_SHARED").is_some() {
static STORE: std::sync::OnceLock<ghast_world::SharedChunks> = std::sync::OnceLock::new();
w.set_shared_chunks(Some(STORE.get_or_init(Default::default).clone()));
}
w
}
impl ModernSim {
#[inline]
fn ext_wanted(&self) -> bool {
let x = &self.ext;
x.fall_flying
|| x.glider
|| x.rocket_count() > 0
|| x.spin_attack
|| x.auto_spin_ticks > 0
|| x.sleeping
|| self.movement_attributes
}
pub(crate) fn new() -> Self {
ModernSim {
world: new_world(config()),
player: modern::PlayerState::new([0.0; 3], 0.0, 0.0),
packets: ghast_physics::Packets::new(),
piston_step: false,
send_due: false,
updates: BlockUpdates::default(),
mining: mining_attributes(),
conduit_power: None,
ranges: range_attributes(),
old_pos: [0.0; 3],
entities: None,
use_effects: None,
ext: modern::PlayerExt::default(),
own: OwnEntity::default(),
rain_level: 0.0,
ext_active: false,
riptide: [0.0; 2],
around: Around::default(),
teams: None,
profile_name: "".into(),
riding: None,
vehicles: None,
parked: None,
left_mount: None,
reply: None,
force_step: ForceStepPosition::Off,
rec: None,
movement_attributes: false,
filter_dirty: false,
session: SessionPackets::default(),
gate: modern::LoadGate::waiting(),
entity_push: true,
predictions: Default::default(),
snapped: false,
server_flags: None,
absorption: 0.0,
absorption_dirty: false,
sleep: None,
pistons: super::pistons::Pistons::new(),
piston_edits: super::pistons::Edits::new(),
piston_uncertain_at: None,
piston_clock: (0, 0),
piston_carry: Vec::new(),
player_section: None,
section_moves: Vec::new(),
section_moves_n: 0,
nonliving: None,
fishing: crate::fishing::Fishing::default(),
}
}
pub(crate) fn with(opts: &SimOptions) -> Self {
let mut s = Self::new();
if let Some(c) = opts.world {
s.world = new_world(c);
}
if let Some(cache) = &opts.shared_chunks {
s.world.set_shared_chunks(Some(cache.clone()));
}
if let Some(p) = opts.record.as_deref() {
match crate::record::Recorder::create(p) {
Ok(r) => s.rec = Some(Box::new(r)),
Err(e) => log::warn!("cannot record to {}: {e}", p.display()),
}
}
s.entities = opts.entities.map(super::entity::Tracker::new);
s.teams = s.entities.is_some().then(Box::default);
if let Some(n) = &opts.profile_name {
s.profile_name = n.as_str().into();
}
s.force_step = opts.force_step_position;
s
}
#[cfg(all(test, feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
pub(crate) fn test_nether() -> Self {
let mut s = Self::new();
s.world.apply_registry(
"minecraft:dimension_type",
[
("minecraft:overworld", None),
("minecraft:the_nether", None),
]
.into_iter(),
);
s.world.apply_registry(
"minecraft:worldgen/biome",
[("minecraft:plains", None)].into_iter(),
);
s.world.enter_dimension("minecraft:the_nether", 1, 8);
s.sync_level();
s
}
#[cfg(all(
test,
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[allow(dead_code)]
pub(crate) fn test_share_chunks(&mut self, cache: Option<ghast_world::SharedChunks>) {
self.world.set_shared_chunks(cache);
}
#[cfg(test)]
pub(crate) fn test_overworld() -> Self {
Self::test_overworld_with(&SimOptions::default())
}
#[cfg(test)]
pub(crate) fn test_overworld_with(opts: &SimOptions) -> Self {
let mut s = Self::with(opts);
s.world.apply_registry(
"minecraft:dimension_type",
[("minecraft:overworld", None)].into_iter(),
);
s.world.apply_registry(
"minecraft:worldgen/biome",
[("minecraft:plains", None)].into_iter(),
);
s.world.enter_dimension("minecraft:overworld", 0, 8);
s.sync_level();
s
}
}
#[cold]
#[inline(never)]
fn force_modern_position(
packets: &mut ghast_physics::Packets,
p: &mut modern::PlayerState,
mode: ForceStepPosition,
) {
use ghast_physics::Packet as P;
let cur = p.pos;
if cur[1] == p.sent.pos[1] {
return;
}
let Some(&P::Move {
pos: None,
look,
on_ground,
horizontal_collision,
}) = packets
.as_slice()
.iter()
.rev()
.find(|q| matches!(q, P::Move { .. }))
else {
return;
};
if mode == ForceStepPosition::StepUpOnly && !(on_ground && cur[1] > p.sent.pos[1]) {
return;
}
let mut out = ghast_physics::Packets::new();
for q in packets.as_slice() {
out.push(match *q {
P::Move { pos: None, .. } => P::Move {
pos: Some(cur),
look,
on_ground,
horizontal_collision,
},
other => other,
});
}
*packets = out;
p.sent.pos = cur;
p.sent.position_reminder = 0;
}
sync_pose_fn!(sync_pose_26(p: modern::PlayerState), y: p.pos[1], sneaking: shift);
pub(crate) fn held_item_facts(id: u16, count: u8, efficiency: u8) -> HeldItem {
let item = super::data::Item::from_id(id);
let name = item.map_or("", super::data::Item::name);
let food = item.and_then(super::data::Item::food);
HeldItem {
id,
count,
efficiency,
places_block: item.is_some_and(|i| i.block().is_some()),
usable: food.is_some()
|| matches!(
name,
"potion"
| "milk_bucket"
| "honey_bottle"
| "bow"
| "crossbow"
| "shield"
| "trident"
| "spyglass"
| "goat_horn"
),
food: food.is_some(),
always_edible: food.is_some_and(|f| f.can_always_eat),
tool_speed: None,
modern_item: item.map(|_| id),
swing_on_use: false,
equips: false,
equip_swings: false,
creative_keeps_blocks: item
.and_then(super::data::Item::tool)
.is_some_and(|t| !t.can_destroy_blocks_in_creative),
use_succeeds: false,
}
}
pub(crate) fn dig_progress(
m: &crate::hands::ModernDig,
held: Option<&HeldItem>,
f: crate::hands::DigFactors,
) -> f32 {
use super::data::{BlockState, Item, dig};
let Some(state) = BlockState::from_id(m.state) else {
return 0.0;
};
let item = held.and_then(|h| h.modern_item).and_then(Item::from_id);
let c = dig::DigConditions {
mining_efficiency: m.mining_efficiency,
block_break_speed: m.block_break_speed,
submerged_mining_speed: m.submerged_mining_speed,
haste: (f.haste > 0).then(|| i32::from(f.haste) - 1),
conduit_power: m.conduit_power,
mining_fatigue: (f.fatigue > 0).then(|| i32::from(f.fatigue) - 1),
eye_in_water: f.in_water,
on_ground: f.on_ground,
};
dig::destroy_progress_with(state, item, &c)
}
fn scoreboard_name<'a>(
t: &'a super::entity::Tracker,
e: &'a ghast_entity::Entity,
buf: &'a mut [u8; 36],
) -> &'a str {
match t.scoreboard_name(e) {
Some(n) => n,
None => e.uuid().hyphenated().encode_lower(buf),
}
}
#[cfg(test)]
pub(super) fn entity_ids_for_test() -> ([i32; 7], [i32; 2], [i32; 2], i32) {
EntityIds::get().tuple()
}