Ride pigs and striders

Saddles fit adult pigs and striders; a saddled one can be ridden and
steered with a carrot or warped fungus on a stick, whose use boosts it
and wears the stick (a worn-out stick becomes a fishing rod). Saddles,
horse armour and donkey chests drop when their wearer dies, and saddled
pigs and striders keep their saddle in the save.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-09 07:25:01 +02:00
parent 3e2cdcae33
commit e5399b1613
6 changed files with 172 additions and 2 deletions
+22
View File
@@ -231,6 +231,21 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
]),
);
}
"minecraft:pig" | "minecraft:strider" => {
let mut equipment = match map.get(&"equipment".into()) {
Some(Tag::Compound(c)) => c.clone(),
_ => Compound::new(),
};
if m.extra.saddled {
equipment.insert(
"saddle".into(),
Tag::compound([("id", string("minecraft:saddle")), ("count", Tag::Int(1))]),
);
} else {
equipment.remove(&"saddle".into());
}
map.insert("equipment".into(), Tag::Compound(equipment));
}
"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)));
@@ -308,6 +323,13 @@ 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 matches!(
m.species(),
crate::mobs::Species::Pig | crate::mobs::Species::Strider
) {
m.extra.saddled =
tag.get("equipment").and_then(|e| e.get("saddle")).is_some() || flag(tag, "Saddle");
}
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;
+7
View File
@@ -1587,6 +1587,13 @@ impl Game<'_> {
if self.spectator() {
return Ok(());
}
// A carrot or warped fungus on a stick boosts the ridden pig or strider.
if self.riding.is_some()
&& let Some(item) = self.held().map(|s| s.item.clone())
&& self.use_steering_stick(&item)
{
return Ok(());
}
if self.interact_frame()
|| self.interact_armor_stand()
|| self.interact_boat()
@@ -587,6 +587,22 @@ impl Game<'_> {
self.spawn_item(d, pos, [0.0, 0.2, 0.0], 10);
}
}
// Saddles, horse armour and chests always drop.
let mut gear: Vec<&str> = Vec::new();
if m.extra.saddled {
gear.push("minecraft:saddle");
}
if m.extra.chested && horizon_client::mobs::equine::is_equine(m.species()) {
gear.push("minecraft:chest");
}
if horizon_client::mobs::equine::is_equine(m.species())
&& let Some(armor) = m.extra.head.as_deref()
{
gear.push(armor);
}
for item in gear {
self.spawn_item(ItemStack::new(item, 1), pos, [0.0, 0.2, 0.0], 10);
}
{
let item = &m.extra.main_hand;
// Equipment drop chance 8.5% (+ player kill only).
+66 -1
View File
@@ -5,6 +5,7 @@
use super::Game;
use horizon_client::{
hud::HudBatch,
items::ItemStack,
mobs::{MobEvent, Species, equine},
sprint::Keys,
};
@@ -13,6 +14,8 @@ 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::Pig => 0.86875,
Species::Strider => 1.7,
Species::Horse => 1.44375,
Species::Donkey => 1.1125,
Species::Mule => 1.2125,
@@ -33,10 +36,65 @@ impl Game<'_> {
let id = self.riding?;
self.mobs.iter().position(|m| m.id == id)
}
/// `Pig` / `Strider.mobInteract`: saddle an adult, or ride a saddled one.
fn interact_steerable(&mut self, index: usize, item: &str) -> bool {
let m = &mut self.mobs[index];
if m.is_baby() || !m.alive() || Some(m.id) == self.riding {
return false;
}
let at = m.center();
if item == "minecraft:saddle" && !m.extra.saddled {
m.extra.saddled = true;
let sound = if m.species() == Species::Strider {
"minecraft:entity.strider.saddle"
} else {
"minecraft:entity.pig.saddle"
};
self.audio.play(sound, Some(at), 0.5, 1.0);
self.consume_held();
self.world
.modified
.insert((at[0].floor() as i32 >> 4, at[2].floor() as i32 >> 4));
return true;
}
if !m.extra.saddled || self.keys.contains(&winit::keyboard::KeyCode::ShiftLeft) {
return false;
}
self.riding = Some(m.id);
true
}
/// `FoodOnAStickItem.use` while riding: boost the mount, wear the stick.
pub(super) fn use_steering_stick(&mut self, item: &str) -> bool {
let (species, wear) = match item {
"minecraft:carrot_on_a_stick" => (Species::Pig, 7),
"minecraft:warped_fungus_on_a_stick" => (Species::Strider, 1),
_ => return false,
};
let Some(i) = self.mount_index() else {
return false;
};
if self.mobs[i].species() != species || !equine::boost(&mut self.mobs[i]) {
return false;
}
if !self.creative
&& let Some(stack) = self.inventory[self.selected].as_mut()
{
stack.damage += wear;
let max = self.res.items.get(&stack.item).map_or(25, |i| i.max_damage);
if stack.damage >= max {
self.inventory[self.selected] = Some(ItemStack::new("minecraft:fishing_rod", 1));
}
}
self.swing_arm();
true
}
/// `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 matches!(species, Species::Pig | Species::Strider) {
return self.interact_steerable(index, item);
}
if !equine::is_equine(species) || !m.alive() || Some(m.id) == self.riding {
return false;
}
@@ -152,7 +210,13 @@ impl Game<'_> {
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 held = self.held().map(|s| s.item.clone());
let steer = match self.mobs[i].species() {
Species::Pig => held.as_deref() == Some("minecraft:carrot_on_a_stick"),
Species::Strider => held.as_deref() == Some("minecraft:warped_fungus_on_a_stick"),
_ => false,
};
let saddled = self.mobs[i].extra.saddled && equine::is_equine(self.mobs[i].species());
let mut jump = 0.0;
if saddled {
let st = &mut self.mount;
@@ -205,6 +269,7 @@ impl Game<'_> {
yaw: self.yaw,
pitch: self.pitch,
jump: if jump > 0.0 { jump } else { pending },
steer,
});
true
}
+46 -1
View File
@@ -37,6 +37,8 @@ pub struct Rider {
pub pitch: f32,
/// `playerJumpPendingScale` from the jump bar.
pub jump: f32,
/// Holding the mount's steering stick (pigs, striders).
pub steer: bool,
}
pub fn is_equine(s: Species) -> bool {
@@ -128,7 +130,35 @@ pub fn inherit(child: &mut Mob, a: &Mob, b: &Mob, r: &mut impl RandomSource) {
}
/// 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)
let Some(r) = m.rider else {
return false;
};
match m.species() {
// Pig/Strider.getControllingPassenger: saddled, the rider holding the stick.
Species::Pig | Species::Strider => m.extra.saddled && r.steer,
_ => m.extra.saddled || m.species() == Species::SkeletonHorse && m.extra.tame,
}
}
/// `ItemBasedSteering.boost`: 140 to 980 ticks of extra speed.
pub fn boost(m: &mut Mob) -> bool {
if m.extra.counter2 > 0 {
return false;
}
m.extra.counter2 = m.random.next_int_bound(841).unwrap_or(0) + 140;
m.extra.counter = 0;
true
}
/// `ItemBasedSteering.tickBoost` and `boostFactor`.
fn boost_factor(m: &mut Mob) -> f32 {
if m.extra.counter2 <= 0 {
return 1.0;
}
m.extra.counter += 1;
if m.extra.counter > m.extra.counter2 {
m.extra.counter2 = 0;
return 1.0;
}
1.0 + 1.15 * (m.extra.counter as f32 / m.extra.counter2 as f32 * PI).sin()
}
/// `AbstractHorse.MountPanicGoal`: only without a rider.
#[derive(Clone, Debug)]
@@ -255,6 +285,21 @@ pub fn ridden_step(m: &mut Mob) {
m.body_yaw = r.yaw;
m.head_yaw = r.yaw;
m.ai.nav.stop();
if matches!(m.species(), Species::Pig | Species::Strider) {
// Pig/Strider: always forward along the rider's look, at a fraction
// of the movement speed, boosted by the stick.
m.head_pitch = r.pitch * 0.5;
m.ai.xxa = 0.0;
m.ai.zza = 1.0;
let factor = if m.species() == Species::Pig {
0.225
} else {
0.55
};
let boost = boost_factor(m);
m.set_speed((m.attrs.speed * factor) as f32 * boost);
return;
}
let standing = m.extra.counter > 0;
if m.on_ground && r.jump == 0.0 && standing {
m.ai.xxa = 0.0;
+15
View File
@@ -327,6 +327,21 @@ pub fn layers(m: &Mob) -> Vec<Layer> {
push(&mut v, "horse_armor#main", &tex, color, false);
}
}
// SimpleEquipmentLayer: pig and strider saddles.
S::Pig if m.extra.saddled && !m.is_baby() => push(
&mut v,
"pig#saddle",
"entity/equipment/pig_saddle/saddle",
white,
false,
),
S::Strider if m.extra.saddled && !m.is_baby() => push(
&mut v,
"strider#saddle",
"entity/equipment/strider_saddle/saddle",
white,
false,
),
// CatCollarLayer.
S::Cat if m.extra.tame => {
let (model, texture) = if m.is_baby() {