Bees fly, pollinate flowers, get angry and sting (#208)
A port of vanilla 26.3 Bee: FlyingMoveControl and flying navigation, hover wandering, flower search and pollination (nectar), growing crops, tempting and breeding, persistent anger with the hurt-by alert, the sting (poison, stinger lost, later death), drowning, staying home at night and in rain, roll, textures and NBT. Hives as homes are not simulated yet. FlyingMoveControl clamps the pitch like Entity.setXRot, so a rotlerp that wraps to 359 gives 90 as in vanilla. Mob AI parity: 9 bee scenarios, 3609/3609 ticks; full harness 120/120. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -470,7 +470,7 @@ fn player_hurt(player: Option<&PlayerView>, e: &MobEvent) -> bool {
|
||||
|
||||
/// `player_down`: the scenario's player is no valid target (creative, or
|
||||
/// killed this tick).
|
||||
fn print(out: &mut String, t: i32, i: usize, m: &Mob, player_down: bool) {
|
||||
fn print(out: &mut String, t: i32, i: usize, m: &Mob, player_down: bool, now: i64) {
|
||||
let _ = write!(out, "{t} {i}");
|
||||
if m.removed {
|
||||
// Entity.RemovalReason: the end of the death animation, else a discard.
|
||||
@@ -589,6 +589,21 @@ fn print(out: &mut String, t: i32, i: usize, m: &Mob, player_down: bool) {
|
||||
.map_or("-".into(), |p| format!("{},{},{}", p[0], p[1], p[2]));
|
||||
let _ = write!(out, "\tcg {} {held} {opened}", m.extra.variant3);
|
||||
}
|
||||
if let Some(b) = horizon_client::mobs::bee::get(m) {
|
||||
let anger = if b.anger_end > 0 {
|
||||
b.anger_end - now
|
||||
} else {
|
||||
-1
|
||||
};
|
||||
let flower = b
|
||||
.flower
|
||||
.map_or("-".into(), |p| format!("{},{},{}", p[0], p[1], p[2]));
|
||||
let _ = write!(
|
||||
out,
|
||||
"\tbee {} {anger} {} {} {flower}",
|
||||
b.flags, b.ticks_without_nectar, b.flower_cooldown
|
||||
);
|
||||
}
|
||||
out.push('\n');
|
||||
}
|
||||
|
||||
@@ -835,6 +850,10 @@ fn main() -> horizon_client::Result<()> {
|
||||
}
|
||||
}
|
||||
m.random = LegacyRandom::new(spec.seed);
|
||||
if m.species() == Species::Bee {
|
||||
// The oracle draws the constructor's cooldowns again once seeded.
|
||||
horizon_client::mobs::bee::draw_cooldowns(&mut m);
|
||||
}
|
||||
if horizon_client::mobs::monster_brain::has_brain(m.species()) {
|
||||
// The oracle delays the sensors again with the seeded random
|
||||
// and seeds RunOne's shuffles with the mob's seed.
|
||||
@@ -902,7 +921,7 @@ fn main() -> horizon_client::Result<()> {
|
||||
// from it, and the scenarios feed neither.
|
||||
let mut level_random = LegacyRandom::new(0);
|
||||
for (i, m) in mobs.iter().enumerate() {
|
||||
print(&mut out, 0, i, m, s.creative);
|
||||
print(&mut out, 0, i, m, s.creative, world.game_time);
|
||||
}
|
||||
// The MobWorld every step sees, over a snapshot of the mobs.
|
||||
macro_rules! mob_world {
|
||||
@@ -1152,7 +1171,14 @@ fn main() -> horizon_client::Result<()> {
|
||||
.iter()
|
||||
.any(|e| player_hurt(player.as_ref(), e) && player_damage(e) >= 20.0);
|
||||
for (i, m) in mobs.iter().enumerate() {
|
||||
print(&mut out, t, i, m, s.creative || player_killed);
|
||||
print(
|
||||
&mut out,
|
||||
t,
|
||||
i,
|
||||
m,
|
||||
s.creative || player_killed,
|
||||
world.game_time,
|
||||
);
|
||||
}
|
||||
for e in &events {
|
||||
if let MobEvent::Sound(name, _, volume, pitch) = e {
|
||||
|
||||
@@ -389,6 +389,7 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
crate::mobs::nautilus::to_nbt(m, map);
|
||||
}
|
||||
"minecraft:sulfur_cube" => crate::mobs::sulfur_cube::to_nbt(m, map),
|
||||
"minecraft:bee" => crate::mobs::bee::to_nbt(m, map),
|
||||
"minecraft:sniffer" => crate::mobs::sniffer::to_nbt(m, map),
|
||||
"minecraft:wither" => {
|
||||
map.insert("Invul".into(), Tag::Int(m.extra.counter));
|
||||
@@ -768,6 +769,9 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
if m.species() == crate::mobs::Species::SulfurCube {
|
||||
crate::mobs::sulfur_cube::from_nbt(&mut m, tag);
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Bee {
|
||||
crate::mobs::bee::from_nbt(&mut m, tag);
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Creaking
|
||||
&& let Some(Tag::IntArray(home)) = tag.get("home_pos")
|
||||
&& home.len() == 3
|
||||
|
||||
@@ -12,6 +12,7 @@ pub mod animal_brain;
|
||||
pub mod aquatic;
|
||||
pub mod axolotl;
|
||||
pub mod bat;
|
||||
pub mod bee;
|
||||
pub mod body_anim;
|
||||
pub mod brain;
|
||||
pub mod breeze;
|
||||
@@ -755,6 +756,8 @@ pub struct Extra {
|
||||
pub lone: bool,
|
||||
/// A breeze's or creaking's brain (`monster_brain`).
|
||||
pub brain: Option<Box<monster_brain::Brain>>,
|
||||
/// A bee's nectar, anger, flower and hive state.
|
||||
pub bee: Option<Box<bee::Bee>>,
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Mob {
|
||||
|
||||
@@ -105,6 +105,7 @@ pub enum Family {
|
||||
Nautilus,
|
||||
Strider,
|
||||
Bat,
|
||||
Bee,
|
||||
}
|
||||
pub fn family(s: Species) -> Family {
|
||||
use Species as S;
|
||||
@@ -165,6 +166,7 @@ pub fn family(s: Species) -> Family {
|
||||
S::Shulker => Family::Shulker,
|
||||
S::Strider => Family::Strider,
|
||||
S::Bat => Family::Bat,
|
||||
S::Bee => Family::Bee,
|
||||
_ => Family::Generic,
|
||||
}
|
||||
}
|
||||
@@ -221,6 +223,7 @@ pub fn register(m: &mut Mob) {
|
||||
Family::Nautilus => super::nautilus::register(m),
|
||||
Family::Strider => super::strider::register(m),
|
||||
Family::Bat => super::bat::register(m),
|
||||
Family::Bee => super::bee::register(m),
|
||||
}
|
||||
}
|
||||
/// Mob.tick additions that run before the entity tick (creeper fuse, puffing).
|
||||
@@ -404,6 +407,9 @@ pub fn tick(
|
||||
if m.species() == Species::Bat {
|
||||
super::bat::tick(m);
|
||||
}
|
||||
if m.species() == Species::Bee {
|
||||
super::bee::tick(m, level_random);
|
||||
}
|
||||
true
|
||||
}
|
||||
/// LivingEntity.updateSwingTime (6-tick swing duration).
|
||||
@@ -859,7 +865,8 @@ fn server_ai_step(
|
||||
// A creaking looked at stands still: its navigation, move, look and jump
|
||||
// controls wait (CreakingPathNavigation and the Creaking*Control).
|
||||
let frozen = super::creaking::is_creaking(m) && !super::creaking::can_move(m);
|
||||
if !frozen {
|
||||
// The bee's navigation waits while it pollinates.
|
||||
if !frozen && !super::bee::pollinating(m) {
|
||||
m.nav_tick(w);
|
||||
}
|
||||
if super::monster_brain::has_brain(m.species()) {
|
||||
@@ -894,7 +901,10 @@ fn server_ai_step(
|
||||
}
|
||||
if !super::axolotl::is_playing_dead(m) {
|
||||
m.move_control_tick(w, events);
|
||||
m.look_control_tick();
|
||||
// BeeLookControl: still while angry.
|
||||
if !(m.species() == Species::Bee && super::bee::angry(m, w)) {
|
||||
m.look_control_tick();
|
||||
}
|
||||
}
|
||||
m.jump_control_tick();
|
||||
}
|
||||
@@ -919,6 +929,7 @@ fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
// SpellcasterIllager.customServerAiStep.
|
||||
Species::Evoker if m.extra.counter > 0 => m.extra.counter -= 1,
|
||||
Species::Bat => super::bat::server_ai_step(m, cx.w, cx.events),
|
||||
Species::Bee => super::bee::server_ai_step(m, cx),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -944,6 +955,7 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
Species::Ravager => super::ravager::ai_step(m, w, events),
|
||||
Species::Wither => super::wither::ai_step(m, w, events),
|
||||
Species::Allay => super::allay::ai_step(m),
|
||||
Species::Bee => super::bee::ai_step(m, w),
|
||||
Species::Breeze => super::breeze::ai_step(m),
|
||||
Species::Sniffer => super::sniffer::ai_step(m, events),
|
||||
Species::HappyGhast => super::happy_ghast::ai_step(m, w),
|
||||
@@ -1183,6 +1195,14 @@ pub fn walk_target_value(m: &Mob, w: &MobWorld, p: [i32; 3]) -> f32 {
|
||||
if m.species() == Species::Strider {
|
||||
return super::strider::walk_target_value(m, w, p);
|
||||
}
|
||||
// Bee.getWalkTargetValue: any air block.
|
||||
if m.species() == Species::Bee {
|
||||
return if w.facts.is_air(w.world.block(p[0], p[1], p[2])) {
|
||||
10.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
}
|
||||
// AbstractNautilus and Creaking.getWalkTargetValue: everywhere alike.
|
||||
if matches!(
|
||||
m.species(),
|
||||
@@ -1221,6 +1241,10 @@ pub fn accepts_damage(m: &mut Mob, source: &Damage, _amount: f32) -> bool {
|
||||
super::bat::hurt(m);
|
||||
true
|
||||
}
|
||||
Species::Bee => {
|
||||
super::bee::hurt(m);
|
||||
true
|
||||
}
|
||||
Species::Enderman => super::enderman::on_damage(m, source),
|
||||
Species::WitherSkeleton | Species::Blaze | Species::MagmaCube | Species::Strider
|
||||
if source.is_fire() =>
|
||||
@@ -1258,6 +1282,9 @@ pub fn do_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
if m.species() == Species::IronGolem {
|
||||
return super::golem::iron_hurt_target(m, who, cx);
|
||||
}
|
||||
if m.species() == Species::Bee {
|
||||
return super::bee::sting(m, who, cx);
|
||||
}
|
||||
if matches!(m.species(), Species::Hoglin | Species::Zoglin) {
|
||||
return super::piglin::hoglin_hurt_target(m, who, cx);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -993,10 +993,13 @@ pub fn anim(m: &Mob, s: &State, p: &mut Poses, a: &Animations) -> bool {
|
||||
p,
|
||||
s,
|
||||
&Bee {
|
||||
has_stinger: true,
|
||||
on_ground: m.on_ground,
|
||||
angry: m.extra.anger > 0,
|
||||
roll_amount: 0.0,
|
||||
has_stinger: !super::bee::has_stung(m),
|
||||
on_ground: m.on_ground && m.velocity.length_squared() < 1.0e-7,
|
||||
// The anger end time is cleared the tick after it passes.
|
||||
angry: super::bee::get(m).is_some_and(|b| b.anger_end > 0),
|
||||
// Bee.getRollAmount(partialTick).
|
||||
roll_amount: super::bee::get(m)
|
||||
.map_or(0.0, |b| b.roll_o + (b.roll - b.roll_o) * s.partial),
|
||||
},
|
||||
),
|
||||
Species::Bat => bat(p, s, m.extra.flag, &st[0], &st[1], a),
|
||||
|
||||
@@ -167,7 +167,9 @@ impl Mob {
|
||||
let sd = (xd * xd + zd * zd).sqrt();
|
||||
if yd.abs() > EPSILON || sd.abs() > EPSILON {
|
||||
let x_rot = -trig::atan2_degrees(yd, sd);
|
||||
self.head_pitch = rotlerp(self.head_pitch, x_rot, max_turn);
|
||||
// Entity.setXRot clamps: a pitch rotlerp wraps to 359 becomes 90.
|
||||
self.head_pitch =
|
||||
(rotlerp(self.head_pitch, x_rot, max_turn) % 360.0).clamp(-90.0, 90.0);
|
||||
self.ai.yya = if yd > 0.0 { speed } else { -speed };
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -174,6 +174,26 @@ impl GoalSelector {
|
||||
|
||||
// --- random positions (DefaultRandomPos / LandRandomPos / RandomPos) -------
|
||||
|
||||
/// RandomPos.moveUpToAboveSolid: out of the solid blocks, then up to
|
||||
/// `above` more blocks of air.
|
||||
fn move_up_to_above_solid(w: &MobWorld, mut p: [i32; 3], above: i32) -> [i32; 3] {
|
||||
if !w.solid(p[0], p[1], p[2]) {
|
||||
return p;
|
||||
}
|
||||
p[1] += 1;
|
||||
while p[1] <= 319 && w.solid(p[0], p[1], p[2]) {
|
||||
p[1] += 1;
|
||||
}
|
||||
let first = p[1];
|
||||
while p[1] <= 319 && p[1] - first < above {
|
||||
p[1] += 1;
|
||||
if w.solid(p[0], p[1], p[2]) {
|
||||
p[1] -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
p
|
||||
}
|
||||
/// `Mob.isWithinHome(BlockPos)`.
|
||||
pub fn within_home(c: [i32; 3], r: i32, p: [i32; 3]) -> bool {
|
||||
let d = |i: usize| i64::from(c[i] - p[i]);
|
||||
@@ -371,29 +391,89 @@ impl Mob {
|
||||
xd: f64,
|
||||
zd: f64,
|
||||
) -> Option<[f64; 3]> {
|
||||
// Every caller passes `(float) (Math.PI / 2)`.
|
||||
let max_rad = f64::from(std::f32::consts::FRAC_PI_2);
|
||||
self.pick_best(w, |m| {
|
||||
let d = m.random_direction_within(
|
||||
0.0,
|
||||
f64::from(h),
|
||||
v,
|
||||
fly_height,
|
||||
xd,
|
||||
zd,
|
||||
// Every caller passes `(float) (Math.PI / 2)`.
|
||||
f64::from(std::f32::consts::FRAC_PI_2),
|
||||
)?;
|
||||
let mut p = m.toward(f64::from(h), d);
|
||||
if p[1] < crate::chunk::MIN_Y || p[1] >= 320 || m.restricted(f64::from(h), p) {
|
||||
m.air_and_water_pos(w, h, v, fly_height, xd, zd, max_rad)
|
||||
})
|
||||
}
|
||||
/// AirAndWaterRandomPos.generateRandomPos.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn air_and_water_pos(
|
||||
&mut self,
|
||||
w: &MobWorld,
|
||||
h: i32,
|
||||
v: i32,
|
||||
fly_height: i32,
|
||||
xd: f64,
|
||||
zd: f64,
|
||||
max_rad: f64,
|
||||
) -> Option<[i32; 3]> {
|
||||
let d = self.random_direction_within(0.0, f64::from(h), v, fly_height, xd, zd, max_rad)?;
|
||||
let mut p = self.toward(f64::from(h), d);
|
||||
if p[1] < crate::chunk::MIN_Y || p[1] >= 320 || self.restricted(f64::from(h), p) {
|
||||
return None;
|
||||
}
|
||||
// RandomPos.moveUpOutOfSolid
|
||||
if w.solid(p[0], p[1], p[2]) {
|
||||
p[1] += 1;
|
||||
while p[1] <= 319 && w.solid(p[0], p[1], p[2]) {
|
||||
p[1] += 1;
|
||||
}
|
||||
}
|
||||
(self.malus(w.path_type_static(p[0], p[1], p[2])) == 0.0).then_some(p)
|
||||
}
|
||||
/// AirRandomPos.getPosTowards: an AirAndWaterRandomPos towards a point,
|
||||
/// out of water.
|
||||
pub fn air_random_pos_towards(
|
||||
&mut self,
|
||||
w: &MobWorld,
|
||||
h: i32,
|
||||
v: i32,
|
||||
fly_height: i32,
|
||||
to: [f64; 3],
|
||||
max_rad: f64,
|
||||
) -> Option<[f64; 3]> {
|
||||
let (xd, zd) = (to[0] - self.position.x, to[2] - self.position.z);
|
||||
self.pick_best(w, |m| {
|
||||
let p = m.air_and_water_pos(w, h, v, fly_height, xd, zd, max_rad)?;
|
||||
(w.fluid(p[0], p[1], p[2]) != crate::blocks::Fluid::Water).then_some(p)
|
||||
})
|
||||
}
|
||||
/// HoverRandomPos.getPos: a stable spot within the radians of a
|
||||
/// direction, raised a random `hover_min..=hover_max` blocks above the
|
||||
/// solid ground it is in, out of water and free of path maluses.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn hover_random_pos(
|
||||
&mut self,
|
||||
w: &MobWorld,
|
||||
h: i32,
|
||||
v: i32,
|
||||
xd: f64,
|
||||
zd: f64,
|
||||
max_rad: f64,
|
||||
hover_max: i32,
|
||||
hover_min: i32,
|
||||
) -> Option<[f64; 3]> {
|
||||
self.pick_best(w, |m| {
|
||||
let d = m.random_direction_within(0.0, f64::from(h), v, 0, xd, zd, max_rad)?;
|
||||
// LandRandomPos.generateRandomPosTowardDirection
|
||||
let p = m.toward(f64::from(h), d);
|
||||
if p[1] < crate::chunk::MIN_Y
|
||||
|| p[1] >= 320
|
||||
|| m.restricted(f64::from(h), p)
|
||||
|| !m.stable_destination(w, p)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
// RandomPos.moveUpOutOfSolid
|
||||
if w.solid(p[0], p[1], p[2]) {
|
||||
p[1] += 1;
|
||||
while p[1] <= 319 && w.solid(p[0], p[1], p[2]) {
|
||||
p[1] += 1;
|
||||
}
|
||||
}
|
||||
(m.malus(w.path_type_static(p[0], p[1], p[2])) == 0.0).then_some(p)
|
||||
let above = m
|
||||
.random
|
||||
.next_int_bound(hover_max - hover_min + 1)
|
||||
.unwrap_or(0)
|
||||
+ hover_min;
|
||||
let p = move_up_to_above_solid(w, p, above);
|
||||
let water = w.fluid(p[0], p[1], p[2]) == crate::blocks::Fluid::Water;
|
||||
(!water && m.malus(w.path_type_static(p[0], p[1], p[2])) == 0.0).then_some(p)
|
||||
})
|
||||
}
|
||||
/// LandRandomPos.getPos
|
||||
@@ -1340,6 +1420,9 @@ pub struct HurtByTarget {
|
||||
pub alert_except: Vec<Species>,
|
||||
/// Attackers ignored (e.g. zombified piglins ignore other zombified piglins).
|
||||
pub ignore: Vec<Species>,
|
||||
/// `Bee.BeeHurtByOtherGoal`: kept only while angry, and alerting others
|
||||
/// only when the attacker is in sight.
|
||||
pub bee: bool,
|
||||
timestamp: i32,
|
||||
st: TargetState,
|
||||
}
|
||||
@@ -1349,6 +1432,7 @@ impl HurtByTarget {
|
||||
alert: false,
|
||||
alert_except: vec![],
|
||||
ignore: vec![],
|
||||
bee: false,
|
||||
timestamp: 0,
|
||||
st: TargetState {
|
||||
unseen_memory: 300,
|
||||
@@ -1364,6 +1448,10 @@ impl HurtByTarget {
|
||||
self.ignore = s.to_vec();
|
||||
self
|
||||
}
|
||||
pub fn bee(mut self) -> Self {
|
||||
self.bee = true;
|
||||
self
|
||||
}
|
||||
}
|
||||
impl Default for HurtByTarget {
|
||||
fn default() -> Self {
|
||||
@@ -1372,6 +1460,13 @@ impl Default for HurtByTarget {
|
||||
}
|
||||
impl Goal for HurtByTarget {
|
||||
goal_clone!();
|
||||
fn name(&self) -> &'static str {
|
||||
if self.bee {
|
||||
"BeeHurtByOtherGoal"
|
||||
} else {
|
||||
"HurtByTarget"
|
||||
}
|
||||
}
|
||||
fn flags(&self) -> u8 {
|
||||
TARGET
|
||||
}
|
||||
@@ -1396,6 +1491,9 @@ impl Goal for HurtByTarget {
|
||||
t.alive && t.can_be_seen_as_enemy && !(t.is_player && t.creative)
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
if self.bee && !super::bee::angry(m, cx.w) {
|
||||
return false;
|
||||
}
|
||||
target_continue(&mut self.st, true, m, cx)
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
@@ -1426,6 +1524,10 @@ impl Goal for HurtByTarget {
|
||||
.filter(|s| Who::Mob(s.id) != by)
|
||||
.map(|s| s.id)
|
||||
.collect();
|
||||
// Bee.BeeHurtByOtherGoal.alertOther: only with the attacker in sight.
|
||||
if self.bee && !ids.is_empty() && !m.sees(cx.w, by) {
|
||||
return;
|
||||
}
|
||||
for other in ids {
|
||||
cx.events.push(MobEvent::SetTarget {
|
||||
mob: other,
|
||||
|
||||
@@ -346,10 +346,10 @@ impl Mob {
|
||||
self.vertical_collision_below = vertical && wanted.y < 0.0;
|
||||
self.on_ground = self.vertical_collision_below;
|
||||
// Strider.checkFallDamage: lava breaks any fall, and the fluid state
|
||||
// waits for the next baseTick; Bat.checkFallDamage does nothing.
|
||||
// waits for the next baseTick; Bat and Bee.checkFallDamage do nothing.
|
||||
if self.kind.flags.lava_walker && self.fluids.in_lava {
|
||||
self.fall_distance = 0.0;
|
||||
} else if self.kind.species != super::Species::Bat {
|
||||
} else if !matches!(self.kind.species, super::Species::Bat | super::Species::Bee) {
|
||||
self.check_fall_damage(w, moved, events);
|
||||
}
|
||||
// restituteMovementAfterCollisions with no bounciness: the colliding
|
||||
@@ -782,9 +782,15 @@ impl Mob {
|
||||
self.ai.no_jump_delay = 0;
|
||||
}
|
||||
}
|
||||
/// Mob.jumpInLiquid: floaters rise 0.04 per tick, others 0.3.
|
||||
/// Mob.jumpInLiquid: floaters rise 0.04 per tick, others 0.3; bees 0.01.
|
||||
fn jump_in_liquid(&mut self) {
|
||||
self.velocity.y += if self.ai.nav.can_float { 0.04 } else { 0.3 };
|
||||
self.velocity.y += if self.species() == super::Species::Bee {
|
||||
0.01
|
||||
} else if self.ai.nav.can_float {
|
||||
0.04
|
||||
} else {
|
||||
0.3
|
||||
};
|
||||
}
|
||||
pub fn jump_from_ground(&mut self, w: &MobWorld) {
|
||||
if self.species() == super::Species::Rabbit {
|
||||
|
||||
@@ -562,6 +562,9 @@ impl Mob {
|
||||
}
|
||||
/// PathNavigation.isStableDestination for the mob's navigation.
|
||||
pub fn stable_destination(&self, w: &MobWorld, p: [i32; 3]) -> bool {
|
||||
if self.species() == super::Species::Bee {
|
||||
return super::bee::stable_destination(w, p);
|
||||
}
|
||||
// StriderPathNavigation: lava too.
|
||||
if self.kind.flags.lava_walker && w.block_name(p[0], p[1], p[2]) == "minecraft:lava" {
|
||||
return true;
|
||||
|
||||
@@ -263,6 +263,24 @@ pub fn body(m: &Mob) -> (String, String) {
|
||||
"entity/strider/strider"
|
||||
}),
|
||||
),
|
||||
// BeeRenderer.getTextureLocation: angry, carrying nectar, or both.
|
||||
S::Bee => {
|
||||
let angry = super::bee::get(m).is_some_and(|b| b.anger_end > 0);
|
||||
let nectar = super::bee::has_nectar(m);
|
||||
let texture = match (angry, nectar) {
|
||||
(true, true) => "entity/bee/bee_angry_nectar",
|
||||
(true, false) => "entity/bee/bee_angry",
|
||||
(false, true) => "entity/bee/bee_nectar",
|
||||
(false, false) => "entity/bee/bee",
|
||||
};
|
||||
let layer = baby_or(m, "bee#main", "bee_baby#main");
|
||||
let texture = if layer.starts_with("bee_baby") {
|
||||
b(texture)
|
||||
} else {
|
||||
texture.to_owned()
|
||||
};
|
||||
(layer, texture)
|
||||
}
|
||||
S::Squid => (
|
||||
baby_or(m, "squid#main", "squid_baby#main"),
|
||||
b("entity/squid/squid"),
|
||||
|
||||
@@ -615,6 +615,20 @@ public final class VanillaMobAiOracle {
|
||||
if (cooldown > 0) brain.setMemory(MemoryModuleType.TRANSPORT_ITEMS_COOLDOWN_TICKS, cooldown);
|
||||
else brain.eraseMemory(MemoryModuleType.TRANSPORT_ITEMS_COOLDOWN_TICKS);
|
||||
}
|
||||
if (mob instanceof net.minecraft.world.entity.animal.bee.Bee bee) {
|
||||
// The constructor's draws, made again with the seeded random: the validate
|
||||
// goals' cooldowns (registerGoals), then the flower cooldown's initialiser.
|
||||
var rnd = bee.getRandom();
|
||||
int hive = net.minecraft.util.Mth.nextInt(rnd, 20, 40);
|
||||
int flower = net.minecraft.util.Mth.nextInt(rnd, 20, 40);
|
||||
for (WrappedGoal g : ((GoalSelector) get(bee, "goalSelector")).getAvailableGoals()) {
|
||||
String n = g.getGoal().getClass().getSimpleName();
|
||||
if (n.equals("ValidateHiveGoal")) field(g.getGoal().getClass(), "VALIDATE_HIVE_COOLDOWN").setInt(g.getGoal(), hive);
|
||||
if (n.equals("ValidateFlowerGoal")) field(g.getGoal().getClass(), "validateFlowerCooldown").setInt(g.getGoal(), flower);
|
||||
}
|
||||
field(net.minecraft.world.entity.animal.bee.Bee.class, "remainingCooldownBeforeLocatingNewFlower")
|
||||
.setInt(bee, net.minecraft.util.Mth.nextInt(rnd, 20, 60));
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Object, Sensor<?>> sensors = (Map<Object, Sensor<?>>) get(brain, "sensors");
|
||||
for (Sensor<?> sensor : sensors.values()) sensor.randomlyDelayStart(mob.getRandom());
|
||||
@@ -986,6 +1000,18 @@ public final class VanillaMobAiOracle {
|
||||
sb.append("\tcg ").append(golem.getState().ordinal()).append(' ').append(stack(golem.getMainHandItem())).append(' ')
|
||||
.append(opened == null ? "-" : pos((BlockPos) opened));
|
||||
}
|
||||
if (m instanceof net.minecraft.world.entity.animal.bee.Bee bee) {
|
||||
// Flags (roll 2, stung 4, nectar 8), anger left, ticks without nectar, flower cooldown, flower.
|
||||
Object acc = field(net.minecraft.world.entity.animal.bee.Bee.class, "DATA_FLAGS_ID").get(null);
|
||||
@SuppressWarnings("unchecked")
|
||||
byte flags = bee.getEntityData().get((net.minecraft.network.syncher.EntityDataAccessor<Byte>) acc);
|
||||
long end = bee.getPersistentAngerEndTime();
|
||||
BlockPos flower = bee.getSavedFlowerPos();
|
||||
sb.append("\tbee ").append(flags).append(' ').append(end > 0 ? end - bee.level().getGameTime() : -1).append(' ')
|
||||
.append(field(net.minecraft.world.entity.animal.bee.Bee.class, "ticksWithoutNectarSinceExitingHive").getInt(bee)).append(' ')
|
||||
.append(field(net.minecraft.world.entity.animal.bee.Bee.class, "remainingCooldownBeforeLocatingNewFlower").getInt(bee)).append(' ')
|
||||
.append(flower == null ? "-" : pos(flower));
|
||||
}
|
||||
out.println(sb);
|
||||
}
|
||||
|
||||
|
||||
@@ -237,6 +237,19 @@ def scenarios():
|
||||
CAVE = ['fill -5 -60 -5 5 -54 5 minecraft:stone', 'fill -4 -60 -4 4 -55 4 minecraft:air']
|
||||
for i, seed in enumerate([144, 145, 146]):
|
||||
add(f'bat_cave_{i}', 400, CAVE + [f'mob minecraft:bat 0.5 -58 0.5 {90 * i} {seed} persistent'])
|
||||
# Bees: wandering over grass (HoverRandomPos), pollinating a flower bed until they carry nectar,
|
||||
# drawn to a player holding a flower, staying home at night and in the rain (no hive to find),
|
||||
# drowning in a pool, and angered by a hit: they chase and sting the player once, then die of it.
|
||||
FLOWERS = 'fill 3 -60 2 5 -60 4 minecraft:dandelion'
|
||||
for i, seed in enumerate([151, 152]):
|
||||
add(f'bee_alone_{i}', 400, [f'mob minecraft:bee 0.5 -58 0.5 {90 * i} {seed} persistent'])
|
||||
for i, seed in enumerate([153, 154]):
|
||||
add(f'bee_flowers_{i}', 700, [FLOWERS, f'mob minecraft:bee 0.5 -58 0.5 {180 * i} {seed} persistent'])
|
||||
add('bee_tempted', 200, ['player 6.5 -60 0.5 hand=minecraft:dandelion', 'mob minecraft:bee 0.5 -58 0.5 0 155 persistent'])
|
||||
add('bee_night', 300, [FLOWERS, 'mob minecraft:bee 0.5 -58 0.5 0 156 persistent'], 'time=18000')
|
||||
add('bee_rain', 300, [FLOWERS, 'mob minecraft:bee 0.5 -58 0.5 0 157 persistent'], 'rain')
|
||||
add('bee_pool', 200, ['fill -3 -63 -3 3 -61 3 minecraft:water', 'mob minecraft:bee 0.5 -62 0.5 0 158 persistent'])
|
||||
add('bee_sting', 400, ['player 4.5 -60 0.5', 'mob minecraft:bee 0.5 -58 0.5 0 159 persistent', 'hurt 20 0'])
|
||||
return s
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user