Make horses, donkeys and mules rideable
Horses get random health, speed and jump strength, coat colours with markings, grazing, rearing and AbstractEquineModel's animation. Feeding heals, grows foals and builds temper; riding an untamed horse ends with it tamed or bucking the rider off. Saddles, horse armour and donkey chests fit with a click, a saddled mount follows its rider with the charged jump bar, its health replaces the food bar, and offspring inherit their parents' stats (a horse and a donkey have a mule). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -190,6 +190,47 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
);
|
||||
map.insert("TimeInOverworld".into(), Tag::Int(m.extra.counter2));
|
||||
}
|
||||
"minecraft:horse"
|
||||
| "minecraft:donkey"
|
||||
| "minecraft:mule"
|
||||
| "minecraft:skeleton_horse"
|
||||
| "minecraft:zombie_horse" => {
|
||||
map.insert("Tame".into(), Tag::Byte(i8::from(m.extra.tame)));
|
||||
map.insert("Temper".into(), Tag::Int(i32::from(m.extra.variant3)));
|
||||
if let Some(owner) = m.extra.owner {
|
||||
map.insert("Owner".into(), Tag::IntArray(owner.to_vec()));
|
||||
}
|
||||
if id == "minecraft:horse" {
|
||||
let v = i32::from(m.extra.variant) | i32::from(m.extra.variant2) << 8;
|
||||
map.insert("Variant".into(), Tag::Int(v));
|
||||
}
|
||||
map.insert("ChestedHorse".into(), Tag::Byte(i8::from(m.extra.chested)));
|
||||
let mut equipment = Vec::new();
|
||||
if m.extra.saddled {
|
||||
equipment.push((
|
||||
"saddle",
|
||||
Tag::compound([("id", string("minecraft:saddle")), ("count", Tag::Int(1))]),
|
||||
));
|
||||
}
|
||||
if let Some(armor) = &m.extra.head {
|
||||
equipment.push((
|
||||
"body",
|
||||
Tag::compound([("id", string(armor)), ("count", Tag::Int(1))]),
|
||||
));
|
||||
}
|
||||
map.insert("equipment".into(), Tag::compound(equipment));
|
||||
let attr = |id: &str, v: f64| {
|
||||
Tag::compound([("id", string(id)), ("base", Tag::Double(v.to_bits()))])
|
||||
};
|
||||
map.insert(
|
||||
"attributes".into(),
|
||||
Tag::List(vec![
|
||||
attr("minecraft:max_health", f64::from(m.attrs.max_health)),
|
||||
attr("minecraft:movement_speed", m.attrs.speed),
|
||||
attr("minecraft:jump_strength", m.extra.vector[0]),
|
||||
]),
|
||||
);
|
||||
}
|
||||
"minecraft:slime" | "minecraft:magma_cube" => {
|
||||
map.insert("Size".into(), Tag::Int(m.extra.size.max(1) - 1));
|
||||
map.insert("wasOnGround".into(), Tag::Byte(i8::from(m.extra.flag2)));
|
||||
@@ -267,6 +308,38 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
m.extra.flag2 = flag(tag, "IsImmuneToZombification");
|
||||
m.extra.counter2 = number(tag.get("TimeInOverworld")).unwrap_or(0) as i32;
|
||||
}
|
||||
if crate::mobs::equine::is_equine(m.species()) {
|
||||
m.extra.tame = flag(tag, "Tame");
|
||||
m.extra.variant3 = number(tag.get("Temper")).unwrap_or(0).clamp(0, 100) as u8;
|
||||
m.extra.owner = crate::save::uuid_from_tag(tag.get("Owner"));
|
||||
let v = number(tag.get("Variant")).unwrap_or(0) as i32;
|
||||
m.extra.variant = (v & 0xFF).clamp(0, 6) as u8;
|
||||
m.extra.variant2 = ((v >> 8) & 0xFF).clamp(0, 4) as u8;
|
||||
m.extra.chested = flag(tag, "ChestedHorse");
|
||||
let eq = tag.get("equipment");
|
||||
m.extra.saddled = eq.and_then(|e| e.get("saddle")).is_some();
|
||||
m.extra.head = eq
|
||||
.and_then(|e| e.get("body"))
|
||||
.and_then(|b| text(b.get("id")))
|
||||
.map(Into::into);
|
||||
if let Some(Tag::List(attrs)) = tag.get("attributes") {
|
||||
for a in attrs {
|
||||
let (Some(id), Some(Tag::Double(bits))) = (text(a.get("id")), a.get("base")) else {
|
||||
continue;
|
||||
};
|
||||
let v = f64::from_bits(*bits);
|
||||
match id.as_str() {
|
||||
"minecraft:max_health" => m.attrs.max_health = v as f32,
|
||||
"minecraft:movement_speed" => m.attrs.speed = v,
|
||||
"minecraft:jump_strength" => m.extra.vector[0] = v,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.extra.vector[0] <= 0.0 {
|
||||
m.extra.vector[0] = 0.7;
|
||||
}
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Cat {
|
||||
m.extra.owner = crate::save::uuid_from_tag(tag.get("Owner"));
|
||||
m.extra.tame = m.extra.owner.is_some();
|
||||
|
||||
@@ -27,6 +27,7 @@ mod lightning;
|
||||
mod machines;
|
||||
mod maps;
|
||||
mod minecarts;
|
||||
mod mounts;
|
||||
mod music;
|
||||
mod names;
|
||||
mod options;
|
||||
@@ -610,6 +611,7 @@ struct Game<'a> {
|
||||
remote: Option<remote::Remote>,
|
||||
ui: chat::UiState,
|
||||
combat: combat::CombatTracker,
|
||||
mount: mounts::MountState,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Dim {
|
||||
@@ -2172,7 +2174,7 @@ impl Game<'_> {
|
||||
backward: held(KeyCode::KeyS),
|
||||
left: held(KeyCode::KeyA),
|
||||
right: held(KeyCode::KeyD),
|
||||
jump: false,
|
||||
jump: held(KeyCode::Space),
|
||||
shift: held(KeyCode::ShiftLeft),
|
||||
sprint: false,
|
||||
};
|
||||
@@ -2730,27 +2732,36 @@ impl Game<'_> {
|
||||
// Hud: the action bar and titles draw over the hotbar (nextStratum).
|
||||
self.draw_boss_bar(&mut batch);
|
||||
self.draw_titles(&mut batch);
|
||||
// Gui.renderVehicleHealth / the jump bar while riding a mount.
|
||||
let mounted = !self.creative && !spectator && self.draw_mount_hud(&mut batch, w, h);
|
||||
let atlas = &self.res.atlas;
|
||||
if !self.creative
|
||||
&& !spectator
|
||||
&& let Some(p) = &self.player
|
||||
{
|
||||
// Experience bar and hearts/food (Gui.renderPlayerHealth).
|
||||
batch.sprite(
|
||||
atlas,
|
||||
"gui/sprites/hud/experience_bar_background",
|
||||
w / 2.0 - 91.0,
|
||||
h - 29.0,
|
||||
);
|
||||
let filled = (self.experience.progress * 183.0).floor() / 182.0;
|
||||
if filled > 0.0 {
|
||||
batch.sprite_part(
|
||||
let saddled_mount = mounted
|
||||
&& self
|
||||
.riding
|
||||
.and_then(|id| self.mobs.iter().find(|m| m.id == id))
|
||||
.is_some_and(|m| m.extra.saddled);
|
||||
if !saddled_mount {
|
||||
batch.sprite(
|
||||
atlas,
|
||||
"gui/sprites/hud/experience_bar_progress",
|
||||
"gui/sprites/hud/experience_bar_background",
|
||||
w / 2.0 - 91.0,
|
||||
h - 29.0,
|
||||
filled.min(1.0),
|
||||
);
|
||||
let filled = (self.experience.progress * 183.0).floor() / 182.0;
|
||||
if filled > 0.0 {
|
||||
batch.sprite_part(
|
||||
atlas,
|
||||
"gui/sprites/hud/experience_bar_progress",
|
||||
w / 2.0 - 91.0,
|
||||
h - 29.0,
|
||||
filled.min(1.0),
|
||||
);
|
||||
}
|
||||
}
|
||||
if self.experience.level > 0 {
|
||||
// Gui.renderExperienceLevel: green text with a black outline.
|
||||
@@ -2780,7 +2791,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
let food = p.health.food.food;
|
||||
for i in 0..10 {
|
||||
for i in (0..10).filter(|_| !mounted) {
|
||||
let x = w / 2.0 + 91.0 - i as f32 * 8.0 - 9.0;
|
||||
batch.sprite(atlas, "gui/sprites/hud/food_empty", x, top);
|
||||
let v = food - i * 2;
|
||||
@@ -4218,7 +4229,9 @@ impl Game<'_> {
|
||||
Arc::new(c)
|
||||
}
|
||||
fn tick_mobs(&mut self) -> Result<()> {
|
||||
self.tick_creatures()
|
||||
self.tick_creatures()?;
|
||||
self.position_rider();
|
||||
Ok(())
|
||||
}
|
||||
/// SkyRenderer.renderSunMoonAndStars: bodies on a frame rotated Y -90 then X by angle.
|
||||
fn celestial_geometry(&self, sky: &horizon_client::environment::Sky) -> Vec<Vertex> {
|
||||
@@ -7475,6 +7488,7 @@ pub fn run() -> Result<()> {
|
||||
remote: None,
|
||||
ui: Default::default(),
|
||||
combat: Default::default(),
|
||||
mount: Default::default(),
|
||||
};
|
||||
game.ui.vanilla_root = vanilla_root;
|
||||
game.res.atlas.font.uniform = game.settings.force_unicode;
|
||||
|
||||
@@ -399,7 +399,7 @@ impl Game<'_> {
|
||||
/// 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<()> {
|
||||
let Some(i) = self.boats.iter().position(|b| Some(b.id) == self.riding) else {
|
||||
if self.tick_cart_riding(keys) {
|
||||
if self.tick_cart_riding(keys) || self.tick_mount_riding(keys) {
|
||||
return Ok(());
|
||||
}
|
||||
self.riding = None;
|
||||
|
||||
@@ -690,6 +690,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
MobEvent::FinishAdmiring { mob } => self.finish_admiring(mob),
|
||||
MobEvent::Tamed { .. } | MobEvent::Buck { .. } => self.mount_event(&e),
|
||||
MobEvent::Launch { target, up } => match target {
|
||||
Who::Player => {
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
@@ -868,11 +869,45 @@ impl Game<'_> {
|
||||
let q = self.mobs.iter().find(|m| m.id == partner).cloned();
|
||||
let coin = self.world.random.next_int_bound(2).unwrap_or(0) == 0;
|
||||
let coin2 = self.world.random.next_int_bound(2).unwrap_or(0) == 0;
|
||||
if let Some(id) =
|
||||
self.spawn_mob(&p.kind.id, [p.position.x, p.position.y, p.position.z], true)
|
||||
// A horse and a donkey have a mule.
|
||||
let kind = match (p.species(), q.as_ref().map(|q| q.species())) {
|
||||
(Species::Horse, Some(Species::Donkey)) | (Species::Donkey, Some(Species::Horse)) => {
|
||||
"minecraft:mule".to_owned()
|
||||
}
|
||||
_ => p.kind.id.clone(),
|
||||
};
|
||||
if let Some(id) = self.spawn_mob(&kind, [p.position.x, p.position.y, p.position.z], true)
|
||||
&& let Some(child) = self.mobs.iter_mut().find(|m| m.id == id)
|
||||
{
|
||||
child.extra.age = -24000;
|
||||
if horizon_client::mobs::equine::is_equine(p.species()) {
|
||||
let other = q.clone().unwrap_or_else(|| p.clone());
|
||||
let mut r = self.world.random.clone();
|
||||
horizon_client::mobs::equine::inherit(child, &p, &other, &mut r);
|
||||
// Horse.getBreedOffspring: coat from either parent or new.
|
||||
if p.species() == Species::Horse && other.species() == Species::Horse {
|
||||
let c = r.next_int_bound(9).unwrap_or(0);
|
||||
child.extra.variant = if c < 4 {
|
||||
p.extra.variant
|
||||
} else if c < 8 {
|
||||
other.extra.variant
|
||||
} else {
|
||||
r.next_int_bound(7).unwrap_or(0) as u8
|
||||
};
|
||||
let mk = r.next_int_bound(5).unwrap_or(0);
|
||||
child.extra.variant2 = if mk < 2 {
|
||||
p.extra.variant2
|
||||
} else if mk < 4 {
|
||||
other.extra.variant2
|
||||
} else {
|
||||
r.next_int_bound(5).unwrap_or(0) as u8
|
||||
};
|
||||
}
|
||||
self.world.random = r;
|
||||
let xp = 1 + self.world.random.next_int_bound(7).unwrap_or(0) as u32;
|
||||
self.spawn_orbs([p.position.x, p.position.y, p.position.z], xp);
|
||||
return;
|
||||
}
|
||||
if p.species() == Species::Cat {
|
||||
// Cat.getBreedOffspring.
|
||||
let other = q.as_ref().unwrap_or(&p);
|
||||
@@ -1367,6 +1402,11 @@ impl Game<'_> {
|
||||
.unwrap_or_default();
|
||||
let creative = self.creative;
|
||||
let selected = self.selected;
|
||||
// AbstractHorse.mobInteract: feed, equip or ride.
|
||||
if self.interact_mount(index, &item) {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
// PiglinAi.mobInteract: hand over something gold to admire.
|
||||
if self.mobs[index].alive() && self.give_piglin(index, &item) {
|
||||
self.swing_arm();
|
||||
|
||||
@@ -0,0 +1,337 @@
|
||||
//! Riding horses, donkeys and mules: feeding (`handleEating`), saddles,
|
||||
//! armour and chests, mounting, the rider's control and jump bar
|
||||
//! (`LocalPlayer.aiStep`'s riding jump), positioning, dismounting, and the
|
||||
//! mount's health and jump bar on the HUD.
|
||||
use super::Game;
|
||||
use horizon_client::{
|
||||
hud::HudBatch,
|
||||
mobs::{MobEvent, Species, equine},
|
||||
sprint::Keys,
|
||||
};
|
||||
use horizon_core::{geometry::Vec3, random::RandomSource};
|
||||
|
||||
/// `passengerAttachments` minus the player's 0.6 vehicle attachment.
|
||||
fn seat(s: Species) -> f64 {
|
||||
let attach = match s {
|
||||
Species::Horse => 1.44375,
|
||||
Species::Donkey => 1.1125,
|
||||
Species::Mule => 1.2125,
|
||||
_ => 1.31875,
|
||||
};
|
||||
attach - 0.6
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub(super) struct MountState {
|
||||
/// `jumpRidingTicks`: -10 cooling down after a jump, >= 0 charging.
|
||||
jump_ticks: i32,
|
||||
/// `jumpRidingScale` (0..1).
|
||||
pub(super) jump_scale: f32,
|
||||
was_jumping: bool,
|
||||
}
|
||||
impl Game<'_> {
|
||||
fn mount_index(&self) -> Option<usize> {
|
||||
let id = self.riding?;
|
||||
self.mobs.iter().position(|m| m.id == id)
|
||||
}
|
||||
/// `AbstractHorse.mobInteract`. Returns whether the click was used.
|
||||
pub(super) fn interact_mount(&mut self, index: usize, item: &str) -> bool {
|
||||
let m = &self.mobs[index];
|
||||
let species = m.species();
|
||||
if !equine::is_equine(species) || !m.alive() || Some(m.id) == self.riding {
|
||||
return false;
|
||||
}
|
||||
if self.feed_mount(index, item) {
|
||||
return true;
|
||||
}
|
||||
let m = &mut self.mobs[index];
|
||||
if m.is_baby() {
|
||||
return false;
|
||||
}
|
||||
let at = m.center();
|
||||
let tamed = m.extra.tame;
|
||||
let sound = if item == "minecraft:saddle" && tamed && !m.extra.saddled {
|
||||
m.extra.saddled = true;
|
||||
Some("minecraft:entity.horse.saddle")
|
||||
} else if item.ends_with("_horse_armor")
|
||||
&& species == Species::Horse
|
||||
&& tamed
|
||||
&& m.extra.head.is_none()
|
||||
{
|
||||
m.extra.head = Some(item.into());
|
||||
Some("minecraft:entity.horse.armor")
|
||||
} else if item == "minecraft:chest"
|
||||
&& matches!(species, Species::Donkey | Species::Mule)
|
||||
&& tamed
|
||||
&& !m.extra.chested
|
||||
{
|
||||
m.extra.chested = true;
|
||||
Some("minecraft:entity.donkey.chest")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(sound) = sound {
|
||||
let pitch =
|
||||
(self.world.random.next_float() - self.world.random.next_float()) * 0.2 + 1.0;
|
||||
self.audio.play(sound, Some(at), 0.5, pitch);
|
||||
self.consume_held();
|
||||
self.world
|
||||
.modified
|
||||
.insert((at[0].floor() as i32 >> 4, at[2].floor() as i32 >> 4));
|
||||
return true;
|
||||
}
|
||||
// doPlayerRide
|
||||
let m = &mut self.mobs[index];
|
||||
m.extra.flag = false;
|
||||
m.extra.counter = 0;
|
||||
self.yaw = m.yaw;
|
||||
self.riding = Some(m.id);
|
||||
self.mount.jump_ticks = 0;
|
||||
self.mount.jump_scale = 0.0;
|
||||
true
|
||||
}
|
||||
/// `AbstractHorse.handleEating`.
|
||||
fn feed_mount(&mut self, index: usize, item: &str) -> bool {
|
||||
let (heal, age_up, temper, love) = match item {
|
||||
"minecraft:wheat" => (2.0, 20, 3, false),
|
||||
"minecraft:sugar" => (1.0, 30, 3, false),
|
||||
"minecraft:hay_block" => (20.0, 180, 0, false),
|
||||
"minecraft:apple" => (3.0, 60, 3, false),
|
||||
"minecraft:red_mushroom" => (3.0, 0, 3, false),
|
||||
"minecraft:carrot" => (3.0, 60, 3, false),
|
||||
"minecraft:golden_carrot" => (4.0, 60, 5, true),
|
||||
"minecraft:golden_apple" | "minecraft:enchanted_golden_apple" => (10.0, 240, 10, true),
|
||||
_ => return false,
|
||||
};
|
||||
let m = &mut self.mobs[index];
|
||||
if matches!(m.species(), Species::SkeletonHorse | Species::ZombieHorse) {
|
||||
return false;
|
||||
}
|
||||
let mut used = false;
|
||||
if love && m.extra.tame && m.extra.age == 0 && m.extra.in_love <= 0 {
|
||||
m.extra.in_love = 600;
|
||||
m.extra.love_player = true;
|
||||
used = true;
|
||||
}
|
||||
if m.health < m.attrs.max_health && heal > 0.0 {
|
||||
m.health = (m.health + heal).min(m.attrs.max_health);
|
||||
used = true;
|
||||
}
|
||||
if m.is_baby() && age_up > 0 && !m.extra.age_locked {
|
||||
m.extra.age = (m.extra.age + age_up * 20).min(0);
|
||||
used = true;
|
||||
}
|
||||
if temper > 0 && (used || !m.extra.tame) && m.extra.variant3 < 100 {
|
||||
m.extra.variant3 = (m.extra.variant3 + temper).min(100);
|
||||
used = true;
|
||||
}
|
||||
if !used {
|
||||
return false;
|
||||
}
|
||||
// eating(): the mouth opens and the horse eats.
|
||||
m.anim.v[2] = 1.0;
|
||||
let at = m.center();
|
||||
let sound = match m.species() {
|
||||
Species::Donkey => "minecraft:entity.donkey.eat",
|
||||
Species::Mule => "minecraft:entity.mule.eat",
|
||||
_ => "minecraft:entity.horse.eat",
|
||||
};
|
||||
let pitch = (self.world.random.next_float() - self.world.random.next_float()) * 0.2 + 1.0;
|
||||
self.audio.play(sound, Some(at), 1.0, pitch);
|
||||
self.consume_held();
|
||||
true
|
||||
}
|
||||
/// The rider's input for this tick; returns false when not on a mount.
|
||||
pub(super) fn tick_mount_riding(&mut self, keys: Keys) -> bool {
|
||||
let Some(i) = self.mount_index() else {
|
||||
return false;
|
||||
};
|
||||
if keys.shift || !self.mobs[i].alive() {
|
||||
self.dismount_mount();
|
||||
return true;
|
||||
}
|
||||
let strafe = f32::from(u8::from(keys.left)) - f32::from(u8::from(keys.right));
|
||||
let forward = f32::from(u8::from(keys.forward)) - f32::from(u8::from(keys.backward));
|
||||
// LocalPlayer.aiStep: the riding jump charges while space is held.
|
||||
let saddled = self.mobs[i].extra.saddled;
|
||||
let mut jump = 0.0;
|
||||
if saddled {
|
||||
let st = &mut self.mount;
|
||||
if st.jump_ticks < 0 {
|
||||
st.jump_ticks += 1;
|
||||
if st.jump_ticks == 0 {
|
||||
st.jump_scale = 0.0;
|
||||
}
|
||||
}
|
||||
if st.was_jumping && !keys.jump {
|
||||
st.jump_ticks = -10;
|
||||
let amount = (st.jump_scale * 100.0).floor() as i32;
|
||||
// PlayerRideableJumping.getPlayerJumpPendingScale
|
||||
jump = if amount >= 90 {
|
||||
1.0
|
||||
} else {
|
||||
0.4 + 0.4 * amount as f32 / 90.0
|
||||
};
|
||||
} else if !st.was_jumping && keys.jump {
|
||||
st.jump_ticks = 0;
|
||||
st.jump_scale = 0.0;
|
||||
} else if st.was_jumping {
|
||||
st.jump_ticks += 1;
|
||||
st.jump_scale = if st.jump_ticks < 10 {
|
||||
st.jump_ticks as f32 * 0.1
|
||||
} else {
|
||||
0.8 + 2.0 / (st.jump_ticks - 9) as f32 * 0.1
|
||||
};
|
||||
}
|
||||
st.was_jumping = keys.jump;
|
||||
}
|
||||
let m = &mut self.mobs[i];
|
||||
if jump > 0.0 {
|
||||
// onPlayerJump: rear while jumping (horses).
|
||||
if matches!(
|
||||
m.species(),
|
||||
Species::Horse | Species::SkeletonHorse | Species::ZombieHorse
|
||||
) {
|
||||
m.extra.counter = 20;
|
||||
}
|
||||
let sound = "minecraft:entity.horse.jump";
|
||||
let at = m.center();
|
||||
self.audio.play(sound, Some(at), 0.4, 1.0);
|
||||
}
|
||||
let m = &mut self.mobs[i];
|
||||
let pending = m.rider.map_or(0.0, |r| r.jump);
|
||||
m.rider = Some(equine::Rider {
|
||||
strafe,
|
||||
forward,
|
||||
yaw: self.yaw,
|
||||
pitch: self.pitch,
|
||||
jump: if jump > 0.0 { jump } else { pending },
|
||||
});
|
||||
true
|
||||
}
|
||||
/// `positionRider`: the player sits on the mount after it moves.
|
||||
pub(super) fn position_rider(&mut self) {
|
||||
let Some(i) = self.mount_index() else {
|
||||
return;
|
||||
};
|
||||
let m = &self.mobs[i];
|
||||
let at = Vec3::new(m.position.x, m.position.y + seat(m.species()), m.position.z);
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
self.previous_position = p.position;
|
||||
p.position = at;
|
||||
p.velocity = Vec3::ZERO;
|
||||
p.fall_distance = 0.0;
|
||||
}
|
||||
}
|
||||
/// `removePassenger` + `getDismountLocationForPassenger`: beside the mount.
|
||||
pub(super) fn dismount_mount(&mut self) {
|
||||
let Some(id) = self.riding.take() else {
|
||||
return;
|
||||
};
|
||||
let Some(m) = self.mobs.iter_mut().find(|m| m.id == id) else {
|
||||
return;
|
||||
};
|
||||
m.rider = None;
|
||||
let yaw = m.yaw.to_radians();
|
||||
let side = Vec3::new(f64::from(yaw.cos()), 0.0, f64::from(yaw.sin()));
|
||||
let w = f64::from(m.width()) / 2.0 + 0.4;
|
||||
let base = m.position;
|
||||
let candidates = [
|
||||
Vec3::new(base.x - side.x * w, base.y, base.z - side.z * w),
|
||||
Vec3::new(base.x + side.x * w, base.y, base.z + side.z * w),
|
||||
Vec3::new(base.x, base.y + f64::from(m.height()), base.z),
|
||||
];
|
||||
let spot = candidates
|
||||
.into_iter()
|
||||
.find(|c| {
|
||||
let f = |dy: i32| {
|
||||
self.res
|
||||
.facts
|
||||
.get(self.world.block(
|
||||
c.x.floor() as i32,
|
||||
c.y.floor() as i32 + dy,
|
||||
c.z.floor() as i32,
|
||||
))
|
||||
.full_collision
|
||||
};
|
||||
!f(0) && !f(1)
|
||||
})
|
||||
.unwrap_or(candidates[2]);
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
p.position = spot;
|
||||
p.velocity = Vec3::ZERO;
|
||||
}
|
||||
}
|
||||
pub(super) fn mount_event(&mut self, e: &MobEvent) {
|
||||
match *e {
|
||||
MobEvent::Tamed { mob } => {
|
||||
let owner = self.level.player_uuid.or(Some([0, 0, 0, 1]));
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == mob) {
|
||||
m.extra.owner = owner;
|
||||
m.persistent = true;
|
||||
let at = [
|
||||
m.position.x,
|
||||
m.position.y + f64::from(m.height()) * 0.5 + 0.5,
|
||||
m.position.z,
|
||||
];
|
||||
let _ = self.handle_mob_events(vec![MobEvent::Particles {
|
||||
kind: "heart",
|
||||
at,
|
||||
count: 7,
|
||||
}]);
|
||||
}
|
||||
}
|
||||
MobEvent::Buck { mob } if self.riding == Some(mob) => self.dismount_mount(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// `Gui.renderVehicleHealth` and the jump bar (`JumpableVehicleBarRenderer`).
|
||||
pub(super) fn draw_mount_hud(&self, batch: &mut HudBatch, w: f32, h: f32) -> bool {
|
||||
let Some(i) = self.mount_index() else {
|
||||
return false;
|
||||
};
|
||||
let m = &self.mobs[i];
|
||||
let atlas = &self.res.atlas;
|
||||
// Hearts in rows of ten, right-aligned where the food bar sits.
|
||||
let max = (m.attrs.max_health + 0.5) as i32 / 2;
|
||||
let health = m.health.ceil() as i32;
|
||||
let right = w / 2.0 + 91.0;
|
||||
let mut y = h - 39.0;
|
||||
let mut drawn = 0;
|
||||
while drawn < max {
|
||||
let row = (max - drawn).min(10);
|
||||
for k in 0..row {
|
||||
let x = right - k as f32 * 8.0 - 9.0;
|
||||
batch.sprite(atlas, "gui/sprites/hud/heart/vehicle_container", x, y);
|
||||
let v = health - (drawn + k) * 2;
|
||||
if v >= 2 {
|
||||
batch.sprite(atlas, "gui/sprites/hud/heart/vehicle_full", x, y);
|
||||
} else if v == 1 {
|
||||
batch.sprite(atlas, "gui/sprites/hud/heart/vehicle_half", x, y);
|
||||
}
|
||||
}
|
||||
drawn += row;
|
||||
y -= 10.0;
|
||||
}
|
||||
// The jump bar replaces the experience bar on a saddled jumper.
|
||||
if m.extra.saddled {
|
||||
let x = w / 2.0 - 91.0;
|
||||
let y = h - 29.0;
|
||||
batch.sprite(atlas, "gui/sprites/hud/jump_bar_background", x, y);
|
||||
if self.mount.jump_ticks < 0 {
|
||||
batch.sprite(atlas, "gui/sprites/hud/jump_bar_cooldown", x, y);
|
||||
} else {
|
||||
let filled = (self.mount.jump_scale * 183.0).floor();
|
||||
if filled > 0.0 {
|
||||
batch.sprite_part(
|
||||
atlas,
|
||||
"gui/sprites/hud/jump_bar_progress",
|
||||
x,
|
||||
y,
|
||||
filled / 182.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ pub mod control;
|
||||
pub mod cube;
|
||||
pub mod data;
|
||||
pub mod enderman;
|
||||
pub mod equine;
|
||||
pub mod farm;
|
||||
pub mod goals;
|
||||
pub mod golem;
|
||||
@@ -493,6 +494,8 @@ pub struct Mob {
|
||||
pub anim: anim::AnimState,
|
||||
/// Attribute values that differ per mob (slime size, babies, effects).
|
||||
pub attrs: Attrs,
|
||||
/// The player riding this mob and its input.
|
||||
pub rider: Option<equine::Rider>,
|
||||
}
|
||||
/// Events a mob tick asks the game to act on.
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -569,6 +572,14 @@ pub enum MobEvent {
|
||||
name: &'static str,
|
||||
effect: bool,
|
||||
},
|
||||
/// A horse's rider tamed it.
|
||||
Tamed {
|
||||
mob: u32,
|
||||
},
|
||||
/// A horse throws its rider off.
|
||||
Buck {
|
||||
mob: u32,
|
||||
},
|
||||
/// A piglin's admiring is over: barter or keep the item.
|
||||
FinishAdmiring {
|
||||
mob: u32,
|
||||
@@ -711,6 +722,7 @@ impl Mob {
|
||||
custom_name: None,
|
||||
name_visible: false,
|
||||
anim: anim::AnimState::default(),
|
||||
rider: None,
|
||||
attrs: Attrs {
|
||||
speed: kind.speed,
|
||||
attack_damage: kind.attack_damage,
|
||||
|
||||
@@ -76,6 +76,7 @@ pub enum Family {
|
||||
Illager,
|
||||
/// Piglins, brutes, hoglins and zoglins.
|
||||
Piglin,
|
||||
Equine,
|
||||
/// Slimes and magma cubes.
|
||||
Cube,
|
||||
}
|
||||
@@ -108,6 +109,7 @@ pub fn family(s: Species) -> Family {
|
||||
S::IronGolem | S::SnowGolem => Family::Golem,
|
||||
S::Pillager | S::Vindicator => Family::Illager,
|
||||
S::Piglin | S::PiglinBrute | S::Hoglin | S::Zoglin => Family::Piglin,
|
||||
S::Horse | S::Donkey | S::Mule | S::SkeletonHorse | S::ZombieHorse => Family::Equine,
|
||||
S::Enderman => Family::Enderman,
|
||||
S::Slime | S::MagmaCube => Family::Cube,
|
||||
_ => Family::Generic,
|
||||
@@ -130,6 +132,7 @@ pub fn register(m: &mut Mob) {
|
||||
Family::Golem => super::golem::register_snow(m),
|
||||
Family::Illager if m.species() == Species::Pillager => super::illager::register_pillager(m),
|
||||
Family::Illager => super::illager::register_vindicator(m),
|
||||
Family::Equine => super::equine::register(m),
|
||||
Family::Piglin => match m.species() {
|
||||
Species::Piglin => super::piglin::register_piglin(m),
|
||||
Species::PiglinBrute => super::piglin::register_brute(m),
|
||||
@@ -434,6 +437,11 @@ fn sun_burn_tick(m: &mut Mob, w: &MobWorld) -> bool {
|
||||
/// Mob.serverAiStep
|
||||
fn server_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
m.ai.no_action_time += 1;
|
||||
// A saddled mount follows its rider instead of its goals.
|
||||
if super::equine::controlled(m) {
|
||||
super::equine::ridden_step(m);
|
||||
return;
|
||||
}
|
||||
let tick_count = m.age as i64;
|
||||
let id_based = tick_count + i64::from(m.id);
|
||||
let mut targets = std::mem::take(&mut m.ai.targets);
|
||||
@@ -496,6 +504,7 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
super::piglin::ai_step(m, w, events)
|
||||
}
|
||||
Species::Zoglin if m.extra.anim_ticks > 0 => m.extra.anim_ticks -= 1,
|
||||
s if super::equine::is_equine(s) => super::equine::ai_step(m, w),
|
||||
Species::SnowGolem => super::golem::snow_ai_step(m, w, events),
|
||||
Species::Slime | Species::MagmaCube => super::cube::ai_step(m, w, events),
|
||||
Species::Chicken => farm::chicken_ai_step(m, w, events),
|
||||
|
||||
@@ -431,6 +431,20 @@ pub fn setup(
|
||||
Anim::IronGolem => super::golem::iron_anim(m, s, p),
|
||||
Anim::Illager => super::illager::anim(m, s, p),
|
||||
Anim::Piglin => super::piglin::piglin_anim(m, s, p),
|
||||
Anim::Horse => {
|
||||
super::equine::anim(m, s, p);
|
||||
// DonkeyModel: the chests show once fitted.
|
||||
if !m.extra.chested {
|
||||
for part in ["left_chest", "right_chest"] {
|
||||
if p.has(part) {
|
||||
let v = p.get(part);
|
||||
v[6] = 0.0;
|
||||
v[7] = 0.0;
|
||||
v[8] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Anim::Hoglin => super::piglin::hoglin_anim(m, s, p),
|
||||
Anim::Blaze => super::nether::blaze_anim(s, p),
|
||||
Anim::Ghast => super::nether::ghast_anim(s, p),
|
||||
|
||||
@@ -0,0 +1,460 @@
|
||||
//! Horses, donkeys, mules and the undead horses (`AbstractHorse`): random
|
||||
//! stats, coat colours and markings, eating, rearing, taming by riding,
|
||||
//! the ridden movement and jump, offspring stats and `AbstractEquineModel`.
|
||||
use super::{
|
||||
Mob, MobEvent, MobWorld, Species,
|
||||
anim::{Poses, State},
|
||||
goals::{
|
||||
Breed, Cx, Float, FollowParent, Goal, LookAtPlayer, MOVE, Panic, RandomLookAround, Stroll,
|
||||
Tempt, goal_clone,
|
||||
},
|
||||
};
|
||||
use horizon_core::random::RandomSource;
|
||||
use std::f32::consts::PI;
|
||||
|
||||
pub const COLORS: [&str; 7] = [
|
||||
"white",
|
||||
"creamy",
|
||||
"chestnut",
|
||||
"brown",
|
||||
"black",
|
||||
"gray",
|
||||
"darkbrown",
|
||||
];
|
||||
pub const MARKINGS: [&str; 5] = ["", "white", "whitefield", "whitedots", "blackdots"];
|
||||
|
||||
// AnimState slots.
|
||||
const EAT: usize = 0;
|
||||
const STAND: usize = 1;
|
||||
const MOUTH: usize = 2;
|
||||
|
||||
/// What a rider asks of its mount this tick.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Rider {
|
||||
pub strafe: f32,
|
||||
pub forward: f32,
|
||||
pub yaw: f32,
|
||||
pub pitch: f32,
|
||||
/// `playerJumpPendingScale` from the jump bar.
|
||||
pub jump: f32,
|
||||
}
|
||||
|
||||
pub fn is_equine(s: Species) -> bool {
|
||||
matches!(
|
||||
s,
|
||||
Species::Horse
|
||||
| Species::Donkey
|
||||
| Species::Mule
|
||||
| Species::SkeletonHorse
|
||||
| Species::ZombieHorse
|
||||
)
|
||||
}
|
||||
/// `canPerformRearing`: not donkeys or mules.
|
||||
fn can_rear(s: Species) -> bool {
|
||||
matches!(
|
||||
s,
|
||||
Species::Horse | Species::SkeletonHorse | Species::ZombieHorse
|
||||
)
|
||||
}
|
||||
pub fn register(m: &mut Mob) {
|
||||
let tempt = m.kind.tempt.clone();
|
||||
let rears = can_rear(m.species());
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(0, Float);
|
||||
g.add(1, MountPanic(Panic::new(1.2)));
|
||||
g.add(1, RunAroundLikeCrazy);
|
||||
g.add(2, Breed::new(1.0));
|
||||
g.add(3, Tempt::new(1.25, tempt, false));
|
||||
g.add(4, FollowParent::new(1.0));
|
||||
g.add(6, Stroll::avoiding_water(0.7));
|
||||
g.add(7, LookAtPlayer::new(6.0));
|
||||
g.add(8, RandomLookAround::default());
|
||||
if rears {
|
||||
g.add(9, RandomStand { next: -80 });
|
||||
}
|
||||
}
|
||||
/// `generateMaxHealth`, `generateSpeed`, `generateJumpStrength` and the coat.
|
||||
pub fn finalize(m: &mut Mob) {
|
||||
let r = &mut m.random;
|
||||
let health =
|
||||
15.0 + r.next_int_bound(8).unwrap_or(0) as f32 + r.next_int_bound(9).unwrap_or(0) as f32;
|
||||
let speed =
|
||||
(0.45 + r.next_double() * 0.3 + r.next_double() * 0.3 + r.next_double() * 0.3) * 0.25;
|
||||
let jump = 0.4 + r.next_double() * 0.2 + r.next_double() * 0.2 + r.next_double() * 0.2;
|
||||
match m.species() {
|
||||
Species::Horse => {
|
||||
m.attrs.max_health = health;
|
||||
m.attrs.speed = speed;
|
||||
m.extra.vector[0] = jump;
|
||||
m.extra.variant = m.random.next_int_bound(7).unwrap_or(0) as u8;
|
||||
m.extra.variant2 = m.random.next_int_bound(5).unwrap_or(0) as u8;
|
||||
}
|
||||
Species::Donkey | Species::Mule => {
|
||||
// AbstractChestedHorse.randomizeAttributes: fixed speed, generated health.
|
||||
m.attrs.max_health = health;
|
||||
m.extra.vector[0] = jump;
|
||||
}
|
||||
_ => m.extra.vector[0] = jump,
|
||||
}
|
||||
m.health = m.attrs.max_health;
|
||||
}
|
||||
/// `AbstractHorse.createOffspringAttribute`.
|
||||
pub fn offspring(a: f64, b: f64, min: f64, max: f64, r: &mut impl RandomSource) -> f64 {
|
||||
let (a, b) = (a.clamp(min, max), b.clamp(min, max));
|
||||
let margin = 0.15 * (max - min);
|
||||
let range = (a - b).abs() + margin * 2.0;
|
||||
let quality = (r.next_double() + r.next_double() + r.next_double()) / 3.0 - 0.5;
|
||||
let v = (a + b) / 2.0 + range * quality;
|
||||
if v > max {
|
||||
max - (v - max)
|
||||
} else if v < min {
|
||||
min + (min - v)
|
||||
} else {
|
||||
v
|
||||
}
|
||||
}
|
||||
/// `AbstractHorse.setOffspringAttributes` from two parents.
|
||||
pub fn inherit(child: &mut Mob, a: &Mob, b: &Mob, r: &mut impl RandomSource) {
|
||||
child.attrs.max_health = offspring(
|
||||
f64::from(a.attrs.max_health),
|
||||
f64::from(b.attrs.max_health),
|
||||
15.0,
|
||||
30.0,
|
||||
r,
|
||||
) as f32;
|
||||
child.health = child.attrs.max_health;
|
||||
child.extra.vector[0] = offspring(a.extra.vector[0], b.extra.vector[0], 0.4, 1.0, r);
|
||||
child.attrs.speed = offspring(a.attrs.speed, b.attrs.speed, 0.1125, 0.3375, r);
|
||||
}
|
||||
/// The rider controls the mount: saddled, with a player on it.
|
||||
pub fn controlled(m: &Mob) -> bool {
|
||||
m.rider.is_some() && (m.extra.saddled || m.species() == Species::SkeletonHorse && m.extra.tame)
|
||||
}
|
||||
/// `AbstractHorse.MountPanicGoal`: only without a rider.
|
||||
#[derive(Clone, Debug)]
|
||||
struct MountPanic(Panic);
|
||||
impl Goal for MountPanic {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
self.0.flags()
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
m.rider.is_none() && self.0.can_use(m, cx)
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
m.rider.is_none() && self.0.can_continue(m, cx)
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
self.0.start(m, cx)
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
self.0.stop(m, cx)
|
||||
}
|
||||
}
|
||||
/// `RunAroundLikeCrazyGoal`: an untamed horse with a rider bolts about until
|
||||
/// it is tamed (temper) or throws the rider off.
|
||||
#[derive(Clone, Debug)]
|
||||
struct RunAroundLikeCrazy;
|
||||
impl Goal for RunAroundLikeCrazy {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
if m.extra.tame || m.rider.is_none() {
|
||||
return false;
|
||||
}
|
||||
let r = &mut m.random;
|
||||
let (dx, dz) = (
|
||||
r.next_int_bound(11).unwrap_or(5) - 5,
|
||||
r.next_int_bound(11).unwrap_or(5) - 5,
|
||||
);
|
||||
let dy = r.next_int_bound(9).unwrap_or(4) - 4;
|
||||
let t = [
|
||||
m.position.x + f64::from(dx),
|
||||
m.position.y + f64::from(dy),
|
||||
m.position.z + f64::from(dz),
|
||||
];
|
||||
m.nav_move_to(cx.w, t, 1.2)
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
!m.extra.tame && !m.ai.nav.is_done() && m.rider.is_some()
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
if m.extra.tame || m.random.next_int_bound(50).unwrap_or(1) != 0 {
|
||||
return;
|
||||
}
|
||||
let temper = i32::from(m.extra.variant3);
|
||||
if m.random.next_int_bound(100).unwrap_or(0) < temper {
|
||||
// tameWithName
|
||||
m.extra.tame = true;
|
||||
cx.events.push(MobEvent::Tamed { mob: m.id });
|
||||
return;
|
||||
}
|
||||
m.extra.variant3 = (temper + 5).min(100) as u8;
|
||||
cx.events.push(MobEvent::Buck { mob: m.id });
|
||||
make_mad(m, cx.events);
|
||||
}
|
||||
}
|
||||
/// `AbstractHorse.makeMad`: rear with the angry sound.
|
||||
pub fn make_mad(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
if m.extra.counter > 0 {
|
||||
return;
|
||||
}
|
||||
if can_rear(m.species()) {
|
||||
m.extra.counter = 20;
|
||||
m.extra.flag = false;
|
||||
}
|
||||
let sound = match m.species() {
|
||||
Species::Donkey => "entity.donkey.angry",
|
||||
Species::Mule => "entity.mule.angry",
|
||||
_ => "entity.horse.angry",
|
||||
};
|
||||
events.push(MobEvent::Sound(sound, m.center(), 1.0, 1.0));
|
||||
}
|
||||
/// `RandomStandGoal`.
|
||||
#[derive(Clone, Debug)]
|
||||
struct RandomStand {
|
||||
next: i32,
|
||||
}
|
||||
impl Goal for RandomStand {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
0
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
self.next += 1;
|
||||
if self.next > 0 && m.random.next_int_bound(1000).unwrap_or(1000) < self.next {
|
||||
self.next = -80;
|
||||
return m.random.next_int_bound(10).unwrap_or(1) == 0;
|
||||
}
|
||||
false
|
||||
}
|
||||
fn can_continue(&mut self, _: &mut Mob, _: &mut Cx) -> bool {
|
||||
false
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
m.extra.counter = 20;
|
||||
m.extra.flag = false;
|
||||
if m.species() == Species::Horse {
|
||||
cx.events
|
||||
.push(MobEvent::Sound("entity.horse.angry", m.center(), 1.0, 1.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The mount takes its rider's input (`getRiddenInput`, `tickRidden`).
|
||||
pub fn ridden_step(m: &mut Mob) {
|
||||
let Some(r) = m.rider else {
|
||||
return;
|
||||
};
|
||||
m.yaw = r.yaw;
|
||||
m.head_pitch = r.pitch * 0.5;
|
||||
m.body_yaw = r.yaw;
|
||||
m.head_yaw = r.yaw;
|
||||
m.ai.nav.stop();
|
||||
let standing = m.extra.counter > 0;
|
||||
if m.on_ground && r.jump == 0.0 && standing {
|
||||
m.ai.xxa = 0.0;
|
||||
m.ai.zza = 0.0;
|
||||
return;
|
||||
}
|
||||
let forward = if r.forward <= 0.0 {
|
||||
r.forward * 0.25
|
||||
} else {
|
||||
r.forward
|
||||
};
|
||||
m.ai.xxa = r.strafe * 0.5;
|
||||
m.ai.zza = forward;
|
||||
let speed = m.attrs.speed as f32;
|
||||
m.set_speed(speed);
|
||||
if m.on_ground && r.jump > 0.0 {
|
||||
// executeRidersJump
|
||||
let impulse = m.extra.vector[0] as f32 * r.jump;
|
||||
m.velocity.y = f64::from(impulse);
|
||||
if forward > 0.0 {
|
||||
let (s, c) = (m.yaw.to_radians().sin(), m.yaw.to_radians().cos());
|
||||
m.velocity.x += f64::from(-0.4 * s * r.jump);
|
||||
m.velocity.z += f64::from(0.4 * c * r.jump);
|
||||
}
|
||||
if let Some(rider) = m.rider.as_mut() {
|
||||
rider.jump = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `AbstractHorse.aiStep` and `tick`: healing, grazing, the rear and the
|
||||
/// eating/standing/mouth animations.
|
||||
pub fn ai_step(m: &mut Mob, w: &MobWorld) {
|
||||
if m.alive() && m.random.next_int_bound(900).unwrap_or(1) == 0 && m.death_time == 0 {
|
||||
m.health = (m.health + 1.0).min(m.attrs.max_health);
|
||||
}
|
||||
// Grazing (canEatGrass: horses and donkeys alike).
|
||||
if m.alive() && m.rider.is_none() {
|
||||
let below = w.facts.get(w.world.block(
|
||||
m.position.x.floor() as i32,
|
||||
(m.position.y - 0.5).floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
));
|
||||
if !m.extra.flag
|
||||
&& m.random.next_int_bound(300).unwrap_or(1) == 0
|
||||
&& &*below.name == "minecraft:grass_block"
|
||||
{
|
||||
m.extra.flag = true;
|
||||
m.extra.counter2 = 0;
|
||||
}
|
||||
}
|
||||
if m.extra.flag {
|
||||
m.extra.counter2 += 1;
|
||||
if m.extra.counter2 > 50 {
|
||||
m.extra.counter2 = 0;
|
||||
m.extra.flag = false;
|
||||
}
|
||||
}
|
||||
if m.extra.counter > 0 {
|
||||
m.extra.counter -= 1;
|
||||
}
|
||||
let (eating, standing) = (m.extra.flag, m.extra.counter > 0);
|
||||
let v = &mut m.anim.v;
|
||||
if standing {
|
||||
v[EAT] = 0.0;
|
||||
m.anim.vo[EAT] = 0.0;
|
||||
v[STAND] = (v[STAND] + (1.0 - v[STAND]) * 0.4 + 0.05).min(1.0);
|
||||
} else {
|
||||
if eating {
|
||||
v[EAT] = (v[EAT] + (1.0 - v[EAT]) * 0.4 + 0.05).min(1.0);
|
||||
} else {
|
||||
v[EAT] = (v[EAT] - v[EAT] * 0.4 - 0.05).max(0.0);
|
||||
}
|
||||
let s = v[STAND];
|
||||
v[STAND] = (s + (0.8 * s * s * s - s) * 0.6 - 0.05).max(0.0);
|
||||
}
|
||||
v[MOUTH] = (v[MOUTH] - v[MOUTH] * 0.7 - 0.05).max(0.0);
|
||||
}
|
||||
/// Body texture and the markings overlay.
|
||||
pub fn texture(m: &Mob) -> String {
|
||||
let baby = if m.is_baby() { "_baby" } else { "" };
|
||||
match m.species() {
|
||||
Species::Horse => {
|
||||
let c = COLORS[(m.extra.variant as usize).min(6)];
|
||||
format!("entity/horse/horse_{c}{baby}")
|
||||
}
|
||||
Species::Donkey => format!("entity/horse/donkey{baby}"),
|
||||
Species::Mule => format!("entity/horse/mule{baby}"),
|
||||
Species::SkeletonHorse => format!("entity/horse/horse_skeleton{baby}"),
|
||||
_ => format!("entity/horse/horse_zombie{baby}"),
|
||||
}
|
||||
}
|
||||
pub fn markings(m: &Mob) -> Option<String> {
|
||||
if m.species() != Species::Horse {
|
||||
return None;
|
||||
}
|
||||
let mk = MARKINGS[(m.extra.variant2 as usize).min(4)];
|
||||
if mk.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let baby = if m.is_baby() { "_baby" } else { "" };
|
||||
Some(format!("entity/horse/horse_markings_{mk}{baby}"))
|
||||
}
|
||||
/// The model key prefix for the species.
|
||||
pub fn model_name(s: Species) -> &'static str {
|
||||
match s {
|
||||
Species::Horse => "horse",
|
||||
Species::Donkey => "donkey",
|
||||
Species::Mule => "mule",
|
||||
Species::SkeletonHorse => "skeleton_horse",
|
||||
_ => "zombie_horse",
|
||||
}
|
||||
}
|
||||
/// The saddle layer texture.
|
||||
pub fn saddle_texture(s: Species) -> &'static str {
|
||||
match s {
|
||||
Species::Donkey => "entity/equipment/donkey_saddle/saddle",
|
||||
Species::Mule => "entity/equipment/mule_saddle/saddle",
|
||||
Species::SkeletonHorse => "entity/equipment/skeleton_horse_saddle/saddle",
|
||||
Species::ZombieHorse => "entity/equipment/zombie_horse_saddle/saddle",
|
||||
_ => "entity/equipment/horse_saddle/saddle",
|
||||
}
|
||||
}
|
||||
/// `AbstractEquineModel.setupAnim` with the adult and baby offsets.
|
||||
pub fn anim(m: &Mob, s: &State, p: &mut Poses) {
|
||||
let baby = m.is_baby();
|
||||
let donkey = matches!(m.species(), Species::Donkey | Species::Mule);
|
||||
// Leg/tail/head parameters (getLeg*, getTailXRotOffset).
|
||||
let (stand_angle, stand_y, stand_z, stand_x_off, tail_off) = match (baby, donkey) {
|
||||
(false, _) => (PI / 12.0, 12.0, 4.0, -PI / 3.0, 0.0),
|
||||
(true, false) => (PI / 12.0, 4.0, 0.0, -PI / 3.0, -PI / 2.0),
|
||||
(true, true) => (PI / 3.0, 1.0, 0.5, 0.0, -PI / 4.0),
|
||||
};
|
||||
let clamped = s.y_rot.clamp(-20.0, 20.0);
|
||||
let mut head_x = s.x_rot.to_radians();
|
||||
let (speed, pos) = (s.speed, s.pos);
|
||||
if speed > 0.2 {
|
||||
head_x += (pos * 0.8).cos() * 0.15 * speed;
|
||||
}
|
||||
let eating = m.anim.lerp(EAT, s.partial);
|
||||
let standing = m.anim.lerp(STAND, s.partial);
|
||||
let istand = 1.0 - standing;
|
||||
let feeding = m.anim.lerp(MOUTH, s.partial);
|
||||
let in_water = if m.fluids.in_water { 0.2 } else { 1.0 };
|
||||
let leg1 = (in_water * pos * 0.6662 + PI).cos();
|
||||
let leg_x = leg1 * 0.8 * speed;
|
||||
let base = (1.0 - standing.max(eating)) * (PI / 6.0 + head_x + feeding * s.age.sin() * 0.05);
|
||||
p.xrot(
|
||||
"head_parts",
|
||||
standing * (PI / 12.0 + head_x) + eating * (2.181_661_6 + s.age.sin() * 0.05) + base,
|
||||
);
|
||||
p.yrot(
|
||||
"head_parts",
|
||||
standing * clamped.to_radians() + (1.0 - standing.max(eating)) * clamped.to_radians(),
|
||||
);
|
||||
// animateHeadPartsPlacement
|
||||
{
|
||||
let hp = p.get("head_parts");
|
||||
let lerp = |t: f32, a: f32, b: f32| a + (b - a) * t;
|
||||
if baby && donkey {
|
||||
hp[1] = lerp(eating, hp[1], -1.2);
|
||||
hp[2] = lerp(standing, hp[2], -3.6);
|
||||
} else if baby {
|
||||
hp[1] += lerp(eating, lerp(standing, 0.0, -2.0), 2.0);
|
||||
hp[2] = lerp(standing, hp[2], -4.0);
|
||||
} else {
|
||||
hp[1] += lerp(eating, lerp(standing, 0.0, -8.0), 7.0);
|
||||
hp[2] = lerp(standing, hp[2], -4.0);
|
||||
}
|
||||
}
|
||||
let body_x = p.get("body")[3];
|
||||
p.xrot("body", standing * (-PI / 4.0) + istand * body_x);
|
||||
{
|
||||
let lf = p.get("left_front_leg");
|
||||
lf[1] -= stand_y * standing;
|
||||
lf[2] += stand_z * standing;
|
||||
let (y, z) = (lf[1], lf[2]);
|
||||
let rf = p.get("right_front_leg");
|
||||
rf[1] = y;
|
||||
rf[2] = z;
|
||||
}
|
||||
let stand = stand_angle * standing;
|
||||
let bob = (s.age * 0.6 + PI).cos();
|
||||
let rleg = (stand_x_off + bob) * standing + leg_x * istand;
|
||||
let lleg = (stand_x_off - bob) * standing - leg_x * istand;
|
||||
p.xrot("left_hind_leg", stand - leg1 * 0.5 * speed * istand);
|
||||
p.xrot("right_hind_leg", stand + leg1 * 0.5 * speed * istand);
|
||||
p.xrot("left_front_leg", rleg);
|
||||
p.xrot("right_front_leg", lleg);
|
||||
if baby && donkey {
|
||||
let lerp = |t: f32, a: f32, b: f32| a + (b - a) * t;
|
||||
let y = lerp(standing, p.get("left_hind_leg")[1], -0.3);
|
||||
p.get("left_hind_leg")[1] = y;
|
||||
p.get("right_hind_leg")[1] = y;
|
||||
}
|
||||
let age = if baby { 0.5 } else { 1.0 };
|
||||
p.xrot("tail", tail_off + PI / 6.0 + speed * 0.75);
|
||||
{
|
||||
let t = p.get("tail");
|
||||
t[1] += speed * age;
|
||||
t[2] += speed * 2.0 * age;
|
||||
}
|
||||
p.yrot("tail", 0.0);
|
||||
}
|
||||
@@ -1417,9 +1417,21 @@ impl Goal for Breed {
|
||||
return false;
|
||||
}
|
||||
let id = m.id;
|
||||
// Horses and donkeys breed together (AbstractHorse.canParent: tame).
|
||||
let equine = matches!(species, Species::Horse | Species::Donkey);
|
||||
if equine && !m.extra.tame {
|
||||
return false;
|
||||
}
|
||||
self.partner =
|
||||
cx.w.nearby(m.position, 8.0, move |s| {
|
||||
s.id != id && s.species == species && s.in_love && !s.baby && (!tamable || s.tame)
|
||||
let same = s.species == species
|
||||
|| equine && matches!(s.species, Species::Horse | Species::Donkey);
|
||||
s.id != id
|
||||
&& same
|
||||
&& s.in_love
|
||||
&& !s.baby
|
||||
&& (!tamable || s.tame)
|
||||
&& (!equine || s.tame)
|
||||
})
|
||||
.map(|s| s.id)
|
||||
.next();
|
||||
|
||||
@@ -103,6 +103,13 @@ pub fn body(m: &Mob) -> (String, String) {
|
||||
}
|
||||
};
|
||||
match m.species() {
|
||||
s if super::equine::is_equine(s) => {
|
||||
let name = super::equine::model_name(s);
|
||||
(
|
||||
baby_or(m, &format!("{name}#main"), &format!("{name}_baby#main")),
|
||||
super::equine::texture(m),
|
||||
)
|
||||
}
|
||||
S::Wolf => (
|
||||
baby_or(m, "wolf#main", "wolf_baby#main"),
|
||||
super::tame::texture(m),
|
||||
@@ -286,6 +293,40 @@ pub fn layers(m: &Mob) -> Vec<Layer> {
|
||||
false,
|
||||
);
|
||||
}
|
||||
// HorseMarkingLayer, the saddle and the horse armour.
|
||||
s if super::equine::is_equine(s) => {
|
||||
let name = super::equine::model_name(s);
|
||||
let body = if m.is_baby() {
|
||||
format!("{name}_baby#main")
|
||||
} else {
|
||||
format!("{name}#main")
|
||||
};
|
||||
if let Some(tex) = super::equine::markings(m) {
|
||||
push(&mut v, &body, &tex, white, false);
|
||||
}
|
||||
if m.extra.saddled && !m.is_baby() {
|
||||
push(
|
||||
&mut v,
|
||||
&format!("{name}#saddle"),
|
||||
super::equine::saddle_texture(s),
|
||||
white,
|
||||
false,
|
||||
);
|
||||
}
|
||||
if let Some(armor) = m.extra.head.as_deref()
|
||||
&& let Some(material) = armor
|
||||
.strip_prefix("minecraft:")
|
||||
.and_then(|a| a.strip_suffix("_horse_armor"))
|
||||
{
|
||||
let tex = format!("entity/equipment/horse_body/{material}");
|
||||
let color = if material == "leather" {
|
||||
abgr(0xA06540)
|
||||
} else {
|
||||
white
|
||||
};
|
||||
push(&mut v, "horse_armor#main", &tex, color, false);
|
||||
}
|
||||
}
|
||||
// CatCollarLayer.
|
||||
S::Cat if m.extra.tame => {
|
||||
let (model, texture) = if m.is_baby() {
|
||||
|
||||
@@ -209,6 +209,9 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts) {
|
||||
// ZombifiedPiglin.populateDefaultEquipmentSlots: a golden sword.
|
||||
S::ZombifiedPiglin => m.extra.main_hand = Some("minecraft:golden_sword".into()),
|
||||
S::Pillager => m.extra.main_hand = Some("minecraft:crossbow".into()),
|
||||
S::Horse | S::Donkey | S::Mule | S::SkeletonHorse | S::ZombieHorse => {
|
||||
super::equine::finalize(m)
|
||||
}
|
||||
// Piglin.createSpawnWeapon: half crossbows, half golden swords.
|
||||
S::Piglin if !m.is_baby() => {
|
||||
let crossbow = m.random.next_float() < 0.5;
|
||||
|
||||
Reference in New Issue
Block a user