Striders stand on lava instead of bobbing in it (#256)
Striders fell into the generic fallback AI, whose FloatGoal jumped them up and down in lava. Port vanilla Strider: its goals (no FloatGoal, StriderGoToLavaGoal, RandomStrollGoal every 60 ticks, LookAtPlayerGoal for striders), floatStrider, standing on lava sources through the living collision context and the half-block liquid shape, travelling in air where lava holds it up, StriderPathNavigation's lava destinations, the walk target value, going cold (suffocating speed modifier, cold texture) away from warm blocks, the happy/retreat sounds and a lava-proof checkFallDamage. Mobs now keep Entity.mainSupportingBlockPos from their last move, as getBlockStateOnLegacy reads it. Mob AI parity harness: five strider scenarios, 5/5 match (1105/1105 mob-ticks; 0/5 and 5/1105 before). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,10 +10,10 @@ use horizon_world::{
|
||||
block_collision::{BlockCollisionRegistry, DynamicCollisionWorld, ShulkerCollisionState},
|
||||
block_collision_scan::{BlockCollisionWorld, CollisionBlock},
|
||||
collision::CachedCollisionRegistry,
|
||||
collision_context::CollisionContext,
|
||||
collision_context::{CollisionContext, CollisionEntity, CollisionItem},
|
||||
dynamic_support::DynamicSupportWorld,
|
||||
entity_obstruction::EntityIdentity,
|
||||
fluid::FluidState,
|
||||
fluid::{FluidKind, FluidState},
|
||||
liquid_collision::LiquidCollisionWorld,
|
||||
nbt::{self, Limits},
|
||||
powder_snow_collision::{PowderSnowEntity, PowderSnowWorld},
|
||||
@@ -39,8 +39,8 @@ pub fn load<'r>(root: &Path, registry: &'r BlockRegistry) -> Result<BlockCollisi
|
||||
Ok(BlockCollisionRegistry::new(Arc::new(cached))?)
|
||||
}
|
||||
|
||||
/// What powder snow's contextual collision asks of the colliding entity
|
||||
/// (`PowderSnowBlock.getCollisionShape`).
|
||||
/// What powder snow's and liquids' contextual collisions ask of the colliding
|
||||
/// entity (`PowderSnowBlock` and `LiquidBlock.getCollisionShape`).
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct PowderSnowSubject {
|
||||
pub fall_distance: f64,
|
||||
@@ -50,6 +50,13 @@ pub struct PowderSnowSubject {
|
||||
pub leather_boots: bool,
|
||||
/// `EntityTypeTags.POWDER_SNOW_WALKABLE_MOBS`.
|
||||
pub walkable_type: bool,
|
||||
/// A strider: lava sources hold it up (`canStandOnFluid`), on its
|
||||
/// `getLiquidCollisionShape`.
|
||||
pub lava_walker: bool,
|
||||
}
|
||||
/// `Strider.getLiquidCollisionShape`: `Block.column(16.0, 0.0, 8.0)`.
|
||||
fn strider_liquid_shape() -> VoxelShape {
|
||||
VoxelShape::from_cube([1, 2, 1], &[true, false]).expect("a valid half-block column")
|
||||
}
|
||||
|
||||
pub struct SceneCollisions<'w, 'r> {
|
||||
@@ -60,7 +67,8 @@ pub struct SceneCollisions<'w, 'r> {
|
||||
}
|
||||
impl SceneCollisions<'_, '_> {
|
||||
/// Position contexts permit geometric movement probes without inventing a
|
||||
/// player, inventory, effects or fluid-standing behavior.
|
||||
/// player, inventory, effects or fluid-standing behavior; a lava walker
|
||||
/// collides as the living entity it is, empty-handed.
|
||||
pub fn resolve(
|
||||
&mut self,
|
||||
bounds: Aabb,
|
||||
@@ -72,7 +80,7 @@ impl SceneCollisions<'_, '_> {
|
||||
self,
|
||||
MovementRequest {
|
||||
entity: EntityIdentity(0),
|
||||
context: CollisionContext::position(bounds.min_position().y),
|
||||
context: self.context(bounds),
|
||||
bounds,
|
||||
movement,
|
||||
max_step,
|
||||
@@ -81,6 +89,21 @@ impl SceneCollisions<'_, '_> {
|
||||
},
|
||||
)?)
|
||||
}
|
||||
fn context(&self, bounds: Aabb) -> CollisionContext<'static> {
|
||||
let y = bounds.min_position().y;
|
||||
if !self.subject.is_some_and(|s| s.lava_walker) {
|
||||
return CollisionContext::position(y);
|
||||
}
|
||||
CollisionContext::for_entity(
|
||||
CollisionEntity {
|
||||
identity: EntityIdentity(0),
|
||||
y,
|
||||
descending: false,
|
||||
main_hand: Some(CollisionItem::EMPTY),
|
||||
},
|
||||
false,
|
||||
)
|
||||
}
|
||||
pub fn unobstructed(&mut self, bounds: Aabb) -> Result<bool> {
|
||||
Ok(no_world_collision(
|
||||
self,
|
||||
@@ -180,9 +203,13 @@ impl DynamicCollisionWorld for SceneCollisions<'_, '_> {
|
||||
}
|
||||
impl LiquidCollisionWorld for SceneCollisions<'_, '_> {
|
||||
type Error = io::Error;
|
||||
/// Players and the supported mobs cannot stand on fluids (no striders).
|
||||
/// Only striders stand on fluids.
|
||||
fn entity_liquid_shape(&mut self, _: EntityIdentity) -> io::Result<VoxelShape> {
|
||||
Ok(VoxelShape::empty())
|
||||
Ok(if self.subject.is_some_and(|s| s.lava_walker) {
|
||||
strider_liquid_shape()
|
||||
} else {
|
||||
VoxelShape::empty()
|
||||
})
|
||||
}
|
||||
fn fluid(&mut self, p: BlockPos) -> io::Result<FluidState> {
|
||||
FluidState::from_block(
|
||||
@@ -192,8 +219,10 @@ impl LiquidCollisionWorld for SceneCollisions<'_, '_> {
|
||||
.ok_or_else(|| io::Error::other("scene fluid state outside registry"))?,
|
||||
)
|
||||
}
|
||||
fn entity_can_stand(&mut self, _: EntityIdentity, _: FluidState) -> io::Result<bool> {
|
||||
Ok(false)
|
||||
/// `Strider.canStandOnFluid`: lava.
|
||||
fn entity_can_stand(&mut self, _: EntityIdentity, fluid: FluidState) -> io::Result<bool> {
|
||||
Ok(self.subject.is_some_and(|s| s.lava_walker)
|
||||
&& matches!(fluid.kind(), FluidKind::Lava | FluidKind::FlowingLava))
|
||||
}
|
||||
}
|
||||
impl PowderSnowWorld for SceneCollisions<'_, '_> {
|
||||
|
||||
@@ -58,6 +58,7 @@ pub mod spawn_selection;
|
||||
pub mod spawner;
|
||||
pub mod spawning;
|
||||
pub mod species;
|
||||
pub mod strider;
|
||||
pub mod sulfur_cube;
|
||||
pub mod tame;
|
||||
pub mod trader;
|
||||
@@ -798,6 +799,9 @@ pub struct Mob {
|
||||
/// update (`isUnderWater` reads it).
|
||||
pub was_eye_in_water: bool,
|
||||
pub no_gravity: bool,
|
||||
/// `Entity.mainSupportingBlockPos`: the block it stood on after its last
|
||||
/// move.
|
||||
pub supporting: Option<[i32; 3]>,
|
||||
/// `NoAI`: no goals and no movement.
|
||||
pub no_ai: bool,
|
||||
/// `Silent`.
|
||||
@@ -1174,6 +1178,8 @@ pub struct Seen {
|
||||
pub player_rep: i32,
|
||||
/// `isPushable` and pushed by others (`Entity.push(Entity)` moves it).
|
||||
pub pushable: bool,
|
||||
/// A cold strider (`Strider.isSuffocating`).
|
||||
pub cold_strider: bool,
|
||||
/// `MobCategory` (`monster`, `creature`, ...).
|
||||
pub category: &'static str,
|
||||
/// A villager's `POTENTIAL_JOB_SITE` and `MEETING_POINT`.
|
||||
@@ -1248,6 +1254,7 @@ impl Mob {
|
||||
_ => 0,
|
||||
},
|
||||
pushable: m.pushable(),
|
||||
cold_strider: strider::suffocating(m),
|
||||
category: m.category(),
|
||||
potential_job: villager_brain::potential_job_site(m),
|
||||
meeting: villager.then_some(m.extra.meeting).flatten(),
|
||||
@@ -1461,6 +1468,7 @@ impl Mob {
|
||||
fluids: living::Fluids::default(),
|
||||
was_eye_in_water: false,
|
||||
no_gravity: false,
|
||||
supporting: None,
|
||||
no_ai: false,
|
||||
silent: false,
|
||||
invulnerable_flag: false,
|
||||
@@ -1707,7 +1715,7 @@ impl Mob {
|
||||
/// Movement speed attribute bonus (baby zombies, sprinting modifiers).
|
||||
/// MOVEMENT_SPEED including effects (speed +20%/level, slowness -15%/level).
|
||||
pub fn movement_speed(&self) -> f64 {
|
||||
let mut v = self.attrs.speed * self.speed_bonus();
|
||||
let mut v = strider::movement_speed(self, self.attrs.speed) * self.speed_bonus();
|
||||
for (e, _, amp) in &self.extra.effects {
|
||||
match *e {
|
||||
"minecraft:speed" => v *= 1.0 + 0.2 * f64::from(amp + 1),
|
||||
|
||||
@@ -103,6 +103,7 @@ pub enum Family {
|
||||
Creaking,
|
||||
/// Nautili and zombie nautili.
|
||||
Nautilus,
|
||||
Strider,
|
||||
}
|
||||
pub fn family(s: Species) -> Family {
|
||||
use Species as S;
|
||||
@@ -161,6 +162,7 @@ pub fn family(s: Species) -> Family {
|
||||
S::Guardian | S::ElderGuardian => Family::Guardian,
|
||||
S::Warden => Family::Warden,
|
||||
S::Shulker => Family::Shulker,
|
||||
S::Strider => Family::Strider,
|
||||
_ => Family::Generic,
|
||||
}
|
||||
}
|
||||
@@ -215,6 +217,7 @@ pub fn register(m: &mut Mob) {
|
||||
Family::Warden => super::warden::register(m),
|
||||
Family::Creaking => super::creaking::register(m),
|
||||
Family::Nautilus => super::nautilus::register(m),
|
||||
Family::Strider => super::strider::register(m),
|
||||
}
|
||||
}
|
||||
/// Mob.tick additions that run before the entity tick (creeper fuse, puffing).
|
||||
@@ -358,6 +361,9 @@ pub fn tick(
|
||||
return false;
|
||||
}
|
||||
super::warden::pre_tick(m, w, events);
|
||||
if m.species() == Species::Strider {
|
||||
super::strider::pre_tick(m, w, events);
|
||||
}
|
||||
base_tick(m, w, events);
|
||||
if m.species() == Species::Rabbit {
|
||||
super::rabbit::base_tick(m);
|
||||
@@ -389,6 +395,9 @@ pub fn tick(
|
||||
// CopperGolem.tick: updateWeathering after the living tick.
|
||||
super::copper_golem::update_weathering(m, w, level_random, events);
|
||||
}
|
||||
if m.species() == Species::Strider {
|
||||
super::strider::float(m, w);
|
||||
}
|
||||
true
|
||||
}
|
||||
/// LivingEntity.updateSwingTime (6-tick swing duration).
|
||||
@@ -555,6 +564,8 @@ fn play_ambient(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
Species::Axolotl if !m.fluids.in_water => "entity.axolotl.idle_air",
|
||||
Species::Bat if m.extra.flag && m.random.next_int_bound(4).unwrap_or(1) != 0 => return,
|
||||
Species::Allay if m.extra.main_hand.is_some() => "entity.allay.ambient_with_item",
|
||||
// Strider.getAmbientSound: quiet while panicking or tempted.
|
||||
Species::Strider if m.ai.panicking || m.ai.goals.is_running("Tempt") => return,
|
||||
// HappyGhast: its own voice, never pitched up.
|
||||
Species::HappyGhast => {
|
||||
let sound = super::happy_ghast::sounds(m)[0];
|
||||
@@ -1162,6 +1173,9 @@ pub fn walk_target_value(m: &Mob, w: &MobWorld, p: [i32; 3]) -> f32 {
|
||||
5.0
|
||||
};
|
||||
}
|
||||
if m.species() == Species::Strider {
|
||||
return super::strider::walk_target_value(m, w, p);
|
||||
}
|
||||
// AbstractNautilus and Creaking.getWalkTargetValue: everywhere alike.
|
||||
if matches!(
|
||||
m.species(),
|
||||
|
||||
@@ -796,6 +796,8 @@ pub struct LookAtPlayer {
|
||||
pub only_horizontal: bool,
|
||||
/// `LookAtPlayerGoal(Mob.class, ...)`: the nearest mob, not the player.
|
||||
pub mobs: bool,
|
||||
/// `LookAtPlayerGoal(Strider.class, ...)`: only mobs of this species.
|
||||
pub only: Option<Species>,
|
||||
/// InteractGoal: LOOK and MOVE.
|
||||
pub interact: bool,
|
||||
look_at: Option<Who>,
|
||||
@@ -808,6 +810,7 @@ impl LookAtPlayer {
|
||||
probability: 0.02,
|
||||
only_horizontal: false,
|
||||
mobs: false,
|
||||
only: None,
|
||||
interact: false,
|
||||
look_at: None,
|
||||
look_time: 0,
|
||||
@@ -820,6 +823,13 @@ impl LookAtPlayer {
|
||||
..Self::new(range)
|
||||
}
|
||||
}
|
||||
/// `LookAtPlayerGoal(this, <species class>, range)`.
|
||||
pub fn species(species: Species, range: f32) -> Self {
|
||||
Self {
|
||||
only: Some(species),
|
||||
..Self::mobs(range)
|
||||
}
|
||||
}
|
||||
/// `InteractGoal(this, Player.class, range, probability)`.
|
||||
pub fn interact(range: f32, probability: f32) -> Self {
|
||||
Self {
|
||||
@@ -873,12 +883,13 @@ impl Goal for LookAtPlayer {
|
||||
}
|
||||
// level.getNearestEntity(mobs in the box inflated by (range, 3, range)).
|
||||
let area = m.bounds().inflate(Vec3::new(range, 3.0, range));
|
||||
let id = m.id;
|
||||
let (id, only) = (m.id, self.only);
|
||||
let at = Vec3::new(m.position.x, m.eye_y(), m.position.z);
|
||||
let candidates: Vec<(u32, Vec3)> =
|
||||
cx.w.others
|
||||
.iter()
|
||||
.filter(|s| s.id != id && s.alive && s.bounds.intersects(area))
|
||||
.filter(|s| only.is_none_or(|o| s.species == o))
|
||||
.map(|s| (s.id, s.position))
|
||||
.collect();
|
||||
let mut best: Option<(u32, f64)> = None;
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
//! fluid slowdown and falling adjustment), fluid immersion heights, fall
|
||||
//! damage, fire and the walk animation.
|
||||
use super::{Mob, MobEvent, MobWorld};
|
||||
use crate::{blocks::Fluid, collisions::SceneCollisions};
|
||||
use crate::{
|
||||
blocks::Fluid,
|
||||
collisions::{PowderSnowSubject, SceneCollisions},
|
||||
};
|
||||
use horizon_core::{
|
||||
geometry::{Aabb, Vec3, trig},
|
||||
random::RandomSource,
|
||||
@@ -313,7 +316,11 @@ impl Mob {
|
||||
let mut scene = SceneCollisions {
|
||||
world: w.world,
|
||||
binding: w.collision,
|
||||
subject: None,
|
||||
subject: self.kind.flags.lava_walker.then(|| PowderSnowSubject {
|
||||
fall_distance: self.fall_distance,
|
||||
lava_walker: true,
|
||||
..Default::default()
|
||||
}),
|
||||
};
|
||||
let moved = scene
|
||||
.resolve(self.bounds(), wanted, step, self.on_ground)
|
||||
@@ -338,23 +345,12 @@ impl Mob {
|
||||
let vertical = wanted.y != moved.y;
|
||||
self.vertical_collision_below = vertical && wanted.y < 0.0;
|
||||
self.on_ground = self.vertical_collision_below;
|
||||
// LivingEntity.checkFallDamage refreshes the fluid state out of water
|
||||
// (touching water resets the fall).
|
||||
if !self.fluids.in_water {
|
||||
self.fluids = w.fluids(self.bounds(), self.eye_y());
|
||||
if self.fluids.in_water {
|
||||
self.fall_distance = 0.0;
|
||||
}
|
||||
}
|
||||
// Entity.checkFallDamage
|
||||
if !self.fluids.in_water && moved.y < 0.0 {
|
||||
self.fall_distance -= f64::from(moved.y as f32);
|
||||
}
|
||||
if self.on_ground {
|
||||
if self.fall_distance > 0.0 {
|
||||
self.cause_fall_damage(events);
|
||||
}
|
||||
// Strider.checkFallDamage: lava breaks any fall, and the fluid state
|
||||
// waits for the next baseTick.
|
||||
if self.kind.flags.lava_walker && self.fluids.in_lava {
|
||||
self.fall_distance = 0.0;
|
||||
} else {
|
||||
self.check_fall_damage(w, moved, events);
|
||||
}
|
||||
// restituteMovementAfterCollisions with no bounciness: the colliding
|
||||
// components become (signed) zero.
|
||||
@@ -370,8 +366,29 @@ impl Mob {
|
||||
self.velocity.y = (0.0 - v.y) * 1.0 * 0.0;
|
||||
}
|
||||
}
|
||||
// Entity.checkSupportingBlock
|
||||
self.supporting = self.supporting_block(w, moved);
|
||||
self.movement_emission(w, moved, events);
|
||||
}
|
||||
/// LivingEntity.checkFallDamage: the fluid state refreshed out of water
|
||||
/// (touching water resets the fall), then Entity.checkFallDamage.
|
||||
fn check_fall_damage(&mut self, w: &MobWorld, moved: Vec3, events: &mut Vec<MobEvent>) {
|
||||
if !self.fluids.in_water {
|
||||
self.fluids = w.fluids(self.bounds(), self.eye_y());
|
||||
if self.fluids.in_water {
|
||||
self.fall_distance = 0.0;
|
||||
}
|
||||
}
|
||||
if !self.fluids.in_water && moved.y < 0.0 {
|
||||
self.fall_distance -= f64::from(moved.y as f32);
|
||||
}
|
||||
if self.on_ground {
|
||||
if self.fall_distance > 0.0 {
|
||||
self.cause_fall_damage(events);
|
||||
}
|
||||
self.fall_distance = 0.0;
|
||||
}
|
||||
}
|
||||
/// Entity.applyMovementEmissionAndPlaySound: walked distance, footsteps
|
||||
/// and swimming sounds.
|
||||
fn movement_emission(&mut self, w: &MobWorld, moved: Vec3, events: &mut Vec<MobEvent>) {
|
||||
@@ -381,7 +398,7 @@ impl Mob {
|
||||
let full = (moved.length() * f64::from(0.6_f32)) as f32;
|
||||
let horizontal =
|
||||
((moved.x * moved.x + moved.z * moved.z).sqrt() * f64::from(0.6_f32)) as f32;
|
||||
let supporting = self.supporting_block(w, moved);
|
||||
let supporting = self.supporting;
|
||||
let on = self.supported_on_pos(w, supporting, 1.0e-5);
|
||||
let state = w.world.block(on[0], on[1], on[2]);
|
||||
let climbable = w.facts.get(state).name.as_ref() == "minecraft:powder_snow"
|
||||
@@ -439,11 +456,13 @@ impl Mob {
|
||||
}
|
||||
}
|
||||
/// `Entity.nextStep`: the next whole metre walked; a warden's steps come
|
||||
/// every 0.55.
|
||||
/// every 0.55, a strider's every 0.6.
|
||||
fn next_step(&self) -> f32 {
|
||||
let walked = self.ai.steps.move_dist;
|
||||
if self.kind.species == super::Species::Warden {
|
||||
walked + 0.55
|
||||
} else if self.kind.species == super::Species::Strider {
|
||||
walked + 0.6
|
||||
} else {
|
||||
(walked as i32).wrapping_add(1) as f32
|
||||
}
|
||||
@@ -482,6 +501,11 @@ impl Mob {
|
||||
w.supporting_block(shifted, self.position)
|
||||
})
|
||||
}
|
||||
/// `Entity.getBlockStateOnLegacy`'s position: 0.2 below the feet, or the
|
||||
/// supporting block.
|
||||
pub(super) fn block_on_legacy(&self, w: &MobWorld) -> [i32; 3] {
|
||||
self.supported_on_pos(w, self.supporting, 0.2)
|
||||
}
|
||||
/// `Entity.getOnPos(offset)` with a supporting block: its column (its
|
||||
/// own position for fences, walls and gates up to half a block down).
|
||||
fn supported_on_pos(
|
||||
@@ -575,7 +599,13 @@ impl Mob {
|
||||
if self.kind.flags.flying {
|
||||
return self.travel_flying(w, input, events);
|
||||
}
|
||||
let stands_on_fluid = self.kind.flags.lava_walker && self.fluids.in_lava;
|
||||
// shouldTravelInFluid: not where the fluid at its feet holds it up.
|
||||
let (x, y, z) = (
|
||||
self.position.x.floor() as i32,
|
||||
self.position.y.floor() as i32,
|
||||
self.position.z.floor() as i32,
|
||||
);
|
||||
let stands_on_fluid = self.kind.flags.lava_walker && w.fluid(x, y, z) == Fluid::Lava;
|
||||
if self.is_in_liquid() && self.affected_by_fluids() && !stands_on_fluid {
|
||||
self.travel_in_fluid(w, input, events);
|
||||
} else {
|
||||
|
||||
@@ -562,6 +562,10 @@ impl Mob {
|
||||
}
|
||||
/// PathNavigation.isStableDestination for the mob's navigation.
|
||||
pub fn stable_destination(&self, w: &MobWorld, p: [i32; 3]) -> bool {
|
||||
// StriderPathNavigation: lava too.
|
||||
if self.kind.flags.lava_walker && w.block_name(p[0], p[1], p[2]) == "minecraft:lava" {
|
||||
return true;
|
||||
}
|
||||
match self.ai.nav.kind {
|
||||
NavKind::Ground | NavKind::WallClimber => {
|
||||
w.facts
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
//! Striders (`Strider`): their goals, standing and floating on lava
|
||||
//! (`floatStrider`, `canStandOnFluid`), going cold away from warm blocks
|
||||
//! (`setSuffocating`) and heading back to lava (`StriderGoToLavaGoal`).
|
||||
//! `extra.flag` is the synced `DATA_SUFFOCATING`.
|
||||
use super::{
|
||||
Mob, MobEvent, MobWorld, Species,
|
||||
data::LAND,
|
||||
goals::{
|
||||
Breed, Cx, FollowParent, Goal, JUMP, LookAtPlayer, MOVE, MoveToBlock, Panic,
|
||||
RandomLookAround, Stroll, Tempt, goal_clone, reduced,
|
||||
},
|
||||
path::PathType,
|
||||
};
|
||||
use crate::blocks::Fluid;
|
||||
use horizon_core::random::RandomSource;
|
||||
|
||||
/// `SUFFOCATING_MODIFIER`: `-0.34F`, `ADD_MULTIPLIED_BASE`.
|
||||
const SUFFOCATING: f64 = -0.34_f32 as f64;
|
||||
|
||||
pub fn register(m: &mut Mob) {
|
||||
m.set_malus(PathType::Water, -1.0);
|
||||
m.set_malus(PathType::Lava, 0.0);
|
||||
m.set_malus(PathType::FireInNeighbor, 0.0);
|
||||
m.set_malus(PathType::Fire, 0.0);
|
||||
let tempt = m.kind.tempt.clone();
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(1, Panic::new(1.65));
|
||||
g.add(2, Breed::new(1.0));
|
||||
g.add(3, Tempt::new(1.4, tempt, false));
|
||||
g.add(4, GoToLava(MoveToBlock::new(1.0, 8, 2)));
|
||||
g.add(5, FollowParent::new(1.0));
|
||||
g.add(7, Stroll::new(1.0).interval(60));
|
||||
g.add(8, LookAtPlayer::new(8.0));
|
||||
g.add(8, RandomLookAround::default());
|
||||
g.add(9, LookAtPlayer::species(Species::Strider, 8.0));
|
||||
}
|
||||
pub fn suffocating(m: &Mob) -> bool {
|
||||
m.species() == Species::Strider && m.extra.flag
|
||||
}
|
||||
/// The movement speed attribute with `SUFFOCATING_MODIFIER` while cold.
|
||||
pub fn movement_speed(m: &Mob, base: f64) -> f64 {
|
||||
if suffocating(m) {
|
||||
base + base * SUFFOCATING
|
||||
} else {
|
||||
base
|
||||
}
|
||||
}
|
||||
/// `Strider.tick` before `super.tick()`: the tempted and retreating sounds,
|
||||
/// then cold unless in or on a warm block or riding a warm strider.
|
||||
pub fn pre_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if m.ai.goals.is_running("Tempt") && m.random.next_int_bound(140).unwrap_or(1) == 0 {
|
||||
m.voice("entity.strider.happy", events);
|
||||
} else if m.ai.panicking && m.random.next_int_bound(60).unwrap_or(1) == 0 {
|
||||
m.voice("entity.strider.retreat", events);
|
||||
}
|
||||
if m.no_ai {
|
||||
return;
|
||||
}
|
||||
let warm = |p: [i32; 3]| {
|
||||
w.has_tag(
|
||||
"minecraft:strider_warm_blocks",
|
||||
w.block_name(p[0], p[1], p[2]),
|
||||
)
|
||||
};
|
||||
let inside = [
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
];
|
||||
let in_warm = warm(inside) || warm(m.block_on_legacy(w)) || m.fluids.lava > 0.0;
|
||||
let on_warm_strider = m
|
||||
.extra
|
||||
.mount
|
||||
.and_then(|id| w.seen(id))
|
||||
.is_some_and(|v| v.species == Species::Strider && !v.cold_strider);
|
||||
m.extra.flag = !in_warm && !on_warm_strider;
|
||||
}
|
||||
/// `Strider.floatStrider`, after the living tick: standing on the surface of
|
||||
/// lava, or bobbing up through it.
|
||||
pub fn float(m: &mut Mob, w: &MobWorld) {
|
||||
if !m.fluids.in_lava {
|
||||
return;
|
||||
}
|
||||
let (x, y, z) = (
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
);
|
||||
// `CollisionContext.isAbove(getLiquidCollisionShape(), blockPosition())`:
|
||||
// the column is half a block tall.
|
||||
let above = m.position.y > f64::from(y) + 0.5 - f64::from(1.0e-5_f32);
|
||||
if above && w.fluid(x, y + 1, z) != Fluid::Lava {
|
||||
m.on_ground = true;
|
||||
} else {
|
||||
let v = m.velocity;
|
||||
m.velocity = horizon_core::geometry::Vec3::new(v.x * 0.5, v.y * 0.5 + 0.05, v.z * 0.5);
|
||||
}
|
||||
}
|
||||
/// `Strider.getWalkTargetValue`.
|
||||
pub fn walk_target_value(m: &Mob, w: &MobWorld, p: [i32; 3]) -> f32 {
|
||||
if w.fluid(p[0], p[1], p[2]) == Fluid::Lava {
|
||||
10.0
|
||||
} else if m.fluids.in_lava {
|
||||
f32::NEG_INFINITY
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
/// `StriderGoToLavaGoal.isValidTarget`: lava with room to stand above.
|
||||
fn lava_target(w: &MobWorld, p: [i32; 3]) -> bool {
|
||||
w.block_name(p[0], p[1], p[2]) == "minecraft:lava"
|
||||
&& w.data.state(w.world.block(p[0], p[1] + 1, p[2])).flags & LAND != 0
|
||||
}
|
||||
/// `Strider.StriderGoToLavaGoal`: a `MoveToBlockGoal` for the nearest lava,
|
||||
/// aiming at the lava block itself rather than the one above.
|
||||
#[derive(Clone, Debug)]
|
||||
struct GoToLava(MoveToBlock);
|
||||
impl Goal for GoToLava {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE | JUMP
|
||||
}
|
||||
fn name(&self) -> &'static str {
|
||||
"StriderGoToLavaGoal"
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
if m.fluids.in_lava {
|
||||
return false;
|
||||
}
|
||||
if self.0.next_start > 0 {
|
||||
self.0.next_start -= 1;
|
||||
return false;
|
||||
}
|
||||
self.0.next_start = reduced(200 + m.random.next_int_bound(200).unwrap_or(0));
|
||||
self.0.find_nearest(m, cx.w, lava_target)
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
!m.fluids.in_lava && lava_target(cx.w, self.0.block)
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
self.0.start(m, cx.w);
|
||||
}
|
||||
/// `MoveToBlockGoal.tick` towards `getMoveToTarget()` (the lava block),
|
||||
/// recomputing the path every 20 ticks (`shouldRecalculatePath`).
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let b = self.0.block;
|
||||
let center = [
|
||||
f64::from(b[0]) + 0.5,
|
||||
f64::from(b[1]) + 0.5,
|
||||
f64::from(b[2]) + 0.5,
|
||||
];
|
||||
let d2 = (m.position.x - center[0]).powi(2)
|
||||
+ (m.position.y - center[1]).powi(2)
|
||||
+ (m.position.z - center[2]).powi(2);
|
||||
if d2 >= 1.0 {
|
||||
self.0.reached = false;
|
||||
self.0.try_ticks += 1;
|
||||
if self.0.try_ticks % 20 == 0 {
|
||||
let speed = self.0.speed;
|
||||
m.nav_move_to(cx.w, [center[0], f64::from(b[1]), center[2]], speed);
|
||||
}
|
||||
} else {
|
||||
self.0.reached = true;
|
||||
self.0.try_ticks -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -423,6 +423,7 @@ impl PlayerMotion {
|
||||
falling_block: false,
|
||||
leather_boots: self.leather_boots,
|
||||
walkable_type: false,
|
||||
lava_walker: false,
|
||||
}
|
||||
}
|
||||
/// `LivingEntity.tryAddFrost`: the frozen slowdown, on anything but air.
|
||||
|
||||
@@ -218,6 +218,16 @@ def scenarios():
|
||||
f'mob minecraft:{species} 0.5 -60 0.5 0 {seed} persistent{baby}',
|
||||
f'feed 20 0 minecraft:{food}', f'feed 40 0 minecraft:{food}',
|
||||
])
|
||||
# Striders: standing on a lava pool (floatStrider), walking from cold grass to it
|
||||
# (StriderGoToLavaGoal, suffocating), and drawn by a player holding warped fungus.
|
||||
LAVA = 'fill -5 -63 -5 5 -61 5 minecraft:lava'
|
||||
add('strider_lava', 200, [LAVA, 'mob minecraft:strider 0.5 -61 0.5 0 131 persistent'])
|
||||
add('strider_lava_player', 200, [LAVA, 'player 8.5 -60 0.5',
|
||||
'mob minecraft:strider -1.5 -61 0.5 90 132 persistent'])
|
||||
add('strider_shore', 300, [LAVA, 'mob minecraft:strider 9.5 -60 0.5 90 133 persistent'])
|
||||
add('strider_cold', 200, ['mob minecraft:strider 0.5 -60 0.5 0 134 persistent'])
|
||||
add('strider_tempted', 200, [LAVA, 'player 9.5 -60 0.5 hand=minecraft:warped_fungus',
|
||||
'mob minecraft:strider 0.5 -61 0.5 0 135 persistent'])
|
||||
return s
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user