pub use super::body::Side;
use super::body::{
self, Body, InsideRules, LegacyRandom, MoveRules, atan2, degrees, lerp_rotation, with_env,
};
use super::fluid::kind;
use super::math::{V3, contains};
use super::rules::Rules;
use super::rules::shared::state_flags as sf;
use crate::math::Aabb;
use crate::pick::{BlockHit, Direction};
use crate::world::BlockView;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ProjectileKind {
Snowball,
Egg,
EnderPearl,
ExperienceBottle,
SplashPotion,
LingeringPotion,
WindCharge,
Arrow,
SpectralArrow,
Trident,
SmallFireball,
LargeFireball,
DragonFireball,
WitherSkull,
FishingBobber,
}
#[derive(Clone, Copy, PartialEq, Eq)]
enum Family {
Thrown,
Hurting,
Arrow,
Bobber,
}
impl ProjectileKind {
pub const ALL: [ProjectileKind; 15] = [
ProjectileKind::Snowball,
ProjectileKind::Egg,
ProjectileKind::EnderPearl,
ProjectileKind::ExperienceBottle,
ProjectileKind::SplashPotion,
ProjectileKind::LingeringPotion,
ProjectileKind::WindCharge,
ProjectileKind::Arrow,
ProjectileKind::SpectralArrow,
ProjectileKind::Trident,
ProjectileKind::SmallFireball,
ProjectileKind::LargeFireball,
ProjectileKind::DragonFireball,
ProjectileKind::WitherSkull,
ProjectileKind::FishingBobber,
];
#[must_use]
pub const fn entity_name(self) -> &'static str {
match self {
ProjectileKind::Snowball => "snowball",
ProjectileKind::Egg => "egg",
ProjectileKind::EnderPearl => "ender_pearl",
ProjectileKind::ExperienceBottle => "experience_bottle",
ProjectileKind::SplashPotion => "splash_potion",
ProjectileKind::LingeringPotion => "lingering_potion",
ProjectileKind::WindCharge => "wind_charge",
ProjectileKind::Arrow => "arrow",
ProjectileKind::SpectralArrow => "spectral_arrow",
ProjectileKind::Trident => "trident",
ProjectileKind::SmallFireball => "small_fireball",
ProjectileKind::LargeFireball => "fireball",
ProjectileKind::DragonFireball => "dragon_fireball",
ProjectileKind::WitherSkull => "wither_skull",
ProjectileKind::FishingBobber => "fishing_bobber",
}
}
#[must_use]
pub fn from_entity_name(name: &str) -> Option<ProjectileKind> {
let name = name.strip_prefix("minecraft:").unwrap_or(name);
ProjectileKind::ALL
.into_iter()
.find(|k| k.entity_name() == name)
}
fn family(self) -> Family {
match self {
ProjectileKind::Snowball
| ProjectileKind::Egg
| ProjectileKind::EnderPearl
| ProjectileKind::ExperienceBottle
| ProjectileKind::SplashPotion
| ProjectileKind::LingeringPotion => Family::Thrown,
ProjectileKind::WindCharge
| ProjectileKind::SmallFireball
| ProjectileKind::LargeFireball
| ProjectileKind::DragonFireball
| ProjectileKind::WitherSkull => Family::Hurting,
ProjectileKind::Arrow | ProjectileKind::SpectralArrow | ProjectileKind::Trident => {
Family::Arrow
}
ProjectileKind::FishingBobber => Family::Bobber,
}
}
#[must_use]
pub const fn dimensions(self) -> (f32, f32) {
match self {
ProjectileKind::WindCharge
| ProjectileKind::SmallFireball
| ProjectileKind::WitherSkull => (0.3125, 0.3125),
ProjectileKind::Arrow | ProjectileKind::SpectralArrow | ProjectileKind::Trident => {
(0.5, 0.5)
}
ProjectileKind::LargeFireball | ProjectileKind::DragonFireball => (1.0, 1.0),
_ => (0.25, 0.25),
}
}
fn eye_height(self) -> f32 {
match self {
ProjectileKind::Arrow | ProjectileKind::SpectralArrow | ProjectileKind::Trident => 0.13,
_ => self.dimensions().1 * 0.85,
}
}
#[must_use]
pub const fn gravity(self) -> f64 {
match self {
ProjectileKind::Snowball | ProjectileKind::Egg | ProjectileKind::EnderPearl => 0.03,
ProjectileKind::ExperienceBottle => 0.07,
ProjectileKind::SplashPotion | ProjectileKind::LingeringPotion => 0.05,
ProjectileKind::Arrow | ProjectileKind::SpectralArrow | ProjectileKind::Trident => 0.05,
_ => 0.0,
}
}
#[must_use]
pub const fn default_acceleration_power(self) -> f64 {
match self {
ProjectileKind::SmallFireball
| ProjectileKind::LargeFireball
| ProjectileKind::DragonFireball
| ProjectileKind::WitherSkull => 0.1,
_ => 0.0,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum BobberState {
#[default]
Flying,
Bobbing,
Hooked,
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct HookedEntity {
pub pos: [f64; 3],
pub height: f32,
pub removed: bool,
}
impl HookedEntity {
#[must_use]
pub const fn new(pos: [f64; 3], height: f32) -> HookedEntity {
HookedEntity {
pos,
height,
removed: false,
}
}
#[must_use]
pub const fn removed() -> HookedEntity {
HookedEntity {
pos: [0.0; 3],
height: 0.0,
removed: true,
}
}
}
#[derive(Clone, Debug)]
pub struct Projectile {
kind: ProjectileKind,
b: Body,
accel: f64,
dangerous: bool,
in_ground: bool,
in_ground_time: i32,
life: i32,
last_state: Option<Option<u32>>,
bobber: BobberState,
owner: Option<[f64; 3]>,
owner_holds_rod: bool,
out_of_water: i32,
fish: Option<Box<Fish>>,
}
#[derive(Clone, Debug)]
struct Fish {
uuid_lsb: i64,
game_time: i64,
sync: LegacyRandom,
biting: bool,
hooked: Option<HookedEntity>,
}
impl Default for Fish {
fn default() -> Fish {
Fish {
uuid_lsb: 0,
game_time: 0,
sync: LegacyRandom::new(0),
biting: false,
hooked: None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct ProjectileHit {
pub pos: [i32; 3],
pub face: Direction,
pub location: [f64; 3],
pub inside: bool,
pub border: bool,
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct Impact {
pub tick: u32,
pub hit: ProjectileHit,
}
impl Projectile {
#[must_use]
pub fn new(kind: ProjectileKind, pos: [f64; 3], vel: [f64; 3]) -> Projectile {
let (w, h) = kind.dimensions();
let mut b = Body::new(V3::of(pos), V3::of(vel), w, h, kind.eye_height());
if kind == ProjectileKind::WindCharge {
b.box_drop = 0.15;
b.set_pos(V3::of(pos));
}
Projectile {
kind,
b,
accel: kind.default_acceleration_power(),
dangerous: false,
in_ground: false,
in_ground_time: 0,
life: 0,
last_state: None,
bobber: BobberState::Flying,
owner: None,
owner_holds_rod: true,
out_of_water: 0,
fish: None,
}
}
fn fish(&mut self) -> &mut Fish {
self.fish.get_or_insert_with(Box::default)
}
#[must_use]
pub fn with_uuid_lsb(mut self, lsb: i64) -> Projectile {
self.fish().uuid_lsb = lsb;
self
}
pub fn set_game_time(&mut self, time: i64) {
self.fish().game_time = time;
}
pub fn set_biting(&mut self, biting: bool) {
let f = self.fish();
f.biting = biting;
if biting {
let r = f.sync.next_float();
let y = -0.4f32 * (r * (1.0f32 - 0.6f32) + 0.6f32);
self.b.vel = V3::new(self.b.vel.x, f64::from(y), self.b.vel.z);
}
}
pub fn set_hooked(&mut self, hooked: Option<HookedEntity>) {
if hooked.is_none() && self.fish.is_none() {
return;
}
self.fish().hooked = hooked;
}
#[must_use]
pub fn hooked(&self) -> Option<HookedEntity> {
self.fish.as_ref().and_then(|f| f.hooked)
}
#[must_use]
pub fn biting(&self) -> bool {
self.fish.as_ref().is_some_and(|f| f.biting)
}
#[must_use]
pub fn with_rotation(mut self, yaw: f32, pitch: f32) -> Projectile {
self.b.yaw = yaw;
self.b.pitch = pitch;
self.b.yaw_o = yaw;
self.b.pitch_o = pitch;
self
}
#[must_use]
pub fn with_acceleration_power(mut self, power: f64) -> Projectile {
self.accel = power;
self
}
#[must_use]
pub fn with_dangerous(mut self, dangerous: bool) -> Projectile {
self.dangerous = dangerous;
self
}
#[must_use]
pub fn with_random_seed(mut self, seed: i64) -> Projectile {
self.b.rng = LegacyRandom::new(seed);
self
}
#[must_use]
pub fn with_on_ground(mut self, on_ground: bool) -> Projectile {
self.b.on_ground = on_ground;
self
}
#[must_use]
pub fn with_fall_distance(mut self, fall: f64) -> Projectile {
self.b.fall = fall;
self
}
#[must_use]
pub fn with_owner(mut self, pos: Option<[f64; 3]>, holds_rod: bool) -> Projectile {
self.owner = pos;
self.owner_holds_rod = holds_rod;
self
}
pub fn set_owner_pos(&mut self, pos: Option<[f64; 3]>) {
self.owner = pos;
}
pub fn set_pos(&mut self, pos: [f64; 3]) {
self.b.set_pos(V3::of(pos));
}
pub fn set_vel(&mut self, vel: [f64; 3]) {
self.b.vel = V3::of(vel);
}
pub fn set_rotation(&mut self, yaw: f32, pitch: f32) {
self.b.yaw = yaw;
self.b.pitch = pitch;
}
pub fn set_on_ground(&mut self, on_ground: bool) {
self.b.on_ground = on_ground;
}
pub fn set_interpolation_start(&mut self, pos: [f64; 3], yaw: f32, pitch: f32) {
self.b.pending_old = Some((V3::of(pos), yaw, pitch));
}
#[must_use]
pub fn moved_last_tick(&self) -> &[[f64; 3]] {
&self.b.moved[..usize::from(self.b.moved_n)]
}
pub fn set_in_ground(&mut self, in_ground: bool) {
self.in_ground = in_ground;
}
pub fn set_acceleration_power(&mut self, power: f64) {
self.accel = power;
}
pub fn set_dangerous(&mut self, dangerous: bool) {
self.dangerous = dangerous;
}
#[must_use]
pub fn kind(&self) -> ProjectileKind {
self.kind
}
#[must_use]
pub fn pos(&self) -> [f64; 3] {
self.b.pos.arr()
}
#[must_use]
pub fn vel(&self) -> [f64; 3] {
self.b.vel.arr()
}
#[must_use]
pub fn yaw(&self) -> f32 {
self.b.yaw
}
#[must_use]
pub fn pitch(&self) -> f32 {
self.b.pitch
}
#[must_use]
pub fn bounding_box(&self) -> Aabb {
self.b.bb
}
#[must_use]
pub fn on_ground(&self) -> bool {
self.b.on_ground
}
#[must_use]
pub fn in_water(&self) -> bool {
self.b.in_water
}
#[must_use]
pub fn in_ground(&self) -> bool {
self.in_ground
}
#[must_use]
pub fn in_ground_time(&self) -> i32 {
self.in_ground_time
}
#[must_use]
pub fn life(&self) -> i32 {
self.life
}
#[must_use]
pub fn bobbing(&self) -> BobberState {
self.bobber
}
#[must_use]
pub fn acceleration_power(&self) -> f64 {
self.accel
}
#[must_use]
pub fn removed(&self) -> bool {
self.b.removed
}
#[must_use]
pub fn tick_count(&self) -> i32 {
self.b.tick_count
}
}
#[must_use]
pub fn bobber_liquid_height<R: Rules, W: BlockView<State = R::State>>(
world: &W,
pos: [f64; 3],
) -> f32 {
let floor = crate::math::floor;
let bp = [floor(pos[0]), floor(pos[1]), floor(pos[2])];
with_env::<R, W, _>(world, |w| {
let f = w.fluid(bp[0], bp[1], bp[2]);
if kind(f) == 1 {
w.fluid_height(bp[0], bp[1], bp[2], f)
} else {
0.0
}
})
}
pub fn tick_projectile<R: Rules, W: BlockView<State = R::State>>(
p: &mut Projectile,
side: Side,
world: &W,
) -> Option<ProjectileHit> {
if p.b.removed {
return None;
}
with_env::<R, W, _>(world, |w| match p.kind.family() {
Family::Thrown => thrown::<R, W>(p, side, w),
Family::Hurting => hurting::<R, W>(p, side, w),
Family::Arrow => arrow::<R, W>(p, side, w),
Family::Bobber => bobber::<R, W>(p, side, w),
})
}
pub fn run_projectile<R: Rules, W: BlockView<State = R::State>>(
p: &mut Projectile,
side: Side,
world: &W,
max_ticks: u32,
) -> Option<Impact> {
for t in 1..=max_ticks {
if p.b.removed {
return None;
}
if let Some(hit) = tick_projectile::<R, W>(p, side, world) {
return Some(Impact { tick: t, hit });
}
}
None
}
const PROJECTILE_INSIDE: InsideRules = InsideRules {
projectile_bubbles: true,
no_bubbles: false,
};
fn to_hit(h: BlockHit, border: bool) -> Option<ProjectileHit> {
h.is_block().then_some(ProjectileHit {
pos: h.pos,
face: h.face,
location: h.location,
inside: h.inside,
border,
})
}
fn update_rotation(b: &mut Body) {
let v = b.vel;
let sd = v.horizontal_sqr().sqrt();
b.pitch = lerp_rotation(b.pitch_o, degrees(atan2(v.y, sd)));
b.yaw = lerp_rotation(b.yaw_o, degrees(atan2(v.x, v.z)));
}
fn thrown<R: Rules, W: BlockView<State = R::State>>(
p: &mut Projectile,
side: Side,
w: &body::Env<'_, R, W>,
) -> Option<ProjectileHit> {
let ir = InsideRules {
projectile_bubbles: p.kind != ProjectileKind::EnderPearl,
no_bubbles: false,
};
let b = &mut p.b;
b.start_tick();
if b.first_tick {
let bb = b.bb;
let (x0, y0, z0) = (
super::math::floor(bb.min_x),
super::math::floor(bb.min_y),
super::math::floor(bb.min_z),
);
let (x1, y1, z1) = (
super::math::floor(bb.max_x),
super::math::floor(bb.max_y),
super::math::floor(bb.max_z),
);
for z in z0..=z1 {
for y in y0..=y1 {
for x in x0..=x1 {
let s = w.state(x, y, z);
let ph = R::phys(s);
if ph.kind() == super::rules::shared::BlockKind::BubbleColumn as u8 {
let above = R::phys(w.state(x, y + 1, z));
let nothing_above = (above.flags() & sf::EMPTY != 0
&& above.flags() & sf::CONTEXT == 0
|| above.flags() & sf::CONTEXT != 0
&& above.kind()
== super::rules::shared::BlockKind::PowderSnow as u8)
&& kind(above.fluid()) == 0;
body::bubble_column(b, ph.aux() & 1 != 0, nothing_above, ir);
}
}
}
}
}
b.apply_gravity(p.kind.gravity());
let inertia: f32 = if b.in_water { 0.8 } else { 0.99 };
b.vel = b.vel.scale(f64::from(inertia));
let ctx = b.ctx();
let (hit, border) = body::clip::<R, W>(w, b.pos, b.pos.add(b.vel), &ctx);
let next = if hit.is_block() {
V3::of(hit.location)
} else {
b.pos.add(b.vel)
};
b.set_pos(next);
update_rotation(b);
body::apply_effects_from_blocks::<R, W>(b, w, ir);
body::base_tick::<R, W>(b, w, true, true);
let hit = to_hit(hit, border);
if hit.is_some() && side == Side::Server {
b.removed = true;
}
hit
}
fn hurting<R: Rules, W: BlockView<State = R::State>>(
p: &mut Projectile,
side: Side,
w: &body::Env<'_, R, W>,
) -> Option<ProjectileHit> {
let wind = p.kind == ProjectileKind::WindCharge;
let b = &mut p.b;
b.start_tick();
if wind && side == Side::Server && b.block_pos()[1] > w.max_y + 30 {
b.removed = true;
return None;
}
let (air, liquid): (f32, f32) = if wind {
(1.0, 1.0)
} else if p.kind == ProjectileKind::WitherSkull && p.dangerous {
(0.73, 0.8)
} else {
(0.95, 0.8)
};
let inertia = if b.in_water { liquid } else { air };
let v = b.vel;
b.vel = v
.add(v.normalize().scale(p.accel))
.scale(f64::from(inertia));
let bp = b.block_pos();
if side == Side::Server && !w.w.is_chunk_loaded(bp[0] >> 4, bp[2] >> 4) {
b.removed = true;
return None;
}
let ctx = b.ctx();
let (hit, border) = body::clip::<R, W>(w, b.pos, b.pos.add(b.vel), &ctx);
let next = if hit.is_block() {
V3::of(hit.location)
} else {
b.pos.add(b.vel)
};
rotate_towards_movement(b);
b.set_pos(next);
body::apply_effects_from_blocks::<R, W>(b, w, PROJECTILE_INSIDE);
body::base_tick::<R, W>(b, w, true, true);
let hit = to_hit(hit, border);
if hit.is_some() && side == Side::Server {
b.removed = true;
}
hit
}
fn rotate_towards_movement(b: &mut Body) {
let v = b.vel;
if v.length_sqr() == 0.0 {
return;
}
let sd = v.horizontal_sqr().sqrt();
let yaw = degrees(atan2(v.z, v.x)) + 90.0;
let pitch = degrees(atan2(sd, v.y)) - 90.0;
while pitch - b.pitch_o < -180.0 {
b.pitch_o -= 360.0;
}
while pitch - b.pitch_o >= 180.0 {
b.pitch_o += 360.0;
}
while yaw - b.yaw_o < -180.0 {
b.yaw_o -= 360.0;
}
while yaw - b.yaw_o >= 180.0 {
b.yaw_o += 360.0;
}
b.pitch = b.pitch_o + 0.2 * (pitch - b.pitch_o);
b.yaw = b.yaw_o + 0.2 * (yaw - b.yaw_o);
}
fn arrow<R: Rules, W: BlockView<State = R::State>>(
p: &mut Projectile,
side: Side,
w: &body::Env<'_, R, W>,
) -> Option<ProjectileHit> {
let water_inertia: f32 = if p.kind == ProjectileKind::Trident {
0.99
} else {
0.6
};
let b = &mut p.b;
b.start_tick();
let movement = b.vel;
let bp = b.block_pos();
let bs = w.state(bp[0], bp[1], bp[2]);
if R::phys(bs).flags() & sf::AIR == 0 {
let mut inside = false;
match super::collide::placed_shape::<R>(bs, bp[0], bp[1], bp[2], None) {
Some(super::collide::Placed::Cube(o)) => {
inside = contains(
&Aabb::new(o[0], o[1], o[2], o[0] + 1.0, o[1] + 1.0, o[2] + 1.0),
b.pos,
);
}
Some(sh @ super::collide::Placed::Shape(..)) => {
sh.for_boxes(|bb| {
if contains(&bb, b.pos) {
inside = true;
return false;
}
true
});
}
_ => {}
}
if inside {
b.vel = V3::ZERO;
p.in_ground = true;
}
}
if p.in_ground {
if side == Side::Server {
let changed = match p.last_state {
Some(Some(id)) => R::state_id(bs) != Some(id),
_ => true,
};
let probe = super::math::inflate(
&Aabb::new(b.pos.x, b.pos.y, b.pos.z, b.pos.x, b.pos.y, b.pos.z),
0.06,
0.06,
0.06,
);
if changed && body::no_collision_empty::<R, W>(w, &probe) {
p.in_ground = false;
let (fx, fy, fz) = (
b.rng.next_float() * 0.2,
b.rng.next_float() * 0.2,
b.rng.next_float() * 0.2,
);
b.vel = b.vel.mul(f64::from(fx), f64::from(fy), f64::from(fz));
p.life = 0;
} else {
p.life += 1;
if p.life >= 1200 {
b.removed = true;
}
}
}
p.in_ground_time += 1;
if !b.removed {
let ir = InsideRules {
projectile_bubbles: true,
no_bubbles: p.in_ground,
};
body::apply_effects_from_blocks::<R, W>(b, w, ir);
}
return None;
}
p.in_ground_time = 0;
let origin = b.pos;
if b.in_water {
b.vel = b.vel.scale(f64::from(water_inertia));
}
let yaw = degrees(atan2(movement.x, movement.z));
let pitch = degrees(atan2(movement.y, movement.horizontal_sqr().sqrt()));
b.pitch = lerp_rotation(b.pitch, pitch);
b.yaw = lerp_rotation(b.yaw, yaw);
let ctx = b.ctx();
let (hit, border) = body::clip::<R, W>(w, origin, origin.add(movement), &ctx);
b.set_pos(V3::of(hit.location));
body::apply_effects_between::<R, W>(b, w, origin, V3::of(hit.location), PROJECTILE_INSIDE);
let result = to_hit(hit, border);
if hit.is_block() && !b.removed {
p.last_state = Some(R::state_id(w.state(hit.pos[0], hit.pos[1], hit.pos[2])));
let v = b.vel;
let sign = |x: f64| {
if x > 0.0 {
1.0
} else if x < 0.0 {
-1.0
} else {
x
}
};
let off = V3::new(sign(v.x), sign(v.y), sign(v.z)).scale(f64::from(0.05f32));
let at = b.pos.sub(off);
b.set_pos(at);
b.vel = V3::ZERO;
b.rng.next_float();
p.in_ground = true;
}
if !b.in_water {
b.vel = b.vel.scale(f64::from(0.99f32));
}
if !p.in_ground {
b.apply_gravity(p.kind.gravity());
}
body::base_tick::<R, W>(b, w, !p.in_ground, true);
result
}
fn bobber<R: Rules, W: BlockView<State = R::State>>(
p: &mut Projectile,
side: Side,
w: &body::Env<'_, R, W>,
) -> Option<ProjectileHit> {
if let Some(f) = p.fish.as_deref_mut() {
f.sync = LegacyRandom::new(f.uuid_lsb ^ f.game_time);
}
let b = &mut p.b;
b.start_tick();
body::base_tick::<R, W>(b, w, true, true);
let Some(owner) = p.owner else {
b.removed = true;
return None;
};
if side == Side::Server {
let d = b.pos.dist_sqr(V3::of(owner));
if !p.owner_holds_rod || d > 1024.0 {
b.removed = true;
return None;
}
}
if b.on_ground {
p.life += 1;
if p.life >= 1200 {
b.removed = true;
return None;
}
} else {
p.life = 0;
}
let bp = b.block_pos();
let f = w.fluid(bp[0], bp[1], bp[2]);
let liquid: f32 = if kind(f) == 1 {
w.fluid_height(bp[0], bp[1], bp[2], f)
} else {
0.0
};
let in_water = liquid > 0.0;
let hooked = p.fish.as_ref().and_then(|f| f.hooked);
let mut result = None;
match p.bobber {
BobberState::Flying => {
if hooked.is_some() {
b.vel = V3::ZERO;
p.bobber = BobberState::Hooked;
return None;
}
if in_water {
b.vel = b.vel.mul(0.3, 0.2, 0.3);
p.bobber = BobberState::Bobbing;
return None;
}
let ctx = b.ctx();
let (hit, border) = body::clip::<R, W>(w, b.pos, b.pos.add(b.vel), &ctx);
if hit.is_block() {
let l = V3::of(hit.location);
let d = l.dist_sqr(b.pos);
b.vel = b.vel.normalize().scale(d);
result = to_hit(hit, border);
}
}
BobberState::Bobbing => {
let v = b.vel;
let mut force = b.pos.y + v.y - f64::from(bp[1]) - f64::from(liquid);
if force.abs() < 0.01 {
let sign = if force > 0.0 {
1.0
} else if force < 0.0 {
-1.0
} else {
force
};
force += sign * 0.1;
}
let r = f64::from(b.rng.next_float());
b.vel = V3::new(v.x * 0.9, v.y - force * r * 0.2, v.z * 0.9);
if in_water {
p.out_of_water = (p.out_of_water - 1).max(0);
if let Some(f) = p.fish.as_deref_mut()
&& f.biting
{
let r1 = f64::from(f.sync.next_float());
let r2 = f64::from(f.sync.next_float());
b.vel = b.vel.add(V3::new(0.0, -0.1 * r1 * r2, 0.0));
}
} else {
p.out_of_water = (p.out_of_water + 1).min(10);
}
}
BobberState::Hooked => {
if let Some(h) = hooked {
if h.removed {
if let Some(f) = p.fish.as_deref_mut() {
f.hooked = None;
}
p.bobber = BobberState::Flying;
} else {
let y = h.pos[1] + f64::from(h.height) * 0.8;
b.set_pos(V3::new(h.pos[0], y, h.pos[2]));
}
}
return None;
}
}
let gravity = if R::BOBBER_DEFAULT_GRAVITY {
f64::from(0.03f32)
} else {
0.0
};
if kind(f) != 1 && !b.on_ground && hooked.is_none() {
let sink = if R::BOBBER_DEFAULT_GRAVITY {
gravity
} else {
0.03
};
b.vel = b.vel.add(V3::new(0.0, -sink, 0.0));
}
let authoritative = side == Side::Server;
let mr = MoveRules {
authoritative,
simulate: authoritative || R::SIMULATED_ON_CLIENT,
gravity,
air_drag: 0.98,
};
let v = b.vel;
body::entity_move::<R, W>(b, w, v, mr);
body::apply_effects_from_blocks::<R, W>(b, w, PROJECTILE_INSIDE);
update_rotation(b);
if p.bobber == BobberState::Flying && (b.on_ground || b.hcol) {
b.vel = V3::ZERO;
}
b.vel = b.vel.scale(0.92);
result
}