Burn boats and minecarts in lava, and place boats on lava
Vehicles take lava damage and keep burning for 15 seconds like vanilla (lavaHurt, remainingFireTicks), breaking and dropping their items; a TNT minecart primes from fire. Boat placement stops at lava as well as water. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,8 @@ pub(super) struct Boat {
|
||||
pub hurt_time: i32,
|
||||
pub hurt_dir: i32,
|
||||
pub damage: f32,
|
||||
/// `Entity.remainingFireTicks`: lava sets a boat alight for 15 seconds.
|
||||
pub fire_ticks: i32,
|
||||
pub paddles: [f32; 2],
|
||||
pub paddling: [bool; 2],
|
||||
/// left, right, up, down
|
||||
@@ -77,6 +79,7 @@ impl Boat {
|
||||
hurt_time: 0,
|
||||
hurt_dir: 1,
|
||||
damage: 0.0,
|
||||
fire_ticks: 0,
|
||||
paddles: [0.0; 2],
|
||||
paddling: [false; 2],
|
||||
input: [false; 4],
|
||||
@@ -183,13 +186,18 @@ impl BoatModels {
|
||||
}
|
||||
impl Game<'_> {
|
||||
fn fluid_height(&self, x: i32, y: i32, z: i32) -> Option<(f32, bool)> {
|
||||
self.fluid_height_of(x, y, z, false)
|
||||
}
|
||||
/// `FluidState.getHeight` and whether it is a source; water only,
|
||||
/// unless `lava` too (`ClipContext.Fluid.ANY`).
|
||||
fn fluid_height_of(&self, x: i32, y: i32, z: i32, lava: bool) -> Option<(f32, bool)> {
|
||||
let f = self.res.facts().get(self.world.block(x, y, z));
|
||||
if f.fluid != Fluid::Water {
|
||||
if f.fluid != Fluid::Water && !(lava && f.fluid == Fluid::Lava) {
|
||||
return None;
|
||||
}
|
||||
let above = self.res.facts().get(self.world.block(x, y + 1, z));
|
||||
// FluidState.getHeight: 1 under the same fluid, else amount / 9.
|
||||
let height = if above.fluid == Fluid::Water {
|
||||
let height = if above.fluid == f.fluid {
|
||||
1.0
|
||||
} else {
|
||||
f32::from(f.fluid_level) / 9.0
|
||||
@@ -461,6 +469,78 @@ impl Game<'_> {
|
||||
let b = self.boats[i].clone();
|
||||
self.boats[i] = self.tick_boat(b, false);
|
||||
}
|
||||
// applyEffectsFromBlocks runs on the server for every boat, the
|
||||
// client-driven ones too; a boat lava destroys leaves the list.
|
||||
let mut i = 0;
|
||||
while i < self.boats.len() {
|
||||
let p = self.boats[i].position;
|
||||
let skip = Some(self.boats[i].id) == self.riding
|
||||
|| !ticking(p.x.floor() as i32, p.z.floor() as i32);
|
||||
if skip || !self.boat_fire_tick(i) {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The fire half of `Entity.baseTick` and `LavaFluid.entityInside`
|
||||
/// (`lavaIgnite`, then `lavaHurt`) after the boat moved. True when the
|
||||
/// boat was destroyed and removed.
|
||||
fn boat_fire_tick(&mut self, i: usize) -> bool {
|
||||
let (lava, water) = self.hull_fluids(self.boats[i].bounds());
|
||||
let b = &mut self.boats[i];
|
||||
if water {
|
||||
b.fire_ticks = 0;
|
||||
}
|
||||
let mut burn = 0.0;
|
||||
if b.fire_ticks > 0 {
|
||||
if b.fire_ticks % 20 == 0 && !lava {
|
||||
burn = 1.0;
|
||||
}
|
||||
b.fire_ticks -= 1;
|
||||
}
|
||||
if burn > 0.0 && self.hurt_boat(i, burn, false) {
|
||||
return true;
|
||||
}
|
||||
if !lava {
|
||||
return false;
|
||||
}
|
||||
let b = &mut self.boats[i];
|
||||
b.fire_ticks = b.fire_ticks.max(300);
|
||||
let at = [b.position.x, b.position.y, b.position.z];
|
||||
let pitch = 2.0 + self.world.random.next_float() * 0.4;
|
||||
self.audio
|
||||
.play("minecraft:entity.generic.burn", Some(at), 0.4, pitch);
|
||||
self.hurt_boat(i, 4.0, false)
|
||||
}
|
||||
/// Whether a vehicle's box (deflated by 1e-5, as `applyEffectsFromBlocks`)
|
||||
/// is inside lava, and whether it touches water.
|
||||
pub(super) fn hull_fluids(&self, bb: Aabb) -> (bool, bool) {
|
||||
let (lo, hi) = (bb.min_position(), bb.max_position());
|
||||
let e = 1.0e-5;
|
||||
let (mut lava, mut water) = (false, false);
|
||||
for x in (lo.x + e).floor() as i32..=(hi.x - e).floor() as i32 {
|
||||
for y in (lo.y + e).floor() as i32..=(hi.y - e).floor() as i32 {
|
||||
for z in (lo.z + e).floor() as i32..=(hi.z - e).floor() as i32 {
|
||||
let f = self.res.facts().get(self.world.block(x, y, z));
|
||||
if f.fluid == Fluid::None {
|
||||
continue;
|
||||
}
|
||||
let above = self.res.facts().get(self.world.block(x, y + 1, z));
|
||||
let height = if above.fluid == f.fluid {
|
||||
1.0
|
||||
} else {
|
||||
f64::from(f.fluid_level) / 9.0
|
||||
};
|
||||
if lo.y + e < f64::from(y) + height {
|
||||
match f.fluid {
|
||||
Fluid::Lava => lava = true,
|
||||
Fluid::Water => water = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(lava, water)
|
||||
}
|
||||
/// The player's tick while riding: steer, tick the boat, sit in it.
|
||||
pub(super) fn tick_riding(&mut self, keys: Keys) -> horizon_client::Result<()> {
|
||||
@@ -489,6 +569,9 @@ impl Game<'_> {
|
||||
p.fall_distance = 0.0;
|
||||
}
|
||||
self.boats[i] = b;
|
||||
if self.boat_fire_tick(i) {
|
||||
self.riding = None;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
/// `getDismountLocationForPassenger`: in front of the player if there is
|
||||
@@ -534,7 +617,8 @@ impl Game<'_> {
|
||||
};
|
||||
let dir = view_vector(self.yaw, self.pitch);
|
||||
let reach = self.reach();
|
||||
// ClipContext.Fluid.ANY: the first water surface or block along the ray.
|
||||
// ClipContext.Fluid.ANY: the first fluid surface (water or lava) or
|
||||
// block along the ray.
|
||||
let block = self.pick().map(|h| {
|
||||
(
|
||||
h.point,
|
||||
@@ -544,7 +628,7 @@ impl Game<'_> {
|
||||
.sqrt(),
|
||||
)
|
||||
});
|
||||
let mut water = None;
|
||||
let mut fluid = None;
|
||||
let mut t = 0.0;
|
||||
while t < reach {
|
||||
let p: [f64; 3] = std::array::from_fn(|a| eye[a] + dir[a] * t);
|
||||
@@ -553,15 +637,15 @@ impl Game<'_> {
|
||||
p[1].floor() as i32,
|
||||
p[2].floor() as i32,
|
||||
);
|
||||
if let Some((h, _)) = self.fluid_height(x, y, z)
|
||||
if let Some((h, _)) = self.fluid_height_of(x, y, z, true)
|
||||
&& p[1] <= f64::from(y) + f64::from(h)
|
||||
{
|
||||
water = Some(([p[0], f64::from(y) + f64::from(h), p[2]], t));
|
||||
fluid = Some(([p[0], f64::from(y) + f64::from(h), p[2]], t));
|
||||
break;
|
||||
}
|
||||
t += 0.05;
|
||||
}
|
||||
let hit = match (block, water) {
|
||||
let hit = match (block, fluid) {
|
||||
(Some(b), Some(w)) => {
|
||||
if w.1 < b.1 {
|
||||
w.0
|
||||
@@ -682,15 +766,23 @@ impl Game<'_> {
|
||||
return false;
|
||||
}
|
||||
self.vehicle_attack_sounds();
|
||||
self.hurt_boat(i, damage, self.creative);
|
||||
self.swing_arm();
|
||||
true
|
||||
}
|
||||
/// `VehicleEntity.hurtServer`: wobble, add the damage and break past 40
|
||||
/// (`creative`: a creative player's hit removes it without drops).
|
||||
/// True when the boat was removed.
|
||||
pub(super) fn hurt_boat(&mut self, i: usize, damage: f32, creative: bool) -> bool {
|
||||
let b = &mut self.boats[i];
|
||||
b.hurt_dir = -b.hurt_dir;
|
||||
b.hurt_time = 10;
|
||||
b.damage += damage * 10.0;
|
||||
let destroyed = self.creative || b.damage > 40.0;
|
||||
let destroyed = creative || b.damage > 40.0;
|
||||
if destroyed {
|
||||
let b = self.boats.remove(i);
|
||||
let at = [b.position.x, b.position.y, b.position.z];
|
||||
if !self.creative && self.ui.rules.bool("entity_drops") {
|
||||
if !creative && self.ui.rules.bool("entity_drops") {
|
||||
// ChestBoat.destroy: chestVehicleDestroyed spills the contents.
|
||||
for stack in b.items.iter().flatten() {
|
||||
self.spawn_item(stack.clone(), at, super::dispenser::new_item_motion(), 10);
|
||||
@@ -709,8 +801,7 @@ impl Game<'_> {
|
||||
);
|
||||
}
|
||||
}
|
||||
self.swing_arm();
|
||||
true
|
||||
destroyed
|
||||
}
|
||||
/// AbstractBoatRenderer.
|
||||
pub(super) fn boat_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec<Vertex>) {
|
||||
|
||||
@@ -79,6 +79,8 @@ pub(super) struct Minecart {
|
||||
pub hurt_time: i32,
|
||||
pub hurt_dir: i32,
|
||||
pub damage: f32,
|
||||
/// `Entity.remainingFireTicks`: lava sets a cart alight for 15 seconds.
|
||||
pub fire_ticks: i32,
|
||||
pub items: Vec<Option<ItemStack>>,
|
||||
/// Furnace minecarts: fuel ticks and the push direction.
|
||||
pub fuel: i32,
|
||||
@@ -177,6 +179,7 @@ impl Minecart {
|
||||
hurt_time: 0,
|
||||
hurt_dir: 1,
|
||||
damage: 0.0,
|
||||
fire_ticks: 0,
|
||||
items: vec![None; kind.slots()],
|
||||
fuel: 0,
|
||||
push: [0.0; 2],
|
||||
@@ -823,6 +826,50 @@ impl Game<'_> {
|
||||
self.carts.remove(i);
|
||||
}
|
||||
}
|
||||
// applyEffectsFromBlocks runs on the server for every cart, the
|
||||
// ridden ones too.
|
||||
let ids: Vec<u32> = self.carts.iter().map(|c| c.id).collect();
|
||||
for id in ids {
|
||||
if let Some(i) = self.carts.iter().position(|c| c.id == id) {
|
||||
let p = self.carts[i].position;
|
||||
if ticking(p.x.floor() as i32, p.z.floor() as i32) {
|
||||
self.cart_fire_tick(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The fire half of `Entity.baseTick` and `LavaFluid.entityInside`
|
||||
/// (`lavaIgnite`, then `lavaHurt`) for one cart, through
|
||||
/// `VehicleEntity.hurtServer`: lava breaks a cart on its second tick in
|
||||
/// it, and primes a TNT minecart (`damageSourceIgnitesTnt`).
|
||||
fn cart_fire_tick(&mut self, i: usize) {
|
||||
let (lava, water) = self.hull_fluids(self.carts[i].bounds());
|
||||
let id = self.carts[i].id;
|
||||
let c = &mut self.carts[i];
|
||||
if water {
|
||||
c.fire_ticks = 0;
|
||||
}
|
||||
let mut burn = false;
|
||||
if c.fire_ticks > 0 {
|
||||
burn = c.fire_ticks % 20 == 0 && !lava;
|
||||
c.fire_ticks -= 1;
|
||||
}
|
||||
if burn {
|
||||
self.hurt_cart(i, 1.0, false, true);
|
||||
}
|
||||
if !lava {
|
||||
return;
|
||||
}
|
||||
let Some(i) = self.carts.iter().position(|c| c.id == id) else {
|
||||
return;
|
||||
};
|
||||
let c = &mut self.carts[i];
|
||||
c.fire_ticks = c.fire_ticks.max(300);
|
||||
let at = [c.position.x, c.position.y, c.position.z];
|
||||
let pitch = 2.0 + self.world.random.next_float() * 0.4;
|
||||
self.audio
|
||||
.play("minecraft:entity.generic.burn", Some(at), 0.4, pitch);
|
||||
self.hurt_cart(i, 4.0, false, true);
|
||||
}
|
||||
/// `ClientPacketListener.postAddEntitySoundInstance` for the carts that
|
||||
/// joined the level since the last tick, and `LocalPlayer.startRiding`'s
|
||||
|
||||
Reference in New Issue
Block a user