Pandas: genes, sit, roll, lie on back, sneeze and unhappy states, synced to clients
A panda now has vanilla's states: it sits to eat bamboo or cake it picks up or is given, a lazy one lies on its back, a playful one or a cub rolls over, a cub sneezes, and a panda that is fed with no bamboo around sulks. A worried panda sits and shivers in a thunderstorm. The genes show in its coat, pass to its young, and are saved. The flags, counters and genes go to clients as entity data, and the model, the item in its mouth, the crumbs and the sneeze are drawn from them, in game and in a LAN guest's window.
This commit is contained in:
@@ -259,6 +259,18 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
map.entry("sound_variant".into())
|
||||
.or_insert_with(|| string("minecraft:classic"));
|
||||
}
|
||||
"minecraft:panda" => {
|
||||
use crate::mobs::panda::GENES;
|
||||
for (key, gene) in [
|
||||
("MainGene", m.extra.variant),
|
||||
("HiddenGene", m.extra.variant2),
|
||||
] {
|
||||
map.insert(
|
||||
key.into(),
|
||||
string(GENES[usize::from(gene).min(GENES.len() - 1)]),
|
||||
);
|
||||
}
|
||||
}
|
||||
"minecraft:piglin" | "minecraft:piglin_brute" | "minecraft:hoglin" => {
|
||||
map.insert(
|
||||
"IsImmuneToZombification".into(),
|
||||
@@ -808,6 +820,11 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
.unwrap_or(0) as u8;
|
||||
}
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Panda {
|
||||
let gene = |key| text(tag.get(key)).map_or(0, |n| crate::mobs::panda::gene_from_name(&n));
|
||||
m.extra.variant = gene("MainGene");
|
||||
m.extra.variant2 = gene("HiddenGene");
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Wolf {
|
||||
let health = m.health;
|
||||
m.extra.owner = crate::save::uuid_from_tag(tag.get("Owner"));
|
||||
|
||||
@@ -127,6 +127,7 @@ mod packs;
|
||||
mod pad;
|
||||
mod pad_menu;
|
||||
mod paintings;
|
||||
mod pandas;
|
||||
mod passengers;
|
||||
mod persist;
|
||||
mod perspective;
|
||||
|
||||
@@ -33,5 +33,6 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
self.eye_particles();
|
||||
self.panda_effects();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,6 +670,7 @@ impl Game<'_> {
|
||||
self.tick_projectiles()?;
|
||||
self.tick_fangs();
|
||||
self.tick_allays();
|
||||
self.tick_pandas();
|
||||
self.tick_breeze_effects();
|
||||
self.tick_sniffer_effects();
|
||||
self.piglin_pickups();
|
||||
@@ -1331,9 +1332,14 @@ impl Game<'_> {
|
||||
m.ai.aggressive |= aggressive;
|
||||
}
|
||||
}
|
||||
MobEvent::PandaSneezed { mob } => self.panda_sneezed(mob),
|
||||
MobEvent::GiftLoot { mob, table, at } => {
|
||||
// Turtle.ageBoundaryReached: only with mob loot on.
|
||||
if table == "minecraft:gameplay/turtle_grow" && !self.ui.rules.bool("mob_drops")
|
||||
// Turtle.ageBoundaryReached and Panda.afterSneeze: only
|
||||
// with mob loot on.
|
||||
if matches!(
|
||||
table,
|
||||
"minecraft:gameplay/turtle_grow" | "minecraft:gameplay/panda_sneeze"
|
||||
) && !self.ui.rules.bool("mob_drops")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1570,6 +1576,13 @@ impl Game<'_> {
|
||||
self.spawn_breeding_orb([p.position.x, p.position.y, p.position.z], xp);
|
||||
return;
|
||||
}
|
||||
// Panda.getBreedOffspring: genes from both parents.
|
||||
if p.species() == Species::Panda {
|
||||
horizon_client::mobs::panda::inherit(child, &p, q.as_ref().unwrap_or(&p));
|
||||
let xp = 1 + self.world.random.next_int_bound(7).unwrap_or(0) as u32;
|
||||
self.spawn_breeding_orb([p.position.x, p.position.y, p.position.z], xp);
|
||||
return;
|
||||
}
|
||||
// Nautilus.getBreedOffspring: a tame parent's baby is tame too.
|
||||
if p.species() == Species::Nautilus && p.extra.tame {
|
||||
child.extra.tame = true;
|
||||
@@ -2687,6 +2700,14 @@ impl Game<'_> {
|
||||
let creative = self.creative;
|
||||
// The hand's slot (Player.interactOn passes the hand).
|
||||
let selected = self.held_slot();
|
||||
// Panda.mobInteract: bamboo, or a click on a panda lying on its back.
|
||||
if self.mobs[index].species() == Species::Panda && self.mobs[index].alive() {
|
||||
let taken = self.interact_panda(index, &item);
|
||||
if taken {
|
||||
self.swing_arm();
|
||||
}
|
||||
return Ok(taken);
|
||||
}
|
||||
if self.interact_zombie_villager(index, &item) {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
@@ -350,6 +350,29 @@ fn mob_meta(
|
||||
}
|
||||
defaults.push((17, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
// Panda: UNHAPPY_COUNTER, SNEEZE_COUNTER and EAT_COUNTER (after
|
||||
// AgeableMob's two), MAIN_GENE_ID, HIDDEN_GENE_ID and DATA_ID_FLAGS;
|
||||
// the client animates the states from them.
|
||||
"minecraft:panda" => {
|
||||
let (flags, counters) = horizon_client::mobs::panda::get(m)
|
||||
.map_or((0, [0; 3]), |s| (s.flags, [s.unhappy, s.sneeze, s.eat]));
|
||||
for (index, value) in (18..).zip(counters) {
|
||||
if value != 0 {
|
||||
meta.push((index, serializer::INT, Value::Int(value)));
|
||||
}
|
||||
defaults.push((index, serializer::INT, Value::Int(0)));
|
||||
}
|
||||
for (index, gene) in [(21, e.variant), (22, e.variant2)] {
|
||||
if gene != 0 {
|
||||
meta.push((index, serializer::BYTE, Value::Byte(gene as i8)));
|
||||
}
|
||||
defaults.push((index, serializer::BYTE, Value::Byte(0)));
|
||||
}
|
||||
if flags != 0 {
|
||||
meta.push((23, serializer::BYTE, Value::Byte(flags as i8)));
|
||||
}
|
||||
defaults.push((23, serializer::BYTE, Value::Byte(0)));
|
||||
}
|
||||
// SpellcasterIllager.DATA_SPELL_CASTING_ID: the casting pose.
|
||||
"minecraft:evoker" | "minecraft:illusioner" => {
|
||||
if e.variant2 != 0 {
|
||||
|
||||
@@ -312,13 +312,15 @@ impl Game<'_> {
|
||||
owner.use_item_remaining_ticks = 72_000 - mob.extra.using_item;
|
||||
owner.crossbow_charge_duration = 25;
|
||||
}
|
||||
let context = if left {
|
||||
horizon_assets::item_model::DisplayContext::ThirdPersonLeftHand
|
||||
} else {
|
||||
horizon_assets::item_model::DisplayContext::ThirdPersonRightHand
|
||||
use horizon_assets::item_model::DisplayContext as Context;
|
||||
// PandaHoldsItemLayer shows the item as it lies on the ground.
|
||||
let (context, ordinal) = match (mob.species(), left) {
|
||||
(Species::Panda, _) => (Context::Ground, 7),
|
||||
(_, true) => (Context::ThirdPersonLeftHand, 1),
|
||||
(_, false) => (Context::ThirdPersonRightHand, 2),
|
||||
};
|
||||
// `updateForLiving`: seeded by the entity id plus the context ordinal.
|
||||
let seed = mob.id as i32 + if left { 1 } else { 2 };
|
||||
let seed = mob.id as i32 + ordinal;
|
||||
let state = self.resolve_item(&stack, context, Some(&owner), seed);
|
||||
if lit {
|
||||
self.submit_item_world(&state, t, light, out);
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
//! Pandas on the game side: the food they find on the ground and pick up
|
||||
//! (`Mob.aiStep`, `Panda.pickUpItem`), the bamboo a player gives them
|
||||
//! (`Panda.mobInteract`), the start a sneeze gives the grown pandas about,
|
||||
//! and the crumbs and the sneeze a window draws.
|
||||
use super::{
|
||||
Game,
|
||||
pickups::{Collector, Taken},
|
||||
};
|
||||
use horizon_client::{
|
||||
items::ItemStack,
|
||||
mobs::{Species, panda},
|
||||
particles::{ParticleOptions, ParticleType},
|
||||
};
|
||||
use horizon_core::geometry::Vec3;
|
||||
|
||||
impl Game<'_> {
|
||||
/// `Panda.canPickUpAndEat`'s tag.
|
||||
fn panda_eats_from_ground(&self, item: &str) -> bool {
|
||||
self.res
|
||||
.items()
|
||||
.item_tags
|
||||
.get("minecraft:panda_eats_from_ground")
|
||||
.is_some_and(|tag| tag.contains(item))
|
||||
}
|
||||
/// A panda takes what lies at its feet when its mouth is free, and
|
||||
/// looks for food within 6 and 8 blocks for `PandaSitGoal`.
|
||||
pub(super) fn tick_pandas(&mut self) {
|
||||
let griefing = self.ui.rules.bool("mob_griefing");
|
||||
for i in 0..self.mobs.len() {
|
||||
let m = &self.mobs[i];
|
||||
if m.species() != Species::Panda || !m.alive() {
|
||||
continue;
|
||||
}
|
||||
let id = m.id;
|
||||
let wants = |g: &Self, e: &horizon_client::entities::ItemEntity| {
|
||||
e.pickup_delay == 0 && g.panda_eats_from_ground(&e.stack.item)
|
||||
};
|
||||
// Mob.aiStep: the items within the box grown by (1, 0, 1).
|
||||
if griefing && m.can_pick_up_loot() && m.extra.main_hand.is_none() {
|
||||
let reach = m.bounds().inflate(Vec3::new(1.0, 0.0, 1.0));
|
||||
let taken = self
|
||||
.dropped
|
||||
.iter()
|
||||
.position(|e| wants(self, e) && reach.intersects(e.bounds()));
|
||||
if let Some(j) = taken {
|
||||
let e = self.dropped.remove(j);
|
||||
self.add_pickup(Taken::Item(Box::new(e.clone())), Collector::Mob(id));
|
||||
panda::hold(&mut self.mobs[i], &e.stack.item, e.stack.count, true);
|
||||
}
|
||||
}
|
||||
let m = &self.mobs[i];
|
||||
let area = |r: f64| m.bounds().inflate(Vec3::new(r, r, r));
|
||||
let (near, wide) = (area(6.0), area(8.0));
|
||||
let food_near = self
|
||||
.dropped
|
||||
.iter()
|
||||
.any(|e| wants(self, e) && near.intersects(e.bounds()));
|
||||
let food_at = self
|
||||
.dropped
|
||||
.iter()
|
||||
.find(|e| wants(self, e) && wide.intersects(e.bounds()))
|
||||
.map(|e| [e.position.x, e.position.y, e.position.z]);
|
||||
panda::set_food(&mut self.mobs[i], food_near, food_at);
|
||||
}
|
||||
}
|
||||
/// `Panda.mobInteract` for a click with `item`; whether the click is taken.
|
||||
pub(super) fn interact_panda(&mut self, index: usize, item: &str) -> bool {
|
||||
let creative = self.creative;
|
||||
let m = &mut self.mobs[index];
|
||||
if panda::scared(m) {
|
||||
return false;
|
||||
}
|
||||
if panda::get_up(m) {
|
||||
return true;
|
||||
}
|
||||
if !m.kind.food.iter().any(|f| f == item) {
|
||||
return false;
|
||||
}
|
||||
if m.ai.target.is_some() {
|
||||
panda::got_bamboo(m);
|
||||
}
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
let mut dropped = None;
|
||||
if m.is_baby() {
|
||||
// ageUp((int) (-getAge() / 20 * 0.1F), true).
|
||||
let seconds = ((-m.extra.age / 20) as f32 * 0.1) as i32;
|
||||
horizon_client::mobs::ai::age_up(m, seconds, true);
|
||||
} else if m.extra.age == 0 && m.extra.in_love <= 0 {
|
||||
m.extra.in_love = 600;
|
||||
m.extra.love_player = true;
|
||||
} else {
|
||||
if panda::is_sitting(m) || m.fluids.in_water {
|
||||
return false;
|
||||
}
|
||||
panda::try_to_sit(m);
|
||||
panda::start_eating(m);
|
||||
// What it held falls, unless the player has infinite materials.
|
||||
if let Some(held) = m.extra.main_hand.clone()
|
||||
&& !creative
|
||||
{
|
||||
dropped = Some(ItemStack::new(&held, panda::held_count(m)));
|
||||
}
|
||||
panda::hold(m, item, 1, false);
|
||||
}
|
||||
self.consume_held();
|
||||
if let Some(stack) = dropped {
|
||||
self.spawn_item(stack, at, [0.0, 0.2, 0.0], 10);
|
||||
}
|
||||
true
|
||||
}
|
||||
/// `Panda.afterSneeze`: the grown pandas within 10 blocks of a cub jump.
|
||||
pub(super) fn panda_sneezed(&mut self, id: u32) {
|
||||
let Some(area) = self
|
||||
.mobs
|
||||
.iter()
|
||||
.find(|m| m.id == id)
|
||||
.map(|m| m.bounds().inflate(Vec3::new(10.0, 10.0, 10.0)))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
for m in &mut self.mobs {
|
||||
if m.species() == Species::Panda
|
||||
&& !m.is_baby()
|
||||
&& m.on_ground
|
||||
&& !m.fluids.in_water
|
||||
&& panda::can_perform_action(m, panda::scared(m))
|
||||
&& area.intersects(m.bounds())
|
||||
{
|
||||
// LivingEntity.jumpFromGround.
|
||||
m.needs_sync = true;
|
||||
let power = f64::from(m.jump_power());
|
||||
if power > 1.0e-5 {
|
||||
m.velocity.y = power.max(m.velocity.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// What a window draws of its pandas: the crumbs of a bite
|
||||
/// (`addEatingParticles`) and the sneeze's particle.
|
||||
pub(super) fn panda_effects(&mut self) {
|
||||
let mut bites = Vec::new();
|
||||
let mut sneezes = Vec::new();
|
||||
for m in self
|
||||
.mobs
|
||||
.iter_mut()
|
||||
.filter(|m| m.species() == Species::Panda)
|
||||
{
|
||||
let (crumbs, sneeze) = panda::effects(m);
|
||||
if let (Some(crumbs), Some(item)) = (crumbs, m.extra.main_hand.clone()) {
|
||||
bites.push((item, crumbs));
|
||||
}
|
||||
sneezes.extend(sneeze);
|
||||
}
|
||||
for (item, crumbs) in bites {
|
||||
let options = self.item_particle(&ItemStack::new(&item, 1));
|
||||
for (at, velocity) in crumbs {
|
||||
self.particles.add(&options, at, velocity);
|
||||
}
|
||||
}
|
||||
let options = ParticleOptions::simple(ParticleType::Sneeze);
|
||||
for (at, velocity) in sneezes {
|
||||
self.particles.add(&options, at, velocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3468,16 +3468,18 @@ impl Game<'_> {
|
||||
// server never sends the fluid contact, and the renderers read it (cod, salmon and
|
||||
// tropical fish lie on their side without `in_water`, #1591).
|
||||
// A frozen level ticks only the players, as below.
|
||||
let fluids: Vec<_> = {
|
||||
let (fluids, thundering): (Vec<_>, bool) = {
|
||||
let w = self.mob_world_base(&[]);
|
||||
let players = self.remote.as_ref().map(|r| &r.level_players);
|
||||
self.mobs
|
||||
let fluids = self
|
||||
.mobs
|
||||
.iter()
|
||||
.map(|m| {
|
||||
(running || players.is_some_and(|p| p.contains_key(&(m.id as i32))))
|
||||
.then(|| w.fluids(m.bounds(), m.eye_y()))
|
||||
})
|
||||
.collect()
|
||||
.collect();
|
||||
(fluids, w.thundering)
|
||||
};
|
||||
for (m, fluids) in self.mobs.iter_mut().zip(fluids) {
|
||||
if let Some(fluids) = fluids {
|
||||
@@ -3589,6 +3591,9 @@ impl Game<'_> {
|
||||
if m.species() == horizon_client::mobs::Species::Bat {
|
||||
horizon_client::mobs::bat::setup_animation_states(m);
|
||||
}
|
||||
if m.species() == horizon_client::mobs::Species::Panda {
|
||||
horizon_client::mobs::panda::client_tick(m, thundering);
|
||||
}
|
||||
}
|
||||
for o in self.orbs.iter_mut().filter(|_| running) {
|
||||
o.previous = o.position;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! own simulation, which a client of a server doesn't run.
|
||||
use super::Game;
|
||||
use horizon_client::mobs::render::{PROFESSIONS, VILLAGER_TYPES};
|
||||
use horizon_client::mobs::{Mob, Species, Who, bat, tame};
|
||||
use horizon_client::mobs::{Mob, Species, Who, bat, panda, tame};
|
||||
use horizon_protocol::entity_data::Value;
|
||||
use horizon_protocol::registry::Builtin;
|
||||
|
||||
@@ -59,6 +59,14 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_enti
|
||||
Who::Mob(*target as u32)
|
||||
});
|
||||
}
|
||||
// Panda: the counters, the two genes and DATA_ID_FLAGS (after
|
||||
// AgeableMob's two entries).
|
||||
(Species::Panda, 18, Value::Int(n)) => panda::set_unhappy(m, *n),
|
||||
(Species::Panda, 19, Value::Int(n)) => panda::set_sneeze(m, *n),
|
||||
(Species::Panda, 20, Value::Int(n)) => panda::set_eat(m, *n),
|
||||
(Species::Panda, 21, Value::Byte(gene)) => m.extra.variant = (*gene).clamp(0, 6) as u8,
|
||||
(Species::Panda, 22, Value::Byte(gene)) => m.extra.variant2 = (*gene).clamp(0, 6) as u8,
|
||||
(Species::Panda, 23, Value::Byte(flags)) => panda::set_flags(m, *flags as u8),
|
||||
// Bat.DATA_ID_FLAGS: resting in bit 0.
|
||||
(Species::Bat, 16, Value::Byte(flags)) => bat::set_resting(m, flags & 1 != 0),
|
||||
// Sheep.DATA_WOOL_ID: the colour in the low nibble, 16 sheared.
|
||||
|
||||
@@ -47,6 +47,7 @@ pub mod monster_brain;
|
||||
pub mod nautilus;
|
||||
pub mod nav;
|
||||
pub mod nether;
|
||||
pub mod panda;
|
||||
pub mod path;
|
||||
pub mod phantom;
|
||||
pub mod piglin;
|
||||
@@ -783,6 +784,8 @@ pub struct Extra {
|
||||
pub brain: Option<Box<monster_brain::Brain>>,
|
||||
/// A bee's nectar, anger, flower and hive state.
|
||||
pub bee: Option<Box<bee::Bee>>,
|
||||
/// A panda's flags, counters and amounts.
|
||||
pub panda: Option<Box<panda::State>>,
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Mob {
|
||||
@@ -1226,6 +1229,10 @@ pub enum MobEvent {
|
||||
center: [f64; 3],
|
||||
spread: [f64; 3],
|
||||
},
|
||||
/// `Panda.afterSneeze`: the grown pandas within 10 blocks start.
|
||||
PandaSneezed {
|
||||
mob: u32,
|
||||
},
|
||||
}
|
||||
/// How a spawned-by-kind mob should be set up.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
||||
@@ -106,6 +106,7 @@ pub enum Family {
|
||||
Strider,
|
||||
Bat,
|
||||
Bee,
|
||||
Panda,
|
||||
}
|
||||
pub fn family(s: Species) -> Family {
|
||||
use Species as S;
|
||||
@@ -167,6 +168,7 @@ pub fn family(s: Species) -> Family {
|
||||
S::Strider => Family::Strider,
|
||||
S::Bat => Family::Bat,
|
||||
S::Bee => Family::Bee,
|
||||
S::Panda => Family::Panda,
|
||||
_ => Family::Generic,
|
||||
}
|
||||
}
|
||||
@@ -227,6 +229,7 @@ pub fn register(m: &mut Mob) {
|
||||
Family::Strider => super::strider::register(m),
|
||||
Family::Bat => super::bat::register(m),
|
||||
Family::Bee => super::bee::register(m),
|
||||
Family::Panda => super::panda::register(m),
|
||||
}
|
||||
// FloatGoal's constructor lets the navigation float, as do the
|
||||
// constructors of these brain-driven and flying mobs. A floater rises
|
||||
@@ -429,6 +432,9 @@ pub fn tick(
|
||||
if m.species() == Species::Bee {
|
||||
super::bee::tick(m, level_random);
|
||||
}
|
||||
if m.species() == Species::Panda {
|
||||
super::panda::tick(m, w, events);
|
||||
}
|
||||
true
|
||||
}
|
||||
/// LivingEntity.updateSwingTime (6-tick swing duration).
|
||||
@@ -1126,6 +1132,17 @@ pub fn voice_sounds(m: &Mob) -> [&'static str; 3] {
|
||||
match m.species() {
|
||||
Species::Nautilus | Species::ZombieNautilus => super::nautilus::sounds(m),
|
||||
Species::SulfurCube => super::sulfur_cube::sounds(m),
|
||||
// Panda.getAmbientSound.
|
||||
Species::Panda => {
|
||||
let ambient = if super::panda::is_aggressive(m) {
|
||||
"entity.panda.aggressive_ambient"
|
||||
} else if super::panda::is_worried(m) {
|
||||
"entity.panda.worried_ambient"
|
||||
} else {
|
||||
m.kind.sounds[0]
|
||||
};
|
||||
[ambient, m.kind.sounds[1], m.kind.sounds[2]]
|
||||
}
|
||||
// The sound variant's baby_sounds (classic sets, like the rest here).
|
||||
Species::Pig if m.is_baby() => [
|
||||
"entity.baby_pig.ambient",
|
||||
@@ -1324,6 +1341,11 @@ pub fn accepts_damage(m: &mut Mob, source: &Damage, _amount: f32) -> bool {
|
||||
super::bee::hurt(m);
|
||||
true
|
||||
}
|
||||
// Panda.hurtServer: up first, whatever the damage.
|
||||
Species::Panda => {
|
||||
super::panda::hurt(m);
|
||||
true
|
||||
}
|
||||
Species::Enderman => super::enderman::on_damage(m, source),
|
||||
Species::WitherSkeleton | Species::Blaze | Species::MagmaCube | Species::Strider
|
||||
if source.is_fire() =>
|
||||
@@ -1375,6 +1397,9 @@ pub fn do_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
if m.species() == Species::Ravager {
|
||||
super::ravager::on_attack(m, cx.events);
|
||||
}
|
||||
if m.species() == Species::Panda {
|
||||
super::panda::bit(m);
|
||||
}
|
||||
if super::creaking::is_creaking(m) {
|
||||
super::creaking::on_attack(m, cx.events);
|
||||
}
|
||||
@@ -1453,6 +1478,12 @@ pub fn do_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
if super::creaking::is_creaking(m) {
|
||||
m.voice("entity.creaking.attack", cx.events);
|
||||
}
|
||||
// Panda.playAttackSound: playSound(PANDA_BITE, 1.0, 1.0).
|
||||
if m.species() == Species::Panda && !m.silent {
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
cx.events
|
||||
.push(MobEvent::Sound("entity.panda.bite", at, 1.0, 1.0));
|
||||
}
|
||||
// Axolotl.playAttackSound: playSound(AXOLOTL_ATTACK, 1.0, 1.0).
|
||||
if m.species() == Species::Axolotl {
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
|
||||
@@ -960,7 +960,7 @@ pub fn anim(m: &Mob, s: &State, p: &mut Poses, a: &Animations) -> bool {
|
||||
match m.species() {
|
||||
Species::Goat => goat(p, s, &Goat::from_mob(m)),
|
||||
Species::PolarBear => polar_bear(p, s, 0.0),
|
||||
Species::Panda => panda(p, s, &Panda::default()),
|
||||
Species::Panda => panda(p, s, &super::panda::pose(m, s.partial)),
|
||||
Species::Llama | Species::TraderLlama => {
|
||||
llama(p, s, m.extra.chested && !s.baby);
|
||||
}
|
||||
|
||||
@@ -135,6 +135,12 @@ impl Mob {
|
||||
if self.species() == super::Species::Rabbit {
|
||||
return super::rabbit::move_control(self, w);
|
||||
}
|
||||
// Panda.PandaMoveControl: only while it can act.
|
||||
if self.species() == super::Species::Panda
|
||||
&& !super::panda::can_perform_action(self, w.thundering)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let attr_speed = self.movement_speed();
|
||||
match self.ai.mov.kind {
|
||||
MoveKind::Custom => super::ai::custom_move_control(self, w, events),
|
||||
|
||||
@@ -244,7 +244,13 @@ pub fn slot_item(m: &Mob, slot: &str) -> Option<LootStack> {
|
||||
}
|
||||
_ => (None, None),
|
||||
};
|
||||
let mut stack = loot_stack(item?, 1);
|
||||
// A panda keeps the whole stack it picked up in its mouth.
|
||||
let count = if slot == "mainhand" && m.species() == Species::Panda {
|
||||
super::panda::held_count(m)
|
||||
} else {
|
||||
1
|
||||
};
|
||||
let mut stack = loot_stack(item?, count as i32);
|
||||
if let (Some(index), Some(g)) = (index, gear::gear(m)) {
|
||||
for (e, l) in &g.slots[index] {
|
||||
stack.enchantments.push((e.to_string(), *l as i32));
|
||||
|
||||
@@ -1691,13 +1691,7 @@ impl<L: FinalizeLevel + ?Sized, R: RandomSource> Ctx<'_, L, R> {
|
||||
let hidden = panda_gene(self.int(16));
|
||||
m.extra.variant = main;
|
||||
m.extra.variant2 = hidden;
|
||||
let shown = panda_variant(main, hidden);
|
||||
if shown == 5 {
|
||||
set_base(m, Attr::MaxHealth, 10.0);
|
||||
}
|
||||
if shown == 1 {
|
||||
set_base(m, Attr::MovementSpeed, f64::from(0.07f32));
|
||||
}
|
||||
super::panda::set_attributes(m);
|
||||
self.ageable(m, g.or(Some(Group::Ageable(Ageable::chance(0.2)))))
|
||||
}
|
||||
S::PolarBear | S::Ocelot => {
|
||||
@@ -1950,7 +1944,7 @@ fn set_memory(m: &mut Mob, name: &'static str, value: i64, ttl: i64) {
|
||||
}
|
||||
/// `Panda.Gene.getRandom` (enum order: normal, lazy, worried, playful,
|
||||
/// brown, weak, aggressive).
|
||||
fn panda_gene(roll: i32) -> u8 {
|
||||
pub fn panda_gene(roll: i32) -> u8 {
|
||||
match roll {
|
||||
0 => 1,
|
||||
1 => 2,
|
||||
|
||||
@@ -1422,6 +1422,9 @@ pub struct HurtByTarget {
|
||||
/// `Bee.BeeHurtByOtherGoal`: kept only while angry, and alerting others
|
||||
/// only when the attacker is in sight.
|
||||
pub bee: bool,
|
||||
/// Whom `alertOther` calls: a filter on the mob (`PandaHurtByTargetGoal`
|
||||
/// calls aggressive pandas only).
|
||||
pub alert_if: Option<fn(&Seen) -> bool>,
|
||||
timestamp: i32,
|
||||
st: TargetState,
|
||||
}
|
||||
@@ -1432,6 +1435,7 @@ impl HurtByTarget {
|
||||
alert_except: vec![],
|
||||
ignore: vec![],
|
||||
bee: false,
|
||||
alert_if: None,
|
||||
timestamp: 0,
|
||||
st: TargetState {
|
||||
unseen_memory: 300,
|
||||
@@ -1451,6 +1455,10 @@ impl HurtByTarget {
|
||||
self.bee = true;
|
||||
self
|
||||
}
|
||||
pub fn alert_if(mut self, f: fn(&Seen) -> bool) -> Self {
|
||||
self.alert_if = Some(f);
|
||||
self
|
||||
}
|
||||
}
|
||||
impl Default for HurtByTarget {
|
||||
fn default() -> Self {
|
||||
@@ -1520,6 +1528,7 @@ impl Goal for HurtByTarget {
|
||||
&& (s.position.z - pos.z).abs() <= range + 1.0
|
||||
})
|
||||
.filter(|s| !self.alert_except.contains(&s.species))
|
||||
.filter(|s| self.alert_if.is_none_or(|f| f(s)))
|
||||
.filter(|s| Who::Mob(s.id) != by)
|
||||
.map(|s| s.id)
|
||||
.collect();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -137,6 +137,10 @@ pub fn body(m: &Mob) -> (String, String) {
|
||||
baby_or(m, "wolf#main", "wolf_baby#main"),
|
||||
super::tame::texture(m),
|
||||
),
|
||||
S::Panda => (
|
||||
baby_or(m, "panda#main", "panda_baby#main"),
|
||||
super::panda::texture(m),
|
||||
),
|
||||
S::HappyGhast => (
|
||||
baby_or(m, "happy_ghast#main", "happy_ghast_baby#main"),
|
||||
if baby {
|
||||
@@ -854,6 +858,7 @@ fn flip_degrees(m: &Mob) -> f32 {
|
||||
fn species_rotations(m: &Mob, alpha: f32) -> glam::Mat4 {
|
||||
match m.species() {
|
||||
Species::Cat => super::tame::cat_rotations(m, alpha),
|
||||
Species::Panda => super::panda::rotations(m, alpha),
|
||||
Species::Shulker => super::shulker::rotations(m),
|
||||
_ => glam::Mat4::IDENTITY,
|
||||
}
|
||||
@@ -1279,6 +1284,12 @@ pub fn held_item_transform(
|
||||
data: &MobData,
|
||||
left: bool,
|
||||
) -> Option<glam::Mat4> {
|
||||
// PandaHoldsItemLayer: the main hand's item in its mouth.
|
||||
if m.species() == Species::Panda {
|
||||
return super::panda::item_offset(m, alpha)
|
||||
.filter(|_| !left)
|
||||
.map(|offset| base_transform(m, alpha, camera) * offset);
|
||||
}
|
||||
if !super::illager::shows_item(m) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user