Check rain at the player's and arrow's position
Arrows now ask whether it rains at their spot (biome precipitation and blocks above, Level.isRainingAt) instead of just the sky light, and a Riptide trident needs rain at the player's position. Rain also puts out a burning player (Entity.baseTick), in the window and for guests on the server thread.
This commit is contained in:
@@ -4669,6 +4669,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
self.powder_snow_fire()?;
|
||||
self.rain_extinguish_in_frame();
|
||||
self.tick_totem();
|
||||
let Some(player) = self.player.as_mut() else {
|
||||
return Ok(());
|
||||
@@ -9903,6 +9904,14 @@ impl Game<'_> {
|
||||
};
|
||||
Some(t < 0.15)
|
||||
}
|
||||
/// `Level.isRainingAt`: it rains, the sky light is 15, nothing that stops
|
||||
/// motion is above, and the biome's precipitation there is rain.
|
||||
fn raining_at(&self, p: BlockPos) -> bool {
|
||||
self.world.weather.levels(1.0).0 > 0.2
|
||||
&& self.world.light(p.x, p.y, p.z) >> 4 == 15
|
||||
&& self.rain_height(p.x, p.z) <= p.y
|
||||
&& self.precipitation(p.x, p.y, p.z) == Some(false)
|
||||
}
|
||||
/// `getHeight(Heightmap.Types.MOTION_BLOCKING, x, z)`: one above the
|
||||
/// highest block in `blocks_motion_in_heightmap` or holding a fluid.
|
||||
fn rain_height(&self, x: i32, z: i32) -> i32 {
|
||||
|
||||
@@ -547,7 +547,7 @@ impl Game<'_> {
|
||||
});
|
||||
}
|
||||
/// `Entity.isInRain`: rain at the block position or at the top of the box.
|
||||
fn in_rain(&mut self, at: Vec3, top: f64) -> bool {
|
||||
pub(super) fn in_rain(&mut self, at: Vec3, top: f64) -> bool {
|
||||
let p = BlockPos::new(
|
||||
at.x.floor() as i32,
|
||||
at.y.floor() as i32,
|
||||
|
||||
@@ -2118,11 +2118,9 @@ impl Game<'_> {
|
||||
ArrowEvent::ShootEvent | ArrowEvent::Drop => {}
|
||||
}
|
||||
}
|
||||
/// `Level.isRainingAt` for arrows: raining, open to the sky (the biome's
|
||||
/// precipitation is not checked here).
|
||||
/// `Level.isRainingAt` for arrows.
|
||||
fn arrow_rain(&self) -> impl Fn(BlockPos) -> bool + '_ {
|
||||
let raining = self.world.weather.levels(1.0).0 > 0.2;
|
||||
move |p: BlockPos| raining && self.world.light(p.x, p.y, p.z) >> 4 == 15
|
||||
move |p: BlockPos| self.raining_at(p)
|
||||
}
|
||||
/// The level as arrows see it.
|
||||
fn arrow_scene<'s>(
|
||||
|
||||
@@ -2267,6 +2267,8 @@ impl Game<'_> {
|
||||
game.cauldron_extinguish(*pos);
|
||||
}
|
||||
}
|
||||
// Entity.baseTick: rain puts out a burning player.
|
||||
game.rain_extinguish_player();
|
||||
// WitherRoseBlock.entityInside along those moves.
|
||||
for event in &events {
|
||||
if matches!(event, MotionEvent::InsideWitherRose) {
|
||||
|
||||
@@ -53,7 +53,11 @@ impl Game<'_> {
|
||||
if let Some(player) = self.player.as_mut() {
|
||||
player.fire_ticks = 0;
|
||||
}
|
||||
// Entity.playEntityOnFireExtinguishedSound
|
||||
self.extinguish_sound(at);
|
||||
Ok(())
|
||||
}
|
||||
/// Entity.playEntityOnFireExtinguishedSound
|
||||
fn extinguish_sound(&mut self, at: [f64; 3]) {
|
||||
let r = self.particles.random();
|
||||
let pitch = 1.6 + (r.next_float() - r.next_float()) * 0.4;
|
||||
self.audio.play(
|
||||
@@ -62,7 +66,37 @@ impl Game<'_> {
|
||||
0.7,
|
||||
pitch,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
/// `Entity.baseTick`: a burning player in the rain (`isInRain`) has the
|
||||
/// fire put out (`clearFire`). Returns whether it did.
|
||||
pub(super) fn rain_extinguish_player(&mut self) -> bool {
|
||||
let Some(player) = self.player.as_ref() else {
|
||||
return false;
|
||||
};
|
||||
let (at, top) = (player.position, player.bounds().max_position().y);
|
||||
if player.fire_ticks <= 0 || !self.in_rain(at, top) {
|
||||
return false;
|
||||
}
|
||||
if let Some(player) = self.player.as_mut() {
|
||||
player.fire_ticks = 0;
|
||||
}
|
||||
true
|
||||
}
|
||||
/// The in-window player's rain extinguish, with its sound (a server's
|
||||
/// fire is the server's).
|
||||
pub(super) fn rain_extinguish_in_frame(&mut self) {
|
||||
if self.remote.is_some() {
|
||||
return;
|
||||
}
|
||||
let at = self
|
||||
.player
|
||||
.as_ref()
|
||||
.map(|p| [p.position.x, p.position.y, p.position.z]);
|
||||
if self.rain_extinguish_player()
|
||||
&& let Some(at) = at
|
||||
{
|
||||
self.extinguish_sound(at);
|
||||
}
|
||||
}
|
||||
/// Whether the block at `pos` is powder snow.
|
||||
pub(super) fn is_powder_snow(&self, pos: [i32; 3]) -> bool {
|
||||
|
||||
@@ -112,7 +112,7 @@ impl Game<'_> {
|
||||
}
|
||||
true
|
||||
}
|
||||
fn in_water_or_rain(&self) -> bool {
|
||||
fn in_water_or_rain(&mut self) -> bool {
|
||||
let Some(p) = &self.player else { return false };
|
||||
let (x, y, z) = (
|
||||
p.position.x.floor() as i32,
|
||||
@@ -121,8 +121,8 @@ impl Game<'_> {
|
||||
);
|
||||
let water = self.res.facts().get(self.world.block(x, y, z)).fluid
|
||||
== horizon_client::blocks::Fluid::Water;
|
||||
let sky = self.world.light(x, y + 1, z) >> 4 == 15;
|
||||
water || (self.world.weather.raining && sky)
|
||||
let (at, top) = (p.position, p.bounds().max_position().y);
|
||||
water || self.in_rain(at, top)
|
||||
}
|
||||
/// The living entities a spinning player can touch this tick, for
|
||||
/// `LivingEntity.checkAutoSpinAttack` (none when not spinning).
|
||||
|
||||
Reference in New Issue
Block a user