Add the nautilus, zombie nautilus, sulfur cube and camel husk
Ports AbstractNautilus, Nautilus, ZombieNautilus and their brains (taming with pufferfish, saddles and nautilus armour, riding with a dash, breeding, spawning below sea level, drowned riders), SulfurCube on the slime code (swallowed blocks and their archetypes, shears, TNT cubes, splitting) and CamelHusk on the camel (its own saddle and sounds, husk jockeys). Camels now save their saddle and stay tame after loading, and horse armour layers load. The entity model harness compares 150 layers, all matching, including the new mobs and previously unmapped armour, harness, fish and villager layers; mob attributes pass with the new types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -197,15 +197,31 @@ fn main() -> horizon_client::Result<()> {
|
||||
// Variant layers (sizes, hatless villagers, climate cows...) animate
|
||||
// like their base model.
|
||||
let mut base = adult.clone();
|
||||
for cut in ["_no_hat", "_small", "_medium", "_large"] {
|
||||
// Armour layers (horse, wolf, nautilus), the coral zombie nautilus,
|
||||
// the happy ghast's harness and ropes and hatless babies animate like
|
||||
// their base model too; the undead horses share one armour layer.
|
||||
let cuts = [
|
||||
"_no_hat", "_small", "_medium", "_large", "_big", "_armor", "_coral", "_harness",
|
||||
"_ropes", "_baby",
|
||||
];
|
||||
let norm = |s: &str| {
|
||||
let mut s = s.to_owned();
|
||||
for cut in cuts {
|
||||
s = s.replace(cut, "");
|
||||
}
|
||||
s.replace("undead_horse#", "zombie_horse#")
|
||||
};
|
||||
for cut in cuts {
|
||||
base = base.replace(cut, "");
|
||||
}
|
||||
let base = base.replace("undead_horse#", "zombie_horse#");
|
||||
let base = base.trim_start_matches("cold_").trim_start_matches("warm_");
|
||||
let Some(def) = species::ALL.iter().find(|d| {
|
||||
d.model == layer
|
||||
|| (baby && d.model == adult)
|
||||
|| d.model == base
|
||||
|| d.model.trim_end_matches("#main") == base.trim_end_matches("#main")
|
||||
|| norm(d.model) == base
|
||||
}) else {
|
||||
out.push_str(&format!("{}\n", json!({"skip": "no species"})));
|
||||
continue;
|
||||
|
||||
@@ -333,14 +333,26 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
);
|
||||
}
|
||||
}
|
||||
"minecraft:camel" => {
|
||||
"minecraft:camel" | "minecraft:camel_husk" => {
|
||||
// LastPoseTick: negative while sitting.
|
||||
let sitting = crate::mobs::camel::sitting(m);
|
||||
map.insert(
|
||||
"LastPoseTick".into(),
|
||||
Tag::Long(if sitting { -1 } else { 0 }),
|
||||
);
|
||||
if let Some(saddle) = m.saddle_item() {
|
||||
map.insert(
|
||||
"equipment".into(),
|
||||
Tag::compound([("saddle", crate::save::item_to_nbt(&saddle))]),
|
||||
);
|
||||
} else {
|
||||
map.remove(&"equipment".into());
|
||||
}
|
||||
}
|
||||
"minecraft:nautilus" | "minecraft:zombie_nautilus" => {
|
||||
crate::mobs::nautilus::to_nbt(m, map);
|
||||
}
|
||||
"minecraft:sulfur_cube" => crate::mobs::sulfur_cube::to_nbt(m, map),
|
||||
"minecraft:sniffer" => crate::mobs::sniffer::to_nbt(m, map),
|
||||
"minecraft:wither" => {
|
||||
map.insert("Invul".into(), Tag::Int(m.extra.counter));
|
||||
@@ -412,8 +424,9 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
("mainhand", &m.extra.main_hand),
|
||||
("offhand", &m.extra.off_hand),
|
||||
(
|
||||
// A happy ghast wears its harness in the body slot.
|
||||
if m.species() == crate::mobs::Species::HappyGhast {
|
||||
// A happy ghast wears its harness in the body slot (and a
|
||||
// nautilus its armour, a sulfur cube its swallowed block).
|
||||
if crate::mobs::species::body_slot(m.species()) {
|
||||
"body"
|
||||
} else {
|
||||
"head"
|
||||
@@ -517,7 +530,7 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
.map(Into::into);
|
||||
if !crate::mobs::equine::is_equine(m.species()) {
|
||||
let slot = |key| eq.get(key).and_then(|i| text(i.get("id"))).map(Into::into);
|
||||
m.extra.head = slot(if m.species() == crate::mobs::Species::HappyGhast {
|
||||
m.extra.head = slot(if crate::mobs::species::body_slot(m.species()) {
|
||||
"body"
|
||||
} else {
|
||||
"head"
|
||||
@@ -677,12 +690,20 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
.and_then(|b| b.get("minecraft:liked_player"))
|
||||
.is_some();
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Camel {
|
||||
if crate::mobs::camel::is_camel(m.species()) {
|
||||
let sitting = matches!(tag.get("LastPoseTick"), Some(Tag::Long(v)) if *v < 0);
|
||||
crate::mobs::camel::stand_up_instantly(&mut m);
|
||||
if sitting {
|
||||
m.extra.egg_time = -1 - 400;
|
||||
}
|
||||
// Camels are always tame (`Camel.register` in Horizon).
|
||||
m.extra.tame = true;
|
||||
}
|
||||
if crate::mobs::nautilus::is_nautilus(m.species()) {
|
||||
crate::mobs::nautilus::from_nbt(&mut m, tag);
|
||||
}
|
||||
if m.species() == crate::mobs::Species::SulfurCube {
|
||||
crate::mobs::sulfur_cube::from_nbt(&mut m, tag);
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Creaking
|
||||
&& let Some(Tag::IntArray(home)) = tag.get("home_pos")
|
||||
|
||||
@@ -52,6 +52,7 @@ mod mount_menu;
|
||||
mod mounts;
|
||||
mod music;
|
||||
mod names;
|
||||
mod nautili;
|
||||
mod options;
|
||||
mod packs;
|
||||
mod paintings;
|
||||
@@ -79,6 +80,7 @@ mod stats_screen;
|
||||
mod storage;
|
||||
mod structures;
|
||||
mod subtitle_hud;
|
||||
mod sulfur_cubes;
|
||||
mod titles;
|
||||
mod tnt;
|
||||
mod totem;
|
||||
@@ -4891,7 +4893,8 @@ impl Game<'_> {
|
||||
);
|
||||
}
|
||||
self.last_hurt_by_player.insert(mob.id);
|
||||
let kind = mob.kind.clone();
|
||||
// getHurtSound / getDeathSound (by species state).
|
||||
let voice = horizon_client::mobs::ai::voice_sounds(mob);
|
||||
let dead = !mob.alive();
|
||||
let sound = if crit {
|
||||
"minecraft:entity.player.attack.crit"
|
||||
@@ -4901,7 +4904,7 @@ impl Game<'_> {
|
||||
"minecraft:entity.player.attack.weak"
|
||||
};
|
||||
self.audio.play(sound, Some(center), 1.0, 1.0);
|
||||
let event = format!("minecraft:{}", kind.sounds[if dead { 2 } else { 1 }]);
|
||||
let event = format!("minecraft:{}", voice[if dead { 2 } else { 1 }]);
|
||||
let pitch =
|
||||
(self.world.random.next_float() - self.world.random.next_float()) * 0.2 + 1.0;
|
||||
self.audio.play(&event, Some(center), 1.0, pitch);
|
||||
|
||||
@@ -195,6 +195,7 @@ impl Game<'_> {
|
||||
Climate::Temperate
|
||||
};
|
||||
BiomeFacts {
|
||||
coral_nautilus: has("minecraft:spawns_coral_variant_zombie_nautilus"),
|
||||
climate,
|
||||
temperature: b.temperature,
|
||||
snowy: has("minecraft:spawns_snow_foxes")
|
||||
@@ -638,6 +639,7 @@ impl Game<'_> {
|
||||
|| matches!(
|
||||
kind.species,
|
||||
Species::Slime
|
||||
| Species::SulfurCube
|
||||
| Species::Ghast
|
||||
| Species::MagmaCube
|
||||
| Species::Guardian
|
||||
@@ -731,6 +733,7 @@ impl Game<'_> {
|
||||
self.tick_sniffer_effects();
|
||||
self.tick_player_effects();
|
||||
self.piglin_pickups();
|
||||
self.sulfur_cube_pickups();
|
||||
Ok(())
|
||||
}
|
||||
/// LivingEntity.die / dropAllDeathLoot.
|
||||
@@ -854,6 +857,9 @@ impl Game<'_> {
|
||||
self.spawn_orbs(pos, xp);
|
||||
}
|
||||
}
|
||||
if m.species() == Species::SulfurCube {
|
||||
self.split_sulfur_cube(m);
|
||||
}
|
||||
if m.species() == Species::Slime || m.species() == Species::MagmaCube {
|
||||
// Slime.remove: split into 2-4 smaller slimes.
|
||||
let size = m.extra.size;
|
||||
@@ -944,13 +950,17 @@ impl Game<'_> {
|
||||
if let Some(t) = self.mobs.iter_mut().find(|m| m.id == target) {
|
||||
let hit = t.damage(amount, source);
|
||||
if hit {
|
||||
let (kind, center, dead) = (t.kind.clone(), t.center(), !t.alive());
|
||||
let (voice, center, dead) = (
|
||||
horizon_client::mobs::ai::voice_sounds(t),
|
||||
t.center(),
|
||||
!t.alive(),
|
||||
);
|
||||
killed = dead;
|
||||
let pitch = (self.world.random.next_float()
|
||||
- self.world.random.next_float())
|
||||
* 0.2
|
||||
+ 1.0;
|
||||
let s = kind.sounds[if dead { 2 } else { 1 }];
|
||||
let s = voice[if dead { 2 } else { 1 }];
|
||||
if !s.is_empty() {
|
||||
self.audio.play(
|
||||
&format!("minecraft:{s}"),
|
||||
@@ -1318,6 +1328,12 @@ impl Game<'_> {
|
||||
self.spawn_orbs([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;
|
||||
child.extra.owner = p.extra.owner;
|
||||
child.persistent = true;
|
||||
}
|
||||
// Offspring inherit a parent's variant (pigs/cows/chickens) or mixed wool.
|
||||
child.extra.variant = p.extra.variant;
|
||||
if p.species() == Species::Sheep {
|
||||
@@ -1948,6 +1964,10 @@ impl Game<'_> {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
if self.interact_sulfur_cube(index, &item) {
|
||||
self.swing_arm();
|
||||
return Ok(true);
|
||||
}
|
||||
// AbstractHorse.mobInteract: feed, equip or ride.
|
||||
if self.interact_mount(index, &item) {
|
||||
self.swing_arm();
|
||||
@@ -2595,7 +2615,9 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
fn species_drops_harness(m: &Mob) -> bool {
|
||||
m.species() == Species::HappyGhast
|
||||
// Body equipment set to drop when killed: a harness, nautilus armour, a
|
||||
// sulfur cube's swallowed block.
|
||||
horizon_client::mobs::species::body_slot(m.species())
|
||||
}
|
||||
fn eat_sound(s: Species) -> &'static str {
|
||||
match s {
|
||||
@@ -2626,6 +2648,11 @@ fn experience_reward(m: &Mob, random: &mut impl RandomSource) -> u32 {
|
||||
| S::Pufferfish
|
||||
| S::Dolphin => 1 + random.next_int_bound(3).unwrap_or(0) as u32,
|
||||
S::IronGolem | S::SnowGolem | S::Villager | S::WanderingTrader => 0,
|
||||
// SulfurCube.getBaseExperienceReward.
|
||||
S::SulfurCube if m.is_baby() => 0,
|
||||
S::SulfurCube => 1 + random.next_int_bound(2).unwrap_or(0) as u32,
|
||||
// Animals in the monster category (Animal.getBaseExperienceReward).
|
||||
S::CamelHusk | S::ZombieNautilus => 1 + random.next_int_bound(3).unwrap_or(0) as u32,
|
||||
_ if m.hostile() => {
|
||||
5 + if m.extra.main_hand.is_some() {
|
||||
1 + random.next_int_bound(3).unwrap_or(0) as u32
|
||||
|
||||
@@ -553,20 +553,32 @@ impl Game<'_> {
|
||||
| Species::SkeletonHorse
|
||||
| Species::ZombieHorse
|
||||
| Species::Camel
|
||||
| Species::CamelHusk
|
||||
);
|
||||
// AbstractNautilus.canDispenserEquipIntoSlot: saddle and
|
||||
// body on a tame adult.
|
||||
let nautilus = horizon_client::mobs::nautilus::is_nautilus(species)
|
||||
&& tamed
|
||||
&& !m.is_baby();
|
||||
let slot_free = match (slot.as_str(), armor_index) {
|
||||
(_, Some(0)) => m.extra.head.is_none(),
|
||||
(_, Some(1)) => m.extra.chest.is_none(),
|
||||
(_, Some(2)) => m.extra.legs.is_none(),
|
||||
(_, Some(3)) => m.extra.feet.is_none(),
|
||||
("saddle", _) => !m.extra.saddled,
|
||||
("body", _) => species == Species::Horse && m.extra.head.is_none(),
|
||||
("body", _) => {
|
||||
(species == Species::Horse
|
||||
|| nautilus && item.ends_with("_nautilus_armor"))
|
||||
&& m.extra.head.is_none()
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
// Mob.canDispenserEquipIntoSlot and the overrides.
|
||||
let saddle_ok = slot == "saddle"
|
||||
&& (matches!(species, Species::Pig | Species::Strider) || equine && tamed);
|
||||
let body_ok = slot == "body" && equine && tamed;
|
||||
&& (matches!(species, Species::Pig | Species::Strider)
|
||||
|| equine && tamed
|
||||
|| nautilus);
|
||||
let body_ok = slot == "body" && (equine && tamed || nautilus);
|
||||
if !slot_free || !(m.extra.pick_up_loot || saddle_ok || body_ok) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ fn seat(s: Species) -> f64 {
|
||||
Species::Llama | Species::TraderLlama => 1.37,
|
||||
Species::Donkey => 1.1125,
|
||||
Species::Mule => 1.2125,
|
||||
Species::Nautilus | Species::ZombieNautilus => 1.1375,
|
||||
_ => 1.31875,
|
||||
};
|
||||
attach - 0.6
|
||||
@@ -111,6 +112,9 @@ impl Game<'_> {
|
||||
if species == Species::HappyGhast {
|
||||
return self.interact_happy_ghast(index, item);
|
||||
}
|
||||
if horizon_client::mobs::nautilus::is_nautilus(species) {
|
||||
return self.interact_nautilus(index, item);
|
||||
}
|
||||
if !equine::is_equine(species) || !m.alive() || Some(m.id) == self.riding {
|
||||
return false;
|
||||
}
|
||||
@@ -175,11 +179,17 @@ impl Game<'_> {
|
||||
}
|
||||
/// `AbstractHorse.handleEating`.
|
||||
fn feed_mount(&mut self, index: usize, item: &str) -> bool {
|
||||
let camel = self.mobs[index].species() == Species::Camel;
|
||||
if camel != (item == "minecraft:cactus") {
|
||||
let species = self.mobs[index].species();
|
||||
let camel = species == Species::Camel;
|
||||
// CamelHusk.isFood: rabbit's feet (and it never falls in love).
|
||||
if species == Species::CamelHusk && item != "minecraft:rabbit_foot" {
|
||||
return false;
|
||||
}
|
||||
if species != Species::CamelHusk && camel != (item == "minecraft:cactus") {
|
||||
return false;
|
||||
}
|
||||
let (heal, age_up, temper, love) = match item {
|
||||
"minecraft:rabbit_foot" if species == Species::CamelHusk => (2.0, 10, 0, false),
|
||||
// Camel.handleEating.
|
||||
"minecraft:cactus" => (2.0, 10, 0, true),
|
||||
"minecraft:wheat" => (2.0, 20, 3, false),
|
||||
@@ -222,6 +232,7 @@ impl Game<'_> {
|
||||
let at = m.center();
|
||||
let sound = match m.species() {
|
||||
Species::Camel => "minecraft:entity.camel.eat",
|
||||
Species::CamelHusk => "minecraft:entity.camel_husk.eat",
|
||||
Species::Donkey => "minecraft:entity.donkey.eat",
|
||||
Species::Mule => "minecraft:entity.mule.eat",
|
||||
_ => "minecraft:entity.horse.eat",
|
||||
@@ -249,7 +260,10 @@ impl Game<'_> {
|
||||
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());
|
||||
// PlayerRideableJumping: horses, camels and nautili (the dash).
|
||||
let saddled = self.mobs[i].extra.saddled
|
||||
&& (equine::is_equine(self.mobs[i].species())
|
||||
|| horizon_client::mobs::nautilus::is_nautilus(self.mobs[i].species()));
|
||||
let mut jump = 0.0;
|
||||
if saddled {
|
||||
let st = &mut self.mount;
|
||||
@@ -290,9 +304,12 @@ impl Game<'_> {
|
||||
) {
|
||||
m.extra.counter = 20;
|
||||
}
|
||||
let sound = "minecraft:entity.horse.jump";
|
||||
let at = m.center();
|
||||
self.audio.play(sound, Some(at), 0.4, 1.0);
|
||||
// The nautilus plays its dash sound itself.
|
||||
if equine::is_equine(m.species()) {
|
||||
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);
|
||||
@@ -315,7 +332,7 @@ impl Game<'_> {
|
||||
};
|
||||
let m = &self.mobs[i];
|
||||
let mut at = Vec3::new(m.position.x, m.position.y + seat(m.species()), m.position.z);
|
||||
if m.species() == Species::Camel {
|
||||
if horizon_client::mobs::camel::is_camel(m.species()) {
|
||||
// Camel.getPassengerAttachmentPoint: the driver half a block
|
||||
// forward, at the body anchor (lower while sitting).
|
||||
let scale = if m.is_baby() { 0.6 } else { 1.0 };
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
//! Nautili on the game side (`AbstractNautilus.mobInteract`): taming with
|
||||
//! pufferfish, feeding, the saddle and armour, riding, and the zombie
|
||||
//! nautilus a drowned with a trident sometimes rides.
|
||||
use super::Game;
|
||||
use horizon_client::{
|
||||
items::ItemStack,
|
||||
mobs::{MobEvent, Species, nautilus},
|
||||
};
|
||||
use horizon_core::random::RandomSource;
|
||||
|
||||
impl Game<'_> {
|
||||
fn item_tagged(&self, tag: &str, item: &str) -> bool {
|
||||
self.res
|
||||
.items
|
||||
.item_tags
|
||||
.get(tag)
|
||||
.is_some_and(|t| t.contains(item))
|
||||
}
|
||||
/// `AbstractNautilus.usePlayerItem`: bucketed fish leave a water bucket.
|
||||
fn use_nautilus_food(&mut self, item: &str) {
|
||||
let bucket = self.item_tagged("minecraft:nautilus_bucket_food", item);
|
||||
self.consume_held();
|
||||
if bucket && !self.creative {
|
||||
let water = ItemStack::new("minecraft:water_bucket", 1);
|
||||
if self.inventory[self.selected].is_none() {
|
||||
self.inventory[self.selected] = Some(water);
|
||||
} else if let Some(rest) = self.give(water) {
|
||||
let at = self.eye_position().unwrap_or([0.0; 3]);
|
||||
self.spawn_item(rest, at, [0.0; 3], 40);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn nautilus_sound(&mut self, index: usize, sound: &str) {
|
||||
let at = self.mobs[index].center();
|
||||
self.audio
|
||||
.play(&format!("minecraft:{sound}"), Some(at), 1.0, 1.0);
|
||||
}
|
||||
/// `AbstractNautilus.mobInteract`. Returns whether the click was used.
|
||||
pub(super) fn interact_nautilus(&mut self, index: usize, item: &str) -> bool {
|
||||
let m = &self.mobs[index];
|
||||
if !m.alive() || Some(m.id) == self.riding {
|
||||
return false;
|
||||
}
|
||||
let taming: Vec<String> = self
|
||||
.res
|
||||
.items
|
||||
.item_tags
|
||||
.get("minecraft:nautilus_taming_items")
|
||||
.map(|t| t.iter().cloned().collect())
|
||||
.unwrap_or_default();
|
||||
let food = nautilus::is_food(m, item, &taming);
|
||||
let sneaking = self.keys.contains(&winit::keyboard::KeyCode::ShiftLeft)
|
||||
|| self.keys.contains(&winit::keyboard::KeyCode::ShiftRight);
|
||||
let tame = m.extra.tame;
|
||||
if m.is_baby() {
|
||||
// Animal.mobInteract: food grows a baby up by a tenth.
|
||||
if !food {
|
||||
return false;
|
||||
}
|
||||
let m = &mut self.mobs[index];
|
||||
if !m.extra.age_locked {
|
||||
let secs = (-m.extra.age / 20) as f32 * 0.1;
|
||||
m.extra.age = (m.extra.age + (secs as i32) * 20).min(0);
|
||||
}
|
||||
let sound = nautilus::eat_sound(m);
|
||||
self.use_nautilus_food(item);
|
||||
self.nautilus_sound(index, sound);
|
||||
return true;
|
||||
}
|
||||
// Shift-use on a tame one opens its (saddle and armour) screen.
|
||||
if tame && sneaking {
|
||||
return false;
|
||||
}
|
||||
if !item.is_empty() {
|
||||
if !tame && food {
|
||||
// tryToTame: one time in three.
|
||||
self.use_nautilus_food(item);
|
||||
let m = &mut self.mobs[index];
|
||||
let tamed = m.random.next_int_bound(3).unwrap_or(1) == 0;
|
||||
if tamed {
|
||||
m.extra.tame = true;
|
||||
m.extra.owner = self.level.player_uuid.or(Some([0, 0, 0, 1]));
|
||||
m.persistent = true;
|
||||
m.nav_stop();
|
||||
m.ai.target = None;
|
||||
}
|
||||
let at = [
|
||||
m.position.x,
|
||||
m.position.y + f64::from(m.height()) * 0.5 + 0.5,
|
||||
m.position.z,
|
||||
];
|
||||
let sound = nautilus::eat_sound(m);
|
||||
let kind = if tamed { "heart" } else { "smoke" };
|
||||
let _ = self.handle_mob_events(vec![MobEvent::Particles { kind, at, count: 7 }]);
|
||||
self.nautilus_sound(index, sound);
|
||||
if tamed {
|
||||
let view = self.mob_entity(&self.mobs[index]);
|
||||
self.trigger_entity("minecraft:tame_animal", "entity", &view);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
let m = &self.mobs[index];
|
||||
if food && m.health < m.attrs.max_health {
|
||||
// feed(player, hand, stack, 2, 1).
|
||||
let sound = nautilus::eat_sound(m);
|
||||
let m = &mut self.mobs[index];
|
||||
m.health = (m.health + 2.0).min(m.attrs.max_health);
|
||||
self.use_nautilus_food(item);
|
||||
self.nautilus_sound(index, sound);
|
||||
return true;
|
||||
}
|
||||
// Equippable.equipOnInteract: a saddle or nautilus armour on a
|
||||
// tame adult.
|
||||
let m = &mut self.mobs[index];
|
||||
if item == "minecraft:saddle" && tame && !m.extra.saddled {
|
||||
let held = self.inventory[self.selected].clone();
|
||||
m.set_saddle(held);
|
||||
let sound = nautilus::saddle_sound(m);
|
||||
self.nautilus_sound(index, sound);
|
||||
self.consume_held();
|
||||
return true;
|
||||
}
|
||||
if item.ends_with("_nautilus_armor") && tame && m.extra.head.is_none() {
|
||||
m.extra.head = Some(item.into());
|
||||
self.nautilus_sound(index, "item.armor.equip_nautilus");
|
||||
self.consume_held();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if tame && !food {
|
||||
// doPlayerRide.
|
||||
let id = self.mobs[index].id;
|
||||
self.break_leash(id, true, false);
|
||||
self.yaw = self.mobs[index].yaw;
|
||||
self.riding = Some(id);
|
||||
self.mount.reset_jump();
|
||||
self.trigger_player("minecraft:started_riding");
|
||||
return true;
|
||||
}
|
||||
// Animal.mobInteract: a tame adult fed falls in love (not a zombie).
|
||||
let m = &mut self.mobs[index];
|
||||
if food && m.species() == Species::Nautilus && m.extra.age == 0 && m.extra.in_love <= 0 {
|
||||
m.extra.in_love = 600;
|
||||
m.extra.love_player = true;
|
||||
let sound = nautilus::eat_sound(m);
|
||||
self.use_nautilus_food(item);
|
||||
self.nautilus_sound(index, sound);
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -137,6 +137,66 @@ impl Game<'_> {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// After Zombie.finalizeSpawn's chickens: Husk and Drowned mounts.
|
||||
match species {
|
||||
Species::Husk if natural => self.spawn_camel_husk_jockey(id, at),
|
||||
Species::Drowned if natural && !baby => self.spawn_zombie_nautilus_jockey(id, at),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// `Husk.finalizeSpawn`: where a camel husk fits, one natural husk in ten
|
||||
/// takes an iron spear and rides one (with a parched; Horizon seats one
|
||||
/// rider, so the parched stands beside it).
|
||||
fn spawn_camel_husk_jockey(&mut self, id: u32, at: [f64; 3]) {
|
||||
let (bx, by, bz) = (at[0].floor(), at[1].floor(), at[2].floor());
|
||||
let room = {
|
||||
let w = self.mob_world_base(&[]);
|
||||
w.no_collision(horizon_core::geometry::Aabb::new(
|
||||
Vec3::new(bx + 0.5 - 0.85, by, bz + 0.5 - 0.85),
|
||||
Vec3::new(bx + 0.5 + 0.85, by + 2.375, bz + 0.5 + 0.85),
|
||||
))
|
||||
};
|
||||
if !room || self.world.random.next_float() >= 0.1 {
|
||||
return;
|
||||
}
|
||||
if let Some(h) = self.mobs.iter_mut().find(|m| m.id == id) {
|
||||
h.extra.main_hand = Some("minecraft:iron_spear".into());
|
||||
}
|
||||
let Some(camel) = self.spawn_mob("minecraft:camel_husk", at, false) else {
|
||||
return;
|
||||
};
|
||||
self.mount_mob(id, camel);
|
||||
let _ = self.spawn_mob("minecraft:parched", at, false);
|
||||
}
|
||||
/// `Drowned.finalizeSpawn`: half the natural drowned holding a trident,
|
||||
/// outside the rivers and oceans that breed more drowned, ride a zombie
|
||||
/// nautilus.
|
||||
fn spawn_zombie_nautilus_jockey(&mut self, id: u32, at: [f64; 3]) {
|
||||
let Some(d) = self.mobs.iter().find(|m| m.id == id) else {
|
||||
return;
|
||||
};
|
||||
if d.extra.main_hand.as_deref() != Some("minecraft:trident")
|
||||
|| self.world.random.next_float() >= 0.5
|
||||
{
|
||||
return;
|
||||
}
|
||||
let (x, y, z) = (
|
||||
at[0].floor() as i32,
|
||||
at[1].floor() as i32,
|
||||
at[2].floor() as i32,
|
||||
);
|
||||
let frequent = self.world.chunks.get(&(x >> 4, z >> 4)).is_some_and(|c| {
|
||||
let b = self.res.biomes.get(c.biome(x, y, z));
|
||||
self.res
|
||||
.mob_data
|
||||
.biome_has("minecraft:more_frequent_drowned_spawns", &b.name)
|
||||
});
|
||||
if frequent {
|
||||
return;
|
||||
}
|
||||
if let Some(n) = self.spawn_mob("minecraft:zombie_nautilus", at, false) {
|
||||
self.mount_mob(id, n);
|
||||
}
|
||||
}
|
||||
fn free_chicken_near(&self, at: [f64; 3]) -> Option<u32> {
|
||||
self.mobs
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
//! Sulfur cubes on the game side (`SulfurCube.mobInteract`, `pickUpItem`,
|
||||
//! `remove`): feeding babies, swallowing a held block, shearing it back
|
||||
//! out, lighting an explosive one, swallowing blocks from the ground and
|
||||
//! splitting into two babies.
|
||||
use super::Game;
|
||||
use horizon_client::{
|
||||
items::ItemStack,
|
||||
mobs::{Mob, Species, sulfur_cube},
|
||||
};
|
||||
use horizon_core::random::RandomSource;
|
||||
|
||||
impl Game<'_> {
|
||||
fn sulfur_sound(&mut self, index: usize, sound: &str) {
|
||||
let at = self.mobs[index].center();
|
||||
self.audio
|
||||
.play(&format!("minecraft:{sound}"), Some(at), 1.0, 1.0);
|
||||
}
|
||||
/// Spit the swallowed block out on top (`EntityAttachment.PASSENGER`).
|
||||
fn eject_sulfur_block(&mut self, index: usize) {
|
||||
let m = &mut self.mobs[index];
|
||||
let Some(item) = m.extra.head.take() else {
|
||||
return;
|
||||
};
|
||||
let at = [
|
||||
m.position.x,
|
||||
m.position.y + f64::from(m.height()),
|
||||
m.position.z,
|
||||
];
|
||||
self.spawn_item(ItemStack::new(&item, 1), at, [0.0, 0.2, 0.0], 10);
|
||||
}
|
||||
/// `SulfurCube.mobInteract`. Returns whether the click was used.
|
||||
pub(super) fn interact_sulfur_cube(&mut self, index: usize, item: &str) -> bool {
|
||||
let m = &self.mobs[index];
|
||||
if m.species() != Species::SulfurCube || !m.alive() {
|
||||
return false;
|
||||
}
|
||||
if m.is_baby() {
|
||||
// Slime balls grow a baby up by a tenth.
|
||||
if !m.kind.food.iter().any(|f| f == item) || m.extra.age_locked {
|
||||
return false;
|
||||
}
|
||||
let m = &mut self.mobs[index];
|
||||
let secs = (-m.extra.age / 20) as f32 * 0.1;
|
||||
m.extra.age = (m.extra.age + (secs as i32) * 20).min(0);
|
||||
self.consume_held();
|
||||
self.sulfur_sound(index, "entity.small_sulfur_cube.eat");
|
||||
return true;
|
||||
}
|
||||
if sulfur_cube::primed(m) {
|
||||
return false;
|
||||
}
|
||||
let explosive = sulfur_cube::archetype(m).is_some_and(|a| a.explosion.is_some());
|
||||
if explosive && matches!(item, "minecraft:flint_and_steel" | "minecraft:fire_charge") {
|
||||
if !self.ui.rules.bool("tnt_explodes") {
|
||||
return false;
|
||||
}
|
||||
sulfur_cube::prime(&mut self.mobs[index], false);
|
||||
if item == "minecraft:flint_and_steel" {
|
||||
self.damage_held_tool();
|
||||
} else {
|
||||
self.consume_held();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if item == "minecraft:shears" && sulfur_cube::has_body(m) {
|
||||
// shear: out comes the block, and nothing is swallowed for 5 s.
|
||||
self.eject_sulfur_block(index);
|
||||
self.mobs[index].extra.ints[3] = sulfur_cube::PICKUP_TIMER;
|
||||
self.sulfur_sound(index, "entity.sulfur_cube.eject");
|
||||
self.damage_held_tool();
|
||||
return true;
|
||||
}
|
||||
if sulfur_cube::swallowable(m, item) {
|
||||
// equipItem: not the same block again; the old one comes out.
|
||||
if m.extra.head.as_deref() == Some(item) {
|
||||
return false;
|
||||
}
|
||||
self.eject_sulfur_block(index);
|
||||
self.mobs[index].extra.head = Some(item.into());
|
||||
self.consume_held();
|
||||
self.sulfur_sound(index, "entity.sulfur_cube.absorb");
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
/// `SulfurCubeSearchForItemsGoal` and `pickUpItem`: an adult with nothing
|
||||
/// inside hops to a block it can swallow within 8 and takes it in.
|
||||
pub(super) fn sulfur_cube_pickups(&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::SulfurCube {
|
||||
continue;
|
||||
}
|
||||
if !m.alive() || m.is_baby() || sulfur_cube::has_body(m) || m.extra.ints[3] > 0 {
|
||||
self.mobs[i].extra.point = None;
|
||||
continue;
|
||||
}
|
||||
let reach = m
|
||||
.bounds()
|
||||
.inflate(horizon_core::geometry::Vec3::new(8.0, 8.0, 8.0));
|
||||
let pos = m.position;
|
||||
let best = self
|
||||
.dropped
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, e)| {
|
||||
e.pickup_delay == 0
|
||||
&& reach.contains(e.position)
|
||||
&& sulfur_cube::swallowable(m, &e.stack.item)
|
||||
})
|
||||
.map(|(j, e)| (j, e.position.distance_squared(pos)))
|
||||
.min_by(|a, b| a.1.total_cmp(&b.1));
|
||||
let Some((j, _)) = best else {
|
||||
self.mobs[i].extra.point = None;
|
||||
continue;
|
||||
};
|
||||
// Mob.aiStep: items within the box grown by (1, 0, 1).
|
||||
let touch = m
|
||||
.bounds()
|
||||
.inflate(horizon_core::geometry::Vec3::new(1.0, 0.0, 1.0));
|
||||
let e = &self.dropped[j];
|
||||
let close = touch.contains(e.position);
|
||||
self.mobs[i].extra.point = Some([e.position.x, e.position.y, e.position.z]);
|
||||
if !griefing || !close {
|
||||
continue;
|
||||
}
|
||||
let item = e.stack.item.clone();
|
||||
let e = &mut self.dropped[j];
|
||||
e.stack.count -= 1;
|
||||
if e.stack.count == 0 {
|
||||
self.dropped.remove(j);
|
||||
}
|
||||
let m = &mut self.mobs[i];
|
||||
m.extra.head = Some(item);
|
||||
m.extra.point = None;
|
||||
self.sulfur_sound(i, "entity.sulfur_cube.absorb");
|
||||
}
|
||||
}
|
||||
/// `AbstractCubeMob.remove`: a dead adult splits into two babies (none
|
||||
/// when it was primed).
|
||||
pub(super) fn split_sulfur_cube(&mut self, m: &Mob) {
|
||||
let size = m.extra.size;
|
||||
if size <= 1 {
|
||||
return;
|
||||
}
|
||||
let offset = f64::from(m.width()) / 2.0;
|
||||
for i in 0..sulfur_cube::split_count(m) {
|
||||
let xd = (f64::from(i % 2) - 0.5) * offset;
|
||||
let zd = (f64::from(i / 2) - 0.5) * offset;
|
||||
let at = [m.position.x + xd, m.position.y + 0.5, m.position.z + zd];
|
||||
let yaw = self.world.random.next_float() * 360.0;
|
||||
if let Some(id) = self.spawn_mob(&m.kind.id, at, m.persistent)
|
||||
&& let Some(c) = self.mobs.iter_mut().find(|c| c.id == id)
|
||||
{
|
||||
c.extra.age = -24000;
|
||||
sulfur_cube::set_size(c, size / 2, true);
|
||||
c.yaw = yaw;
|
||||
c.body_yaw = yaw;
|
||||
c.head_yaw = yaw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ pub mod keyframes;
|
||||
pub mod leash;
|
||||
pub mod living;
|
||||
pub mod llama;
|
||||
pub mod nautilus;
|
||||
pub mod nav;
|
||||
pub mod nether;
|
||||
pub mod path;
|
||||
@@ -46,6 +47,7 @@ pub mod shulker;
|
||||
pub mod sniffer;
|
||||
pub mod spawning;
|
||||
pub mod species;
|
||||
pub mod sulfur_cube;
|
||||
pub mod tame;
|
||||
pub mod trader;
|
||||
pub mod undead;
|
||||
@@ -236,6 +238,7 @@ impl MobTypes {
|
||||
let types: Value = serde_json::from_slice(&fs::read(root.join("entity-types.json"))?)?;
|
||||
let models: Value = serde_json::from_slice(&fs::read(root.join("entity-models.json"))?)?;
|
||||
let item_tags = crate::items::load_tags(root, "item").unwrap_or_default();
|
||||
sulfur_cube::load_archetype_items(&item_tags);
|
||||
let tag = |name: &str| -> Arc<[String]> {
|
||||
let mut v: Vec<String> = item_tags
|
||||
.get(&format!("minecraft:{name}"))
|
||||
|
||||
@@ -93,6 +93,8 @@ pub enum Family {
|
||||
HappyGhast,
|
||||
Warden,
|
||||
Creaking,
|
||||
/// Nautili and zombie nautili.
|
||||
Nautilus,
|
||||
}
|
||||
pub fn family(s: Species) -> Family {
|
||||
use Species as S;
|
||||
@@ -140,11 +142,13 @@ pub fn family(s: Species) -> Family {
|
||||
| S::SkeletonHorse
|
||||
| S::ZombieHorse
|
||||
| S::Camel
|
||||
| S::CamelHusk
|
||||
| S::Llama
|
||||
| S::TraderLlama => Family::Equine,
|
||||
S::Nautilus | S::ZombieNautilus => Family::Nautilus,
|
||||
S::Phantom => Family::Phantom,
|
||||
S::Enderman => Family::Enderman,
|
||||
S::Slime | S::MagmaCube => Family::Cube,
|
||||
S::Slime | S::MagmaCube | S::SulfurCube => Family::Cube,
|
||||
S::Guardian | S::ElderGuardian => Family::Guardian,
|
||||
S::Warden => Family::Warden,
|
||||
S::Shulker => Family::Shulker,
|
||||
@@ -193,6 +197,7 @@ pub fn register(m: &mut Mob) {
|
||||
Family::HappyGhast => super::happy_ghast::register(m),
|
||||
Family::Warden => super::warden::register(m),
|
||||
Family::Creaking => super::creaking::register(m),
|
||||
Family::Nautilus => super::nautilus::register(m),
|
||||
}
|
||||
super::raider::register(m);
|
||||
}
|
||||
@@ -418,6 +423,8 @@ fn play_ambient(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
},
|
||||
Species::Zombie | Species::Husk if m.is_baby() => m.kind.sounds[0],
|
||||
Species::Drowned if m.fluids.in_water => "entity.drowned.ambient_water",
|
||||
// Nautilus/ZombieNautilus.getAmbientSound: by age, under water or on land.
|
||||
Species::Nautilus | Species::ZombieNautilus => super::nautilus::sounds(m)[0],
|
||||
Species::Enderman if m.ai.target.is_some() => "entity.enderman.scream",
|
||||
Species::Wolf if m.ai.target.is_some() => "entity.wolf.growl",
|
||||
Species::Wolf if m.random.next_int_bound(3).unwrap_or(1) == 0 => {
|
||||
@@ -656,6 +663,11 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
}
|
||||
Species::SnowGolem => super::golem::snow_ai_step(m, w, events),
|
||||
Species::Slime | Species::MagmaCube => super::cube::ai_step(m, w, events),
|
||||
Species::SulfurCube => {
|
||||
super::cube::ai_step(m, w, events);
|
||||
super::sulfur_cube::ai_step(m, w, events);
|
||||
}
|
||||
Species::Nautilus | Species::ZombieNautilus => super::nautilus::ai_step(m, w, events),
|
||||
Species::Chicken => farm::chicken_ai_step(m, w, events),
|
||||
Species::Sheep if m.extra.anim_ticks > 0 => {
|
||||
m.extra.anim_ticks -= 1;
|
||||
@@ -680,6 +692,11 @@ fn check_despawn(m: &mut Mob, w: &MobWorld) -> bool {
|
||||
if super::raider::keeps_alive(m, d)
|
||||
|| super::zombie_villager::keeps_alive(m)
|
||||
|| super::riders::keeps_alive(m)
|
||||
// requiresCustomPersistence: a tame nautilus, a sulfur cube holding a
|
||||
// block or let out of a bucket.
|
||||
|| super::nautilus::is_nautilus(m.species()) && m.extra.tame
|
||||
|| m.species() == Species::SulfurCube
|
||||
&& (super::sulfur_cube::has_body(m) || m.extra.scratch[3] != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -718,12 +735,23 @@ pub fn speed_bonus(m: &Mob) -> f64 {
|
||||
_ => 1.0,
|
||||
}
|
||||
}
|
||||
/// The ambient, hurt and death sounds of species that pick them by state
|
||||
/// (`getHurtSound` / `getDeathSound` overrides); the type's otherwise.
|
||||
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),
|
||||
_ => m.kind.sounds,
|
||||
}
|
||||
}
|
||||
pub fn sound_volume(m: &Mob) -> f32 {
|
||||
match m.species() {
|
||||
Species::Ghast => 5.0,
|
||||
Species::HappyGhast => super::happy_ghast::volume(m),
|
||||
Species::Warden => 4.0,
|
||||
Species::Slime | Species::MagmaCube => 0.4 * m.extra.size.max(1) as f32,
|
||||
Species::Slime | Species::MagmaCube | Species::SulfurCube => {
|
||||
0.4 * m.extra.size.max(1) as f32
|
||||
}
|
||||
Species::Cod
|
||||
| Species::Salmon
|
||||
| Species::TropicalFish
|
||||
@@ -745,6 +773,10 @@ pub fn walk_target_value(m: &Mob, w: &MobWorld, p: [i32; 3]) -> f32 {
|
||||
if family(m.species()) == Family::Guardian && w.fluid(p[0], p[1], p[2]) == Fluid::Water {
|
||||
return 10.0 + light();
|
||||
}
|
||||
// AbstractNautilus.getWalkTargetValue: everywhere alike.
|
||||
if matches!(m.species(), Species::Nautilus | Species::ZombieNautilus) {
|
||||
return 0.0;
|
||||
}
|
||||
if m.hostile()
|
||||
&& !matches!(
|
||||
m.species(),
|
||||
@@ -770,6 +802,7 @@ pub fn accepts_damage(m: &mut Mob, source: &Damage, _amount: f32) -> bool {
|
||||
Species::Wither => super::wither::accepts(m, source.kind, source.attacker, false),
|
||||
Species::Warden => super::warden::accepts_damage(m, source),
|
||||
Species::Shulker => super::shulker::accepts(m, source),
|
||||
Species::SulfurCube => super::sulfur_cube::accepts_damage(m, source, _amount),
|
||||
Species::Enderman => super::enderman::on_damage(m, source),
|
||||
Species::WitherSkeleton | Species::Blaze | Species::MagmaCube | Species::Strider
|
||||
if source.is_fire() =>
|
||||
@@ -787,6 +820,7 @@ pub fn after_hurt(m: &mut Mob, source: &Damage) {
|
||||
Species::Shulker => super::shulker::after_hurt(m),
|
||||
Species::Warden => super::warden::hurt(m, source),
|
||||
Species::Wolf => super::tame::after_hurt(m, source),
|
||||
Species::Nautilus | Species::ZombieNautilus => super::nautilus::after_hurt(m, source),
|
||||
// NeutralMob: an iron golem hit by the player stays angry a while.
|
||||
// PiglinAi.wasHurtBy: drop what is being admired, no admiring for
|
||||
// a while after a player's hit, and anger.
|
||||
@@ -907,6 +941,7 @@ pub fn custom_travel(m: &mut Mob, w: &MobWorld, input: Vec3, events: &mut Vec<Mo
|
||||
Family::Shulker => true,
|
||||
Family::Vex => super::vex::travel(m),
|
||||
Family::Villager => super::villager::travel(m),
|
||||
Family::Nautilus => super::nautilus::travel(m, w, input, events),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use std::f32::consts::PI;
|
||||
/// The setupAnim implementation a model uses.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Anim {
|
||||
Nautilus,
|
||||
HappyGhast,
|
||||
Sniffer,
|
||||
Breeze,
|
||||
@@ -461,6 +462,7 @@ pub fn setup(
|
||||
Anim::Breeze => super::breeze::anim(m, s, p, w_anims),
|
||||
Anim::Sniffer => super::sniffer::anim(m, s, p, w_anims),
|
||||
Anim::HappyGhast => super::happy_ghast::anim(m, s, p),
|
||||
Anim::Nautilus => super::nautilus::anim(m, s, p, w_anims),
|
||||
Anim::Llama => super::llama::anim(m, s, p),
|
||||
Anim::Warden => super::warden::anim(m, s, p, w_anims),
|
||||
Anim::Allay => super::allay::anim(m, s, p),
|
||||
|
||||
@@ -51,13 +51,13 @@ pub fn refuse_to_move(m: &Mob) -> bool {
|
||||
}
|
||||
fn sit_down(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
if !sitting(m) {
|
||||
sound(m, "entity.camel.sit", events);
|
||||
sound(m, voice(m, 0), events);
|
||||
m.extra.egg_time = -(m.age as i32).max(1);
|
||||
}
|
||||
}
|
||||
pub fn stand_up(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
if sitting(m) {
|
||||
sound(m, "entity.camel.stand", events);
|
||||
sound(m, voice(m, 1), events);
|
||||
m.extra.egg_time = m.age as i32;
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,26 @@ pub fn stand_up(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
pub fn stand_up_instantly(m: &mut Mob) {
|
||||
m.extra.egg_time = (i64::from(m.age) - STAND_UP - 1).max(0) as i32;
|
||||
}
|
||||
/// `is_camel`: camels and camel husks (`CamelHusk extends Camel`).
|
||||
pub fn is_camel(s: super::Species) -> bool {
|
||||
matches!(s, super::Species::Camel | super::Species::CamelHusk)
|
||||
}
|
||||
/// The sit, stand, dash ready, dash and eat sounds (`CamelHusk` overrides each).
|
||||
pub fn voice(m: &Mob, which: usize) -> &'static str {
|
||||
let husk = m.species() == super::Species::CamelHusk;
|
||||
match (which, husk) {
|
||||
(0, false) => "entity.camel.sit",
|
||||
(0, true) => "entity.camel_husk.sit",
|
||||
(1, false) => "entity.camel.stand",
|
||||
(1, true) => "entity.camel_husk.stand",
|
||||
(2, false) => "entity.camel.dash_ready",
|
||||
(2, true) => "entity.camel_husk.dash_ready",
|
||||
(3, false) => "entity.camel.dash",
|
||||
(3, true) => "entity.camel_husk.dash",
|
||||
(_, false) => "entity.camel.eat",
|
||||
(_, true) => "entity.camel_husk.eat",
|
||||
}
|
||||
}
|
||||
fn sound(m: &Mob, name: &'static str, events: &mut Vec<MobEvent>) {
|
||||
events.push(MobEvent::Sound(
|
||||
name,
|
||||
@@ -82,7 +102,10 @@ impl Goal for CamelPanic {
|
||||
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)
|
||||
// CamelHusk.isMobControlled: not with a mob on its back either.
|
||||
m.rider.is_none()
|
||||
&& !(m.species() == super::Species::CamelHusk && m.extra.rider.is_some())
|
||||
&& self.0.can_use(m, cx)
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
self.0.can_continue(m, cx)
|
||||
@@ -130,7 +153,7 @@ pub fn ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
if m.extra.anim_ticks > 0 {
|
||||
m.extra.anim_ticks -= 1;
|
||||
if m.extra.anim_ticks == 0 {
|
||||
sound(m, "entity.camel.dash_ready", events);
|
||||
sound(m, voice(m, 2), events);
|
||||
}
|
||||
}
|
||||
if sitting(m) && m.fluids.in_water {
|
||||
@@ -188,7 +211,7 @@ pub fn dash(m: &mut Mob, amount: f32, events: &mut Vec<MobEvent>) {
|
||||
m.velocity.y += 1.4285 * a * 0.42;
|
||||
m.extra.anim_ticks = DASH_COOLDOWN;
|
||||
m.extra.flag2 = true;
|
||||
sound(m, "entity.camel.dash", events);
|
||||
sound(m, voice(m, 3), events);
|
||||
}
|
||||
/// `CamelModel.setupAnim`.
|
||||
pub fn anim(
|
||||
|
||||
@@ -14,6 +14,9 @@ const SQUISH: usize = 0;
|
||||
const TARGET_SQUISH: usize = 1;
|
||||
|
||||
pub fn register(m: &mut Mob) {
|
||||
if m.species() == Species::SulfurCube {
|
||||
return super::sulfur_cube::register(m);
|
||||
}
|
||||
m.ai.goals.add(1, CubeFloat);
|
||||
m.ai.goals.add(2, CubeAttack { tired: 0 });
|
||||
m.ai.goals.add(
|
||||
@@ -59,7 +62,8 @@ fn tiny(m: &Mob) -> bool {
|
||||
m.extra.size <= 1
|
||||
}
|
||||
fn can_deal_damage(m: &Mob) -> bool {
|
||||
m.species() == Species::MagmaCube || !tiny(m)
|
||||
// SulfurCube.canDealDamage: never.
|
||||
m.species() == Species::MagmaCube || !tiny(m) && m.species() != Species::SulfurCube
|
||||
}
|
||||
fn jump_delay(m: &mut Mob) -> i32 {
|
||||
let base = m.random.next_int_bound(20).unwrap_or(0) + 10;
|
||||
@@ -75,6 +79,10 @@ fn sound_pitch(m: &mut Mob) -> f32 {
|
||||
}
|
||||
/// CubeMobMoveControl.tick
|
||||
pub fn move_control(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
// SulfurCubeMobMoveControl: still while holding a block.
|
||||
if m.species() == Species::SulfurCube && super::sulfur_cube::has_body(m) {
|
||||
return;
|
||||
}
|
||||
let want = m.extra.vector[0] as f32;
|
||||
m.yaw = rotlerp(m.yaw, want, 90.0);
|
||||
m.head_yaw = m.yaw;
|
||||
@@ -97,6 +105,7 @@ pub fn move_control(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
m.ai.jump = true;
|
||||
let jump = match (m.species(), tiny(m)) {
|
||||
(Species::MagmaCube, _) => "entity.magma_cube.jump",
|
||||
(Species::SulfurCube, _) => super::sulfur_cube::jump_sound(m),
|
||||
(_, true) => "entity.slime.jump_small",
|
||||
_ => "entity.slime.jump",
|
||||
};
|
||||
@@ -112,11 +121,11 @@ pub fn move_control(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
m.set_speed(speed);
|
||||
}
|
||||
}
|
||||
fn set_direction(m: &mut Mob, y_rot: f32, aggressive: bool) {
|
||||
pub(super) fn set_direction(m: &mut Mob, y_rot: f32, aggressive: bool) {
|
||||
m.extra.vector[0] = f64::from(y_rot);
|
||||
m.extra.flag = aggressive;
|
||||
}
|
||||
fn set_wanted(m: &mut Mob, speed: f64) {
|
||||
pub(super) fn set_wanted(m: &mut Mob, speed: f64) {
|
||||
m.ai.mov.speed_modifier = speed;
|
||||
m.ai.mov.operation = Operation::MoveTo;
|
||||
}
|
||||
@@ -136,6 +145,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
let was = m.extra.flag2;
|
||||
if m.on_ground && !was {
|
||||
let squish = match (m.species(), tiny(m)) {
|
||||
(Species::SulfurCube, _) => super::sulfur_cube::squish_sound(m),
|
||||
(Species::MagmaCube, true) => "entity.magma_cube.squish_small",
|
||||
(Species::MagmaCube, false) => "entity.magma_cube.squish",
|
||||
(_, true) => "entity.slime.squish_small",
|
||||
@@ -213,7 +223,7 @@ pub fn scale(m: &Mob, alpha: f32) -> glam::Mat4 {
|
||||
}
|
||||
/// CubeMobFloatGoal
|
||||
#[derive(Clone, Debug)]
|
||||
struct CubeFloat;
|
||||
pub(super) struct CubeFloat;
|
||||
impl Goal for CubeFloat {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
@@ -271,8 +281,8 @@ impl Goal for CubeAttack {
|
||||
}
|
||||
}
|
||||
/// CubeMobRandomDirectionGoal
|
||||
#[derive(Clone, Debug)]
|
||||
struct CubeRandomDirection {
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(super) struct CubeRandomDirection {
|
||||
degrees: f32,
|
||||
next: i32,
|
||||
}
|
||||
@@ -296,7 +306,7 @@ impl Goal for CubeRandomDirection {
|
||||
}
|
||||
/// CubeMobKeepOnJumpingGoal
|
||||
#[derive(Clone, Debug)]
|
||||
struct CubeKeepJumping;
|
||||
pub(super) struct CubeKeepJumping;
|
||||
impl Goal for CubeKeepJumping {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
|
||||
@@ -55,6 +55,7 @@ pub fn is_equine(s: Species) -> bool {
|
||||
| Species::SkeletonHorse
|
||||
| Species::ZombieHorse
|
||||
| Species::Camel
|
||||
| Species::CamelHusk
|
||||
| Species::Llama
|
||||
| Species::TraderLlama
|
||||
)
|
||||
@@ -75,7 +76,7 @@ fn can_rear(s: Species) -> bool {
|
||||
)
|
||||
}
|
||||
pub fn register(m: &mut Mob) {
|
||||
if m.species() == Species::Camel {
|
||||
if super::camel::is_camel(m.species()) {
|
||||
return super::camel::register(m);
|
||||
}
|
||||
if super::llama::is_llama(m.species()) {
|
||||
@@ -159,6 +160,7 @@ pub fn controlled(m: &Mob) -> bool {
|
||||
// Pig/Strider.getControllingPassenger: saddled, the rider holding the stick.
|
||||
Species::Pig | Species::Strider => m.extra.saddled && r.steer,
|
||||
Species::HappyGhast => super::happy_ghast::controlled(m),
|
||||
Species::Nautilus | Species::ZombieNautilus => super::nautilus::controlled(m),
|
||||
_ => m.extra.saddled || m.species() == Species::SkeletonHorse && m.extra.tame,
|
||||
}
|
||||
}
|
||||
@@ -305,6 +307,10 @@ pub fn ridden_step(m: &mut Mob) {
|
||||
let Some(r) = m.rider else {
|
||||
return;
|
||||
};
|
||||
// AbstractNautilus.tickRidden turns half way toward the rider.
|
||||
if super::nautilus::is_nautilus(m.species()) {
|
||||
return super::nautilus::ridden(m);
|
||||
}
|
||||
m.yaw = r.yaw;
|
||||
m.head_pitch = r.pitch * 0.5;
|
||||
m.body_yaw = r.yaw;
|
||||
@@ -313,6 +319,7 @@ pub fn ridden_step(m: &mut Mob) {
|
||||
if m.species() == Species::HappyGhast {
|
||||
return super::happy_ghast::ridden(m);
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -328,7 +335,7 @@ pub fn ridden_step(m: &mut Mob) {
|
||||
m.set_speed((m.attrs.speed * factor) as f32 * boost);
|
||||
return;
|
||||
}
|
||||
if m.species() == Species::Camel {
|
||||
if super::camel::is_camel(m.species()) {
|
||||
// Camel.tickRidden / getRiddenInput: forward stands it up; no input
|
||||
// while sitting; the jump is a dash.
|
||||
if r.forward > 0.0 && super::camel::sitting(m) {
|
||||
@@ -394,7 +401,7 @@ pub fn ridden_step(m: &mut Mob) {
|
||||
/// `AbstractHorse.aiStep` and `tick`: healing, grazing, the rear and the
|
||||
/// eating/standing/mouth animations.
|
||||
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if m.species() == Species::Camel {
|
||||
if super::camel::is_camel(m.species()) {
|
||||
return super::camel::ai_step(m, events);
|
||||
}
|
||||
if super::llama::is_llama(m.species()) {
|
||||
@@ -457,6 +464,7 @@ pub fn texture(m: &Mob) -> String {
|
||||
Species::Mule => format!("entity/horse/mule{baby}"),
|
||||
Species::SkeletonHorse => format!("entity/horse/horse_skeleton{baby}"),
|
||||
Species::Camel => format!("entity/camel/camel{baby}"),
|
||||
Species::CamelHusk => "entity/camel/camel_husk".into(),
|
||||
_ => format!("entity/horse/horse_zombie{baby}"),
|
||||
}
|
||||
}
|
||||
@@ -478,7 +486,8 @@ pub fn model_name(s: Species) -> &'static str {
|
||||
Species::Donkey => "donkey",
|
||||
Species::Mule => "mule",
|
||||
Species::SkeletonHorse => "skeleton_horse",
|
||||
Species::Camel => "camel",
|
||||
// CamelHuskRenderer: the camel's model (and its saddle layer).
|
||||
Species::Camel | Species::CamelHusk => "camel",
|
||||
_ => "zombie_horse",
|
||||
}
|
||||
}
|
||||
@@ -490,6 +499,7 @@ pub fn saddle_texture(s: Species) -> &'static str {
|
||||
Species::SkeletonHorse => "entity/equipment/skeleton_horse_saddle/saddle",
|
||||
Species::ZombieHorse => "entity/equipment/zombie_horse_saddle/saddle",
|
||||
Species::Camel => "entity/equipment/camel_saddle/saddle",
|
||||
Species::CamelHusk => "entity/equipment/camel_husk_saddle/saddle",
|
||||
_ => "entity/equipment/horse_saddle/saddle",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,6 +424,19 @@ pub fn volume(m: &Mob) -> f32 {
|
||||
}
|
||||
/// `HappyGhastModel.setupAnim`: the tentacles, and the body squeezed under a harness.
|
||||
pub fn anim(m: &Mob, s: &State, p: &mut Poses) {
|
||||
// HappyGhastHarnessModel.setupAnim: the goggles down while ridden
|
||||
// (vanilla's literal -0.7854, not -PI/4).
|
||||
#[allow(clippy::approx_constant)]
|
||||
if p.has("goggles") {
|
||||
let g = p.get("goggles");
|
||||
if m.rider.is_some() {
|
||||
g[3] = 0.0;
|
||||
g[1] = 14.0;
|
||||
} else {
|
||||
g[3] = -0.7854;
|
||||
g[1] = 9.0;
|
||||
}
|
||||
}
|
||||
if wearing_harness(m) {
|
||||
let b = p.get("body");
|
||||
b[6] = 0.9375;
|
||||
|
||||
@@ -430,7 +430,7 @@ impl Mob {
|
||||
pub fn jump_from_ground(&mut self) {
|
||||
if matches!(
|
||||
self.species(),
|
||||
super::Species::Slime | super::Species::MagmaCube
|
||||
super::Species::Slime | super::Species::MagmaCube | super::Species::SulfurCube
|
||||
) {
|
||||
super::cube::jump(self);
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,602 @@
|
||||
//! Nautili and zombie nautili (`AbstractNautilus`, `Nautilus`,
|
||||
//! `ZombieNautilus`, `NautilusAi`, `ZombieNautilusAi`): smooth swimming,
|
||||
//! drying out on land, taming with pufferfish, the saddle and armour, the
|
||||
//! ridden swim with its dash, charging at pufferfish and at whoever hurt
|
||||
//! them, the zombie's temperate and coral variants, and `NautilusModel`.
|
||||
use super::{
|
||||
Mob, MobEvent, MobWorld, Species, Who,
|
||||
anim::{Poses, State},
|
||||
control::{LookKind, MoveKind, Operation},
|
||||
goals::{Breed, Cx, Goal, LOOK, LookAtPlayer, MOVE, Panic, Stroll, Tempt, goal_clone},
|
||||
keyframes::Animation,
|
||||
nav::NavKind,
|
||||
};
|
||||
use crate::blocks::Fluid;
|
||||
use horizon_core::{geometry::Vec3, random::RandomSource};
|
||||
use std::collections::HashMap;
|
||||
|
||||
// Nautilus state: `tame`/`owner`, the saddle, `head` the body armour,
|
||||
// `variant` the zombie's variant (0 temperate, 1 warm), `anim_ticks` the
|
||||
// dash cooldown and `flag2` dashing, `counter` the attack target cooldown,
|
||||
// `counter2` the charge cooldown, `anger` the ticks left of `ANGRY_AT`
|
||||
// (at `ai.last_hurt_by`), `ints[1]` the rider's breath effect given,
|
||||
// `scratch[1]` a dash whose sound is still to play.
|
||||
const DASH_COOLDOWN: i32 = 40;
|
||||
const TIME_BETWEEN_ATTACKS: i32 = 80;
|
||||
const ANGER_DURATION: i32 = 400;
|
||||
/// `ZombieNautilusVariants`: the variant keys in index order.
|
||||
pub const VARIANTS: [&str; 2] = ["temperate", "warm"];
|
||||
|
||||
pub fn is_nautilus(s: Species) -> bool {
|
||||
matches!(s, Species::Nautilus | Species::ZombieNautilus)
|
||||
}
|
||||
fn zombie(m: &Mob) -> bool {
|
||||
m.species() == Species::ZombieNautilus
|
||||
}
|
||||
pub fn register(m: &mut Mob) {
|
||||
// SmoothSwimmingMoveControl(85, 10, 0.011, 0, true), SmoothSwimmingLookControl(10).
|
||||
m.ai.mov.kind = MoveKind::SmoothSwimming {
|
||||
max_turn_x: 85.0,
|
||||
max_turn_y: 10.0,
|
||||
in_water: 0.011,
|
||||
outside: 0.0,
|
||||
gravity: true,
|
||||
};
|
||||
m.ai.look.kind = LookKind::SmoothSwimming(10.0);
|
||||
m.ai.nav.kind = NavKind::Water { breach: false };
|
||||
m.set_malus(super::path::PathType::Water, 0.0);
|
||||
let tempt = m.kind.tempt.clone();
|
||||
let stop = if m.is_baby() { 2.5 } else { 3.5 };
|
||||
let is_zombie = zombie(m);
|
||||
let g = &mut m.ai.goals;
|
||||
if is_zombie {
|
||||
// ZombieNautilusAi: no panic, no love, slower temptation and charge.
|
||||
let mut t = Tempt::new(0.9, tempt, false);
|
||||
t.stop_distance = stop;
|
||||
g.add(1, t);
|
||||
g.add(2, Charge::new(0.5));
|
||||
g.add(3, Stroll::swimming(1.0, 1));
|
||||
g.add(3, LookAtPlayer::new(6.0));
|
||||
} else {
|
||||
g.add(0, Panic::new(1.6));
|
||||
g.add(1, Breed::new(0.4));
|
||||
let mut t = Tempt::new(1.3, tempt, false);
|
||||
t.stop_distance = stop;
|
||||
g.add(2, t);
|
||||
g.add(3, Charge::new(0.6));
|
||||
g.add(4, Stroll::swimming(1.0, 1));
|
||||
g.add(4, LookAtPlayer::new(6.0));
|
||||
}
|
||||
}
|
||||
/// `finalizeSpawn`: `NautilusAi.initMemories` (2400 to 3600 ticks before it
|
||||
/// first looks for prey) and the zombie's variant by biome.
|
||||
pub fn finalize(m: &mut Mob, warm_ocean: bool) {
|
||||
m.extra.counter = 2400 + m.random.next_int_bound(1201).unwrap_or(0);
|
||||
if zombie(m) {
|
||||
m.extra.variant = u8::from(warm_ocean);
|
||||
}
|
||||
}
|
||||
/// `checkNautilusSpawnRules`: 5 to 25 blocks below sea level, water below
|
||||
/// and above.
|
||||
pub fn spawn_rules_ok(w: &MobWorld, x: i32, y: i32, z: i32) -> bool {
|
||||
let sea = 63;
|
||||
(sea - 25..=sea - 5).contains(&y)
|
||||
&& w.fluid(x, y - 1, z) == Fluid::Water
|
||||
&& w.block_name(x, y + 1, z) == "minecraft:water"
|
||||
}
|
||||
/// `getControllingPassenger`: a player on a saddled nautilus.
|
||||
pub fn controlled(m: &Mob) -> bool {
|
||||
m.rider.is_some() && m.extra.saddled
|
||||
}
|
||||
/// `AbstractNautilus.isFood`: taming items while wild, food otherwise.
|
||||
pub fn is_food(m: &Mob, item: &str, taming: &[String]) -> bool {
|
||||
if !m.extra.tame && !m.is_baby() {
|
||||
taming.iter().any(|t| t == item)
|
||||
} else {
|
||||
m.kind.food.iter().any(|t| t == item)
|
||||
}
|
||||
}
|
||||
/// The ambient, hurt and death sounds by age and whether it is under water.
|
||||
pub fn sounds(m: &Mob) -> [&'static str; 3] {
|
||||
let under = m.fluids.eye_in_water;
|
||||
match (zombie(m), m.is_baby(), under) {
|
||||
(true, _, true) => [
|
||||
"entity.zombie_nautilus.ambient",
|
||||
"entity.zombie_nautilus.hurt",
|
||||
"entity.zombie_nautilus.death",
|
||||
],
|
||||
(true, _, false) => [
|
||||
"entity.zombie_nautilus.ambient_land",
|
||||
"entity.zombie_nautilus.hurt_land",
|
||||
"entity.zombie_nautilus.death_land",
|
||||
],
|
||||
(false, true, true) => [
|
||||
"entity.baby_nautilus.ambient",
|
||||
"entity.baby_nautilus.hurt",
|
||||
"entity.baby_nautilus.death",
|
||||
],
|
||||
(false, true, false) => [
|
||||
"entity.baby_nautilus.ambient_land",
|
||||
"entity.baby_nautilus.hurt_land",
|
||||
"entity.baby_nautilus.death_land",
|
||||
],
|
||||
(false, false, true) => [
|
||||
"entity.nautilus.ambient",
|
||||
"entity.nautilus.hurt",
|
||||
"entity.nautilus.death",
|
||||
],
|
||||
(false, false, false) => [
|
||||
"entity.nautilus.ambient_land",
|
||||
"entity.nautilus.hurt_land",
|
||||
"entity.nautilus.death_land",
|
||||
],
|
||||
}
|
||||
}
|
||||
fn dash_sound(m: &Mob) -> &'static str {
|
||||
match (zombie(m), m.fluids.eye_in_water) {
|
||||
(true, true) => "entity.zombie_nautilus.dash",
|
||||
(true, false) => "entity.zombie_nautilus.dash_land",
|
||||
(false, true) => "entity.nautilus.dash",
|
||||
(false, false) => "entity.nautilus.dash_land",
|
||||
}
|
||||
}
|
||||
fn dash_ready_sound(m: &Mob) -> &'static str {
|
||||
match (zombie(m), m.fluids.eye_in_water) {
|
||||
(true, true) => "entity.zombie_nautilus.dash_ready",
|
||||
(true, false) => "entity.zombie_nautilus.dash_ready_land",
|
||||
(false, true) => "entity.nautilus.dash_ready",
|
||||
(false, false) => "entity.nautilus.dash_ready_land",
|
||||
}
|
||||
}
|
||||
/// `playEatingSound`.
|
||||
pub fn eat_sound(m: &Mob) -> &'static str {
|
||||
match (zombie(m), m.is_baby()) {
|
||||
(true, _) => "entity.zombie_nautilus.eat",
|
||||
(false, true) => "entity.baby_nautilus.eat",
|
||||
(false, false) => "entity.nautilus.eat",
|
||||
}
|
||||
}
|
||||
/// `getEquipSound(SADDLE)`.
|
||||
pub fn saddle_sound(m: &Mob) -> &'static str {
|
||||
if m.fluids.eye_in_water {
|
||||
"item.nautilus_saddle_underwater_equip"
|
||||
} else {
|
||||
"item.nautilus_saddle_equip"
|
||||
}
|
||||
}
|
||||
fn sound(m: &Mob, name: &'static str, events: &mut Vec<MobEvent>) {
|
||||
events.push(MobEvent::Sound(name, m.center(), 1.0, 1.0));
|
||||
}
|
||||
/// `AbstractNautilus.travelInWater`: its own speed, no fluid drag but 0.9.
|
||||
pub fn travel(m: &mut Mob, w: &MobWorld, input: Vec3, events: &mut Vec<MobEvent>) -> bool {
|
||||
if !m.fluids.in_water {
|
||||
return false;
|
||||
}
|
||||
let speed = m.ai.speed;
|
||||
m.move_relative(speed, input);
|
||||
m.do_move(w, events);
|
||||
m.velocity = Vec3::new(m.velocity.x * 0.9, m.velocity.y * 0.9, m.velocity.z * 0.9);
|
||||
true
|
||||
}
|
||||
/// `tickRidden` and `getRiddenInput`: turn half way to the rider, swim along
|
||||
/// their look, faster in water (`getRiddenSpeed`), and dash on the jump.
|
||||
pub fn ridden(m: &mut Mob) {
|
||||
let Some(r) = m.rider else { return };
|
||||
let diff = super::living::wrap(r.yaw - m.yaw);
|
||||
m.yaw += diff * 0.5;
|
||||
m.head_pitch = r.pitch * 0.5;
|
||||
m.body_yaw = m.yaw;
|
||||
m.head_yaw = m.yaw;
|
||||
m.ai.nav.stop();
|
||||
m.ai.mov.operation = Operation::Wait;
|
||||
let (mut forward, mut up) = (0.0, 0.0);
|
||||
if r.forward != 0.0 {
|
||||
let mut f = r.pitch.to_radians().cos();
|
||||
let mut u = -r.pitch.to_radians().sin();
|
||||
if r.forward < 0.0 {
|
||||
f *= -0.5;
|
||||
u *= -0.5;
|
||||
}
|
||||
forward = f;
|
||||
up = u;
|
||||
}
|
||||
let factor = if m.fluids.in_water { 0.0325 } else { 0.02 };
|
||||
m.ai.speed = factor * m.movement_speed() as f32;
|
||||
m.ai.xxa = r.strafe;
|
||||
m.ai.yya = up;
|
||||
m.ai.zza = forward;
|
||||
if r.jump > 0.0 {
|
||||
if m.extra.anim_ticks <= 0 && !m.extra.flag2 {
|
||||
dash(m, r.jump);
|
||||
}
|
||||
if let Some(rider) = m.rider.as_mut() {
|
||||
rider.jump = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `executeRidersJump` (with `handleStartJump`'s sound): along the rider's
|
||||
/// look, 1.2 in water and 0.5 on land.
|
||||
fn dash(m: &mut Mob, amount: f32) {
|
||||
let Some(r) = m.rider else { return };
|
||||
let (yaw, pitch) = (r.yaw.to_radians(), r.pitch.to_radians());
|
||||
let look = Vec3::new(
|
||||
f64::from(-yaw.sin() * pitch.cos()),
|
||||
f64::from(-pitch.sin()),
|
||||
f64::from(yaw.cos() * pitch.cos()),
|
||||
);
|
||||
let power = if m.fluids.in_water { 1.2 } else { 0.5 };
|
||||
let k = f64::from(power * amount) * m.movement_speed();
|
||||
m.velocity = Vec3::new(
|
||||
m.velocity.x + look.x * k,
|
||||
m.velocity.y + look.y * k,
|
||||
m.velocity.z + look.z * k,
|
||||
);
|
||||
m.extra.anim_ticks = DASH_COOLDOWN;
|
||||
m.extra.flag2 = true;
|
||||
// The sound plays on its next tick.
|
||||
m.extra.scratch[1] = 1;
|
||||
}
|
||||
/// `AbstractNautilus.tick` and the brains' memories: the rider's breath, the
|
||||
/// dash clock, bubbles, and choosing whom to charge at
|
||||
/// (`NautilusAi.findNearestValidAttackTarget`).
|
||||
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if m.extra.scratch[1] != 0 {
|
||||
m.extra.scratch[1] = 0;
|
||||
sound(m, dash_sound(m), events);
|
||||
}
|
||||
// applyEffects: the rider breathes under water.
|
||||
if m.rider.is_some() {
|
||||
if m.extra.ints[1] == 0 || w.game_time % 40 == 0 {
|
||||
m.extra.ints[1] = 1;
|
||||
events.push(MobEvent::EffectPlayer {
|
||||
effect: "minecraft:breath_of_the_nautilus",
|
||||
ticks: 60,
|
||||
amplifier: 0,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
m.extra.ints[1] = 0;
|
||||
}
|
||||
if m.extra.flag2 && m.extra.anim_ticks < 35 {
|
||||
m.extra.flag2 = false;
|
||||
}
|
||||
if m.extra.anim_ticks > 0 {
|
||||
m.extra.anim_ticks -= 1;
|
||||
if m.extra.anim_ticks == 0 {
|
||||
sound(m, dash_ready_sound(m), events);
|
||||
}
|
||||
}
|
||||
if m.fluids.in_water {
|
||||
bubbles(m, events);
|
||||
}
|
||||
// CountDownCooldownTicks and the ANGRY_AT expiry.
|
||||
if m.extra.counter > 0 {
|
||||
m.extra.counter -= 1;
|
||||
}
|
||||
if m.extra.counter2 > 0 {
|
||||
m.extra.counter2 -= 1;
|
||||
}
|
||||
if m.extra.anger > 0 {
|
||||
m.extra.anger -= 1;
|
||||
}
|
||||
if m.ai.target.is_none() && m.alive() && !m.no_ai {
|
||||
m.ai.target = find_target(m, w);
|
||||
}
|
||||
}
|
||||
/// `spawnBubbles`: more as it swims faster, from behind its mouth.
|
||||
fn bubbles(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
let v = m.velocity;
|
||||
let speed = (v.x * v.x + v.y * v.y + v.z * v.z).sqrt();
|
||||
let chance = (speed * 2.0).clamp(f64::from(0.15f32), 1.0);
|
||||
if f64::from(m.random.next_float()) >= chance {
|
||||
return;
|
||||
}
|
||||
let (yaw, pitch) = (
|
||||
m.yaw.to_radians(),
|
||||
m.head_pitch.clamp(-10.0, 10.0).to_radians(),
|
||||
);
|
||||
let dir = [
|
||||
f64::from(-yaw.sin() * pitch.cos()),
|
||||
f64::from(-pitch.sin()),
|
||||
f64::from(yaw.cos() * pitch.cos()),
|
||||
];
|
||||
let spread = m.random.next_double() * 0.8 * (1.0 + speed);
|
||||
for _ in 0..3 {
|
||||
let _ = (f64::from(m.random.next_float()) - 0.5) * spread;
|
||||
}
|
||||
events.push(MobEvent::Particles {
|
||||
kind: "bubble",
|
||||
at: [
|
||||
m.position.x - dir[0] * 1.1,
|
||||
m.position.y - dir[1] + 0.25,
|
||||
m.position.z - dir[2] * 1.1,
|
||||
],
|
||||
count: 1,
|
||||
});
|
||||
}
|
||||
fn in_water_at(w: &MobWorld, p: Vec3) -> bool {
|
||||
w.fluid(p.x.floor() as i32, p.y.floor() as i32, p.z.floor() as i32) == Fluid::Water
|
||||
}
|
||||
/// `NautilusAi.findNearestValidAttackTarget`: whoever it is angry at, else
|
||||
/// now and then (a coin flip every 2400 to 3600 ticks) the nearest pufferfish.
|
||||
fn find_target(m: &mut Mob, w: &MobWorld) -> Option<Who> {
|
||||
if m.extra.in_love > 0 || !m.fluids.in_water || m.is_baby() || m.extra.tame {
|
||||
return None;
|
||||
}
|
||||
if m.extra.anger > 0
|
||||
&& let Some(who) = m.ai.last_hurt_by
|
||||
&& let Some(t) = w.target_info(who)
|
||||
&& t.alive
|
||||
&& !(t.is_player && t.creative)
|
||||
&& in_water_at(w, t.position)
|
||||
{
|
||||
return Some(who);
|
||||
}
|
||||
if m.extra.counter > 0 {
|
||||
return None;
|
||||
}
|
||||
m.extra.counter = 2400 + m.random.next_int_bound(1201).unwrap_or(0);
|
||||
if m.random.next_float() < 0.5 {
|
||||
return None;
|
||||
}
|
||||
w.nearby(m.position, 16.0, |s| {
|
||||
s.species == Species::Pufferfish && in_water_at(w, s.position)
|
||||
})
|
||||
.next()
|
||||
.map(|s| Who::Mob(s.id))
|
||||
}
|
||||
/// `hurtServer`: `NautilusAi.setAngerTarget` for 400 ticks.
|
||||
pub fn after_hurt(m: &mut Mob, source: &super::Damage) {
|
||||
if source.attacker.is_some() {
|
||||
m.extra.anger = ANGER_DURATION + 1;
|
||||
}
|
||||
}
|
||||
/// `ChargeAttack(80, ..., speed, 2, 12, 11, dash)`: rush straight at the
|
||||
/// target and ram it once.
|
||||
#[derive(Clone, Debug)]
|
||||
struct Charge {
|
||||
speed: f64,
|
||||
start: Vec3,
|
||||
velocity: Vec3,
|
||||
}
|
||||
impl Charge {
|
||||
fn new(speed: f64) -> Self {
|
||||
Self {
|
||||
speed,
|
||||
start: Vec3::ZERO,
|
||||
velocity: Vec3::ZERO,
|
||||
}
|
||||
}
|
||||
fn still_ok(&self, m: &Mob, cx: &Cx) -> bool {
|
||||
let Some(t) = m.ai.target.and_then(|who| cx.w.target_info(who)) else {
|
||||
return false;
|
||||
};
|
||||
if !t.alive || t.is_player && t.creative || m.extra.tame || m.extra.counter2 > 0 {
|
||||
return false;
|
||||
}
|
||||
if m.position.distance_squared(self.start) >= 12.0 * 12.0
|
||||
|| t.position.distance_squared(m.position) >= 11.0 * 11.0
|
||||
{
|
||||
return false;
|
||||
}
|
||||
cx.w.line_of_sight(
|
||||
Vec3::new(m.position.x, m.eye_y(), m.position.z),
|
||||
Vec3::new(t.position.x, t.eye_y, t.position.z),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl Goal for Charge {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE | LOOK
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
m.ai.target.is_some() && m.extra.counter2 <= 0 && m.extra.in_love <= 0
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
self.still_ok(m, cx)
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
self.start = m.position;
|
||||
let Some(t) = m.ai.target.and_then(|who| cx.w.target_info(who)) else {
|
||||
return;
|
||||
};
|
||||
let d = Vec3::new(
|
||||
t.position.x - m.position.x,
|
||||
t.position.y - m.position.y,
|
||||
t.position.z - m.position.z,
|
||||
);
|
||||
let len = d.length();
|
||||
self.velocity = if len < 1.0e-4 {
|
||||
Vec3::ZERO
|
||||
} else {
|
||||
Vec3::new(
|
||||
d.x / len * self.speed,
|
||||
d.y / len * self.speed,
|
||||
d.z / len * self.speed,
|
||||
)
|
||||
};
|
||||
if self.still_ok(m, cx) {
|
||||
let name = if zombie(m) {
|
||||
"entity.zombie_nautilus.dash"
|
||||
} else {
|
||||
"entity.nautilus.dash"
|
||||
};
|
||||
sound(m, name, cx.events);
|
||||
}
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
m.extra.counter2 = TIME_BETWEEN_ATTACKS;
|
||||
m.ai.target = None;
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let Some(who) = m.ai.target else { return };
|
||||
let Some(t) = cx.w.target_info(who) else {
|
||||
return;
|
||||
};
|
||||
m.turn_to([t.position.x, t.eye_y, t.position.z], 360.0, 360.0);
|
||||
m.velocity = self.velocity;
|
||||
if !m.bounds().intersects(t.bounds) {
|
||||
return;
|
||||
}
|
||||
// dealDamageToTarget and dealKnockBack (causeExtraKnockback along its facing).
|
||||
let from = [m.position.x, m.position.y, m.position.z];
|
||||
let amount = m.attrs.attack_damage;
|
||||
cx.events.push(match who {
|
||||
Who::Player => MobEvent::AttackPlayer(amount, from),
|
||||
Who::Mob(id) => MobEvent::AttackMob {
|
||||
target: id,
|
||||
amount,
|
||||
source: super::Damage::mob(m.id, from),
|
||||
},
|
||||
});
|
||||
let level = |e: &str| {
|
||||
m.extra
|
||||
.effects
|
||||
.iter()
|
||||
.find(|x| x.0 == e)
|
||||
.map_or(0, |x| x.2 + 1)
|
||||
};
|
||||
let boost = 0.25 * (level("minecraft:speed") - level("minecraft:slowness")) as f32;
|
||||
let factor = (self.speed as f32 * m.movement_speed() as f32).clamp(0.2, 2.0) + boost;
|
||||
let power = f64::from(factor * 2.0);
|
||||
if power > 0.0 {
|
||||
let yaw = m.yaw.to_radians();
|
||||
cx.events.push(MobEvent::Push {
|
||||
target: who,
|
||||
velocity: [
|
||||
-f64::from(yaw.sin()) * power,
|
||||
0.0,
|
||||
f64::from(yaw.cos()) * power,
|
||||
],
|
||||
});
|
||||
m.velocity = Vec3::new(m.velocity.x * 0.6, m.velocity.y, m.velocity.z * 0.6);
|
||||
}
|
||||
m.ai.target = None;
|
||||
}
|
||||
}
|
||||
/// The body texture: the baby's, the adult's, or the zombie's variant.
|
||||
pub fn texture(m: &Mob) -> String {
|
||||
match (zombie(m), m.is_baby(), m.extra.variant) {
|
||||
(true, _, 1) => "entity/nautilus/zombie_nautilus_coral".into(),
|
||||
(true, _, _) => "entity/nautilus/zombie_nautilus".into(),
|
||||
(false, true, _) => "entity/nautilus/nautilus_baby".into(),
|
||||
(false, false, _) => "entity/nautilus/nautilus".into(),
|
||||
}
|
||||
}
|
||||
/// The body model: `ZombieNautilusRenderer` picks the coral model for the
|
||||
/// warm variant.
|
||||
pub fn model(m: &Mob) -> &'static str {
|
||||
match (zombie(m), m.is_baby(), m.extra.variant) {
|
||||
(true, _, 1) => "zombie_nautilus_coral#main",
|
||||
(true, _, _) => "zombie_nautilus#main",
|
||||
(false, true, _) if m.kind.layer("nautilus_baby#main").is_some() => "nautilus_baby#main",
|
||||
_ => "nautilus#main",
|
||||
}
|
||||
}
|
||||
/// The `NAUTILUS_BODY` equipment texture of a nautilus armour item.
|
||||
pub fn armor_texture(item: &str) -> Option<String> {
|
||||
let material = item
|
||||
.strip_prefix("minecraft:")?
|
||||
.strip_suffix("_nautilus_armor")?;
|
||||
let material = if material == "golden" {
|
||||
"gold"
|
||||
} else {
|
||||
material
|
||||
};
|
||||
Some(format!("entity/equipment/nautilus_body/{material}"))
|
||||
}
|
||||
/// `NautilusModel.setupAnim` (and `ZombieNautilusCoralModel`'s corals,
|
||||
/// hidden under armour).
|
||||
pub fn anim(m: &Mob, s: &State, p: &mut Poses, animations: &HashMap<String, Animation>) {
|
||||
let deg = (std::f64::consts::PI / 180.0) as f32;
|
||||
let y = s.y_rot.clamp(-10.0, 10.0);
|
||||
let x = s.x_rot.clamp(-10.0, 10.0);
|
||||
p.yrot("body", y * deg);
|
||||
p.xrot("body", x * deg);
|
||||
if let Some(a) = animations.get("NautilusAnimation.SWIMMING") {
|
||||
a.apply_walk(s.pos + s.age / 5.0, s.speed + 0.2, 2.0, 3.0, p);
|
||||
}
|
||||
if m.extra.head.is_some() {
|
||||
p.visible("corals", false);
|
||||
}
|
||||
}
|
||||
/// Saved fields: `TamableAnimal`'s owner, the saddle, the zombie's variant
|
||||
/// and the brain's attack cooldown.
|
||||
pub fn to_nbt(m: &Mob, map: &mut horizon_world::nbt::Compound) {
|
||||
use horizon_world::nbt::Tag;
|
||||
if let Some(owner) = m.extra.owner {
|
||||
map.insert("Owner".into(), Tag::IntArray(owner.to_vec()));
|
||||
} else {
|
||||
map.remove(&"Owner".into());
|
||||
}
|
||||
map.insert("Sitting".into(), Tag::Byte(0));
|
||||
// AgeableMob and Animal (a water creature is not saved with them above).
|
||||
map.insert("Age".into(), Tag::Int(m.extra.age));
|
||||
map.insert("AgeLocked".into(), Tag::Byte(i8::from(m.extra.age_locked)));
|
||||
map.insert("InLove".into(), Tag::Int(m.extra.in_love.max(0)));
|
||||
map.entry("ForcedAge".into()).or_insert(Tag::Int(0));
|
||||
if zombie(m) {
|
||||
let v = VARIANTS[usize::from(m.extra.variant).min(1)];
|
||||
map.insert(
|
||||
"variant".into(),
|
||||
Tag::String(format!("minecraft:{v}").as_str().into()),
|
||||
);
|
||||
}
|
||||
let mut equipment = match map.get(&"equipment".into()) {
|
||||
Some(Tag::Compound(c)) => c.clone(),
|
||||
_ => horizon_world::nbt::Compound::new(),
|
||||
};
|
||||
match m.saddle_item() {
|
||||
Some(saddle) => {
|
||||
equipment.insert("saddle".into(), crate::save::item_to_nbt(&saddle));
|
||||
}
|
||||
None => {
|
||||
equipment.remove(&"saddle".into());
|
||||
}
|
||||
}
|
||||
map.insert("equipment".into(), Tag::Compound(equipment));
|
||||
map.insert(
|
||||
"Brain".into(),
|
||||
Tag::compound([(
|
||||
"memories",
|
||||
Tag::compound([(
|
||||
"minecraft:attack_target_cooldown",
|
||||
Tag::compound([("value", Tag::Int(m.extra.counter))]),
|
||||
)]),
|
||||
)]),
|
||||
);
|
||||
}
|
||||
pub fn from_nbt(m: &mut Mob, tag: &horizon_world::nbt::Tag) {
|
||||
use horizon_world::nbt::Tag;
|
||||
let int = |k: &str| match tag.get(k) {
|
||||
Some(Tag::Int(v)) => Some(*v),
|
||||
Some(Tag::Byte(v)) => Some(i32::from(*v)),
|
||||
_ => None,
|
||||
};
|
||||
m.extra.age = int("Age").unwrap_or(0);
|
||||
m.extra.age_locked = int("AgeLocked").unwrap_or(0) != 0;
|
||||
m.extra.in_love = int("InLove").unwrap_or(0);
|
||||
m.extra.owner = crate::save::uuid_from_tag(tag.get("Owner"));
|
||||
m.extra.tame = m.extra.owner.is_some();
|
||||
if let Some(Tag::String(v)) = tag.get("variant") {
|
||||
let v = v.to_string().unwrap_or_default();
|
||||
m.extra.variant = u8::from(v.trim_start_matches("minecraft:") == "warm");
|
||||
}
|
||||
let saddle = tag
|
||||
.get("equipment")
|
||||
.and_then(|e| e.get("saddle"))
|
||||
.and_then(crate::save::item_from_nbt);
|
||||
m.set_saddle(saddle);
|
||||
if let Some(Tag::Int(v)) = tag
|
||||
.get("Brain")
|
||||
.and_then(|b| b.get("memories"))
|
||||
.and_then(|b| b.get("minecraft:attack_target_cooldown"))
|
||||
.and_then(|b| b.get("value"))
|
||||
{
|
||||
m.extra.counter = *v;
|
||||
}
|
||||
}
|
||||
@@ -137,6 +137,11 @@ pub fn body(m: &Mob) -> (String, String) {
|
||||
"entity/ghast/happy_ghast".into()
|
||||
},
|
||||
),
|
||||
S::Nautilus | S::ZombieNautilus => (
|
||||
super::nautilus::model(m).into(),
|
||||
super::nautilus::texture(m),
|
||||
),
|
||||
S::SulfurCube => super::sulfur_cube::body(m),
|
||||
S::Sniffer => (
|
||||
baby_or(m, "sniffer#main", "sniffer_baby#main"),
|
||||
if baby {
|
||||
@@ -396,7 +401,13 @@ pub fn layers(m: &Mob) -> Vec<Layer> {
|
||||
} else {
|
||||
white
|
||||
};
|
||||
push(&mut v, "horse_armor#main", &tex, color, false);
|
||||
// UndeadHorseRenderer bakes its own armour layer.
|
||||
let layer = if matches!(s, S::ZombieHorse | S::SkeletonHorse) {
|
||||
"undead_horse_armor#main"
|
||||
} else {
|
||||
"horse_armor#main"
|
||||
};
|
||||
push(&mut v, layer, &tex, color, false);
|
||||
}
|
||||
}
|
||||
// SimpleEquipmentLayer: pig and strider saddles.
|
||||
@@ -435,6 +446,32 @@ pub fn layers(m: &Mob) -> Vec<Layer> {
|
||||
push(&mut v, "iron_golem#main", texture, white, false);
|
||||
}
|
||||
}
|
||||
// NautilusRenderer: the armour and saddle SimpleEquipmentLayers.
|
||||
S::Nautilus | S::ZombieNautilus if !m.is_baby() => {
|
||||
if let Some(texture) = m
|
||||
.extra
|
||||
.head
|
||||
.as_deref()
|
||||
.and_then(super::nautilus::armor_texture)
|
||||
{
|
||||
push(&mut v, "nautilus_armor#main", &texture, white, false);
|
||||
}
|
||||
if m.extra.saddled {
|
||||
push(
|
||||
&mut v,
|
||||
"nautilus#saddle",
|
||||
"entity/equipment/nautilus_saddle/saddle",
|
||||
white,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
// SulfurCubeInnerLayer.
|
||||
S::SulfurCube => {
|
||||
if let Some((model, texture)) = super::sulfur_cube::inner(m) {
|
||||
push(&mut v, model, texture, white, false);
|
||||
}
|
||||
}
|
||||
// SlimeOuterLayer: the translucent outer cube.
|
||||
S::Slime => push(&mut v, "slime#outer", "entity/slime/slime", white, false),
|
||||
S::Sheep if !m.extra.sheared => {
|
||||
@@ -751,6 +788,7 @@ fn species_scale(m: &Mob, alpha: f32) -> glam::Mat4 {
|
||||
glam::Mat4::from_scale(glam::Vec3::new(xz, y, xz))
|
||||
}
|
||||
Species::Slime | Species::MagmaCube => super::cube::scale(m, alpha),
|
||||
Species::SulfurCube => super::sulfur_cube::scale(m, alpha),
|
||||
_ => glam::Mat4::IDENTITY,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ pub fn passenger_attachment(v: &Mob) -> [f64; 3] {
|
||||
Species::Mule => [0.0, 1.2125, 0.0],
|
||||
Species::SkeletonHorse | Species::ZombieHorse => [0.0, 1.31875, 0.0],
|
||||
Species::Pig => [0.0, 0.86875, 0.0],
|
||||
Species::Nautilus | Species::ZombieNautilus => [0.0, 1.1375, 0.0],
|
||||
// Camel.getPassengerAttachmentPoint for a lone standing driver.
|
||||
Species::Camel | Species::CamelHusk if !super::camel::sitting(v) => {
|
||||
[0.0, f64::from(v.height()) - 0.375, 0.5]
|
||||
}
|
||||
// The default attachments: the top of the bounding box.
|
||||
_ => [0.0, f64::from(v.height()), 0.0],
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ pub struct BiomeFacts {
|
||||
pub wolf: u8,
|
||||
/// `MoonBrightnessCheck(>= 0.9)`: the full moon.
|
||||
pub full_moon: bool,
|
||||
/// `spawns_coral_variant_zombie_nautilus` (the warm ocean).
|
||||
pub coral_nautilus: bool,
|
||||
}
|
||||
/// SpawnPlacementTypes for the species.
|
||||
pub fn placement_ok(species: Species, w: &MobWorld, x: i32, y: i32, z: i32) -> bool {
|
||||
@@ -173,7 +175,14 @@ pub fn spawn_rules_ok(
|
||||
{
|
||||
!w.block_name(x, y - 1, z).contains("nether_wart_block") || species == S::Ghast
|
||||
}
|
||||
S::Husk | S::Stray => dark_enough(w, random, x, y, z) && w.can_see_sky(x, y, z),
|
||||
// Monster.checkSurfaceMonstersSpawnRules.
|
||||
S::Husk | S::Stray | S::CamelHusk => {
|
||||
dark_enough(w, random, x, y, z) && w.can_see_sky(x, y, z)
|
||||
}
|
||||
// AbstractNautilus.checkNautilusSpawnRules.
|
||||
S::Nautilus => super::nautilus::spawn_rules_ok(w, x, y, z),
|
||||
// SulfurCube.checkSulfurCubeSpawnRules: anywhere it fits.
|
||||
S::SulfurCube => true,
|
||||
S::Drowned => w.fluid(x, y, z) == Fluid::Water && dark_enough(w, random, x, y, z),
|
||||
_ => {
|
||||
// Monster.checkMonsterSpawnRules
|
||||
@@ -367,7 +376,9 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts, difficulty: &LocalDifficulty) {
|
||||
}
|
||||
S::Llama | S::TraderLlama => super::llama::finalize(m),
|
||||
// Camel.finalizeSpawn: standing, with fixed attributes.
|
||||
S::Camel => super::camel::stand_up_instantly(m),
|
||||
S::Camel | S::CamelHusk => super::camel::stand_up_instantly(m),
|
||||
S::Nautilus | S::ZombieNautilus => super::nautilus::finalize(m, biome.coral_nautilus),
|
||||
S::SulfurCube => super::sulfur_cube::finalize(m),
|
||||
// Piglin.createSpawnWeapon: half crossbows, half golden swords, and
|
||||
// each piece of golden armour one time in ten.
|
||||
S::Piglin if !m.is_baby() => {
|
||||
|
||||
@@ -89,6 +89,10 @@ pub enum Species {
|
||||
HappyGhast,
|
||||
Warden,
|
||||
Creaking,
|
||||
CamelHusk,
|
||||
Nautilus,
|
||||
ZombieNautilus,
|
||||
SulfurCube,
|
||||
}
|
||||
/// Baby bounding boxes (each class's BABY_DIMENSIONS).
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -1238,6 +1242,60 @@ pub const ALL: &[Def] = &[
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
// After the camel: the camel husk reuses `camel#main`.
|
||||
def!(
|
||||
CamelHusk,
|
||||
"camel_husk",
|
||||
"camel#main",
|
||||
"entity/camel/camel_husk",
|
||||
A::Camel,
|
||||
[
|
||||
"entity.camel_husk.ambient",
|
||||
"entity.camel_husk.hurt",
|
||||
"entity.camel_husk.death"
|
||||
],
|
||||
Some("entity.camel_husk.step"),
|
||||
Baby::None
|
||||
),
|
||||
def!(
|
||||
Nautilus,
|
||||
"nautilus",
|
||||
"nautilus#main",
|
||||
"entity/nautilus/nautilus",
|
||||
A::Nautilus,
|
||||
[
|
||||
"entity.nautilus.ambient",
|
||||
"entity.nautilus.hurt",
|
||||
"entity.nautilus.death"
|
||||
],
|
||||
None,
|
||||
Baby::Scale(0.5, None)
|
||||
),
|
||||
def!(
|
||||
ZombieNautilus,
|
||||
"zombie_nautilus",
|
||||
"zombie_nautilus#main",
|
||||
"entity/nautilus/zombie_nautilus",
|
||||
A::Nautilus,
|
||||
[
|
||||
"entity.zombie_nautilus.ambient",
|
||||
"entity.zombie_nautilus.hurt",
|
||||
"entity.zombie_nautilus.death"
|
||||
],
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
// Babies are size 1 and adults size 2: the size scales the dimensions.
|
||||
def!(
|
||||
SulfurCube,
|
||||
"sulfur_cube",
|
||||
"sulfur_cube#main",
|
||||
"entity/sulfur_cube/sulfur_cube_outer",
|
||||
A::Slime,
|
||||
["", "entity.sulfur_cube.hurt", "entity.sulfur_cube.death"],
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
];
|
||||
pub fn def(s: Species) -> &'static Def {
|
||||
ALL.iter().find(|d| d.species == s).unwrap_or(&ALL[0])
|
||||
@@ -1260,7 +1318,7 @@ impl Def {
|
||||
Species::Sheep => &["sheep_baby"],
|
||||
Species::Chicken => &["chicken_baby", "cold_chicken"],
|
||||
Species::Rabbit => &["rabbit_baby"],
|
||||
Species::Horse => &["horse_baby"],
|
||||
Species::Horse => &["horse_baby", "horse_armor"],
|
||||
Species::Donkey => &["donkey_baby"],
|
||||
Species::Mule => &["mule_baby"],
|
||||
Species::Llama => &["llama_baby"],
|
||||
@@ -1269,12 +1327,14 @@ impl Def {
|
||||
Species::Panda => &["panda_baby"],
|
||||
Species::PolarBear => &["polar_bear_baby"],
|
||||
Species::Fox => &["fox_baby"],
|
||||
Species::Wolf => &["wolf_baby"],
|
||||
Species::Wolf => &["wolf_baby", "wolf_armor"],
|
||||
Species::Sniffer => &["sniffer_baby"],
|
||||
Species::HappyGhast => &[
|
||||
"happy_ghast_baby",
|
||||
"happy_ghast_harness",
|
||||
"happy_ghast_ropes",
|
||||
"happy_ghast_baby_harness",
|
||||
"happy_ghast_baby_ropes",
|
||||
],
|
||||
Species::Cat => &["cat_baby"],
|
||||
Species::Ocelot => &["ocelot_baby"],
|
||||
@@ -1303,8 +1363,12 @@ impl Def {
|
||||
Species::Zoglin => &["zoglin_baby"],
|
||||
Species::Strider => &["strider_baby"],
|
||||
Species::Camel => &["camel_baby"],
|
||||
Species::ZombieHorse => &["zombie_horse_baby"],
|
||||
Species::SkeletonHorse => &["skeleton_horse_baby"],
|
||||
Species::CamelHusk => &["camel_husk"],
|
||||
Species::Nautilus => &["nautilus_baby", "nautilus_armor"],
|
||||
Species::ZombieNautilus => &["zombie_nautilus_coral", "nautilus_armor", "nautilus"],
|
||||
Species::SulfurCube => &["sulfur_cube_small"],
|
||||
Species::ZombieHorse => &["zombie_horse_baby", "undead_horse_armor"],
|
||||
Species::SkeletonHorse => &["skeleton_horse_baby", "undead_horse_armor"],
|
||||
_ => &[],
|
||||
};
|
||||
v.extend_from_slice(extra);
|
||||
@@ -1330,6 +1394,8 @@ impl Def {
|
||||
| S::ZombifiedPiglin
|
||||
| S::Zoglin
|
||||
| S::Wither
|
||||
| S::CamelHusk
|
||||
| S::ZombieNautilus
|
||||
);
|
||||
let aquatic = matches!(
|
||||
s,
|
||||
@@ -1390,6 +1456,7 @@ impl Def {
|
||||
| S::Bogged
|
||||
| S::Parched
|
||||
| S::Phantom
|
||||
| S::ZombieNautilus
|
||||
),
|
||||
undead,
|
||||
breathes_water: aquatic
|
||||
@@ -1405,10 +1472,12 @@ impl Def {
|
||||
| S::SnowGolem
|
||||
| S::Ghast
|
||||
| S::Blaze
|
||||
| S::Nautilus
|
||||
),
|
||||
needs_water: aquatic,
|
||||
// Nautilus.handleAirSupply: it dries out on land.
|
||||
needs_water: aquatic || s == S::Nautilus,
|
||||
water_sensitive: matches!(s, S::Enderman | S::Blaze | S::SnowGolem),
|
||||
animal: !matches!(s, S::Bat)
|
||||
animal: !matches!(s, S::Bat | S::SulfurCube)
|
||||
&& !self.hostile_class()
|
||||
&& !aquatic
|
||||
&& !matches!(
|
||||
@@ -1474,6 +1543,9 @@ impl Def {
|
||||
S::Goat => "goat_food",
|
||||
S::Sniffer => "sniffer_food",
|
||||
S::HappyGhast => "happy_ghast_food",
|
||||
S::CamelHusk => "camel_husk_food",
|
||||
S::Nautilus | S::ZombieNautilus => "nautilus_food",
|
||||
S::SulfurCube => "sulfur_cube_food",
|
||||
S::Panda => "panda_food",
|
||||
S::Fox => "fox_food",
|
||||
S::Wolf => "wolf_food",
|
||||
@@ -1496,6 +1568,8 @@ impl Def {
|
||||
Species::Horse | Species::Donkey | Species::Mule => "horse_tempt_items",
|
||||
Species::Llama | Species::TraderLlama => "llama_tempt_items",
|
||||
Species::Strider => "strider_tempt_items",
|
||||
// An adult sulfur cube follows what it can swallow.
|
||||
Species::SulfurCube => "sulfur_cube_swallowable",
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -1528,7 +1602,7 @@ impl Def {
|
||||
pub fn max_head_x_rot(&self) -> f32 {
|
||||
match self.species {
|
||||
Species::Dolphin | Species::Axolotl => 1.0,
|
||||
Species::Slime | Species::MagmaCube => 0.0,
|
||||
Species::Slime | Species::MagmaCube | Species::SulfurCube => 0.0,
|
||||
_ => 40.0,
|
||||
}
|
||||
}
|
||||
@@ -1579,3 +1653,11 @@ impl Def {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Mobs whose `body` equipment slot Horizon keeps in `Extra::head` (a
|
||||
/// happy ghast's harness, nautilus armour, a sulfur cube's swallowed block).
|
||||
pub fn body_slot(s: Species) -> bool {
|
||||
matches!(
|
||||
s,
|
||||
Species::HappyGhast | Species::Nautilus | Species::ZombieNautilus | Species::SulfurCube
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,621 @@
|
||||
//! Sulfur cubes (`SulfurCube` on `AbstractCubeMob`): hopping like a slime
|
||||
//! but harmless, size 1 babies growing into size 2 adults, swallowing a
|
||||
//! block (by hand, from the ground or a dispenser) that stops it in place
|
||||
//! and gives it the block's archetype (`SulfurCubeArchetype`: buoyancy,
|
||||
//! knockback, sounds, contact damage, a TNT fuse), shearing the block out,
|
||||
//! buckets, and the outer/inner models and their render scale.
|
||||
use super::{
|
||||
Damage, DamageKind, Mob, MobEvent, MobWorld,
|
||||
control::MoveKind,
|
||||
goals::{Cx, Goal, JUMP, LOOK, MOVE, goal_clone},
|
||||
};
|
||||
use horizon_core::{geometry::Vec3, random::RandomSource};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
// Sulfur cube state (on top of `cube`'s `size`, `counter` jump delay,
|
||||
// `flag` aggressive, `flag2` was on ground, `vector[0]` direction):
|
||||
// `head` the swallowed block, `counter2` the fuse plus one (0 unprimed),
|
||||
// `ints[3]` the pickup timer, `scratch[1]` a fuse just lit (sound pending),
|
||||
// `scratch[2]` the push sound cooldown, `scratch[3]` from a bucket,
|
||||
// `point` the item it is after.
|
||||
pub const PICKUP_TIMER: i32 = 100;
|
||||
|
||||
/// One `SulfurCubeArchetype` (the parts Horizon's physics can use).
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Archetype {
|
||||
pub name: &'static str,
|
||||
pub buoyant: bool,
|
||||
/// `explosion`: fuse ticks, power, causes fire.
|
||||
pub explosion: Option<(i32, f32, bool)>,
|
||||
/// `contact_damage` amount (`sulfur_cube_hot`).
|
||||
pub contact_damage: Option<f32>,
|
||||
/// The knockback resistance modifier (the attribute clamps to 0..1).
|
||||
pub knockback_resistance: f64,
|
||||
pub horizontal_power: f32,
|
||||
pub vertical_power: f32,
|
||||
pub hit_sound: &'static str,
|
||||
pub push_sound: &'static str,
|
||||
pub push_cooldown: f32,
|
||||
pub push_threshold: f32,
|
||||
}
|
||||
macro_rules! arch {
|
||||
($n:literal, $b:expr, $e:expr, $c:expr, $k:expr, $h:expr, $v:expr, $cd:expr, $t:expr) => {
|
||||
Archetype {
|
||||
name: $n,
|
||||
buoyant: $b,
|
||||
explosion: $e,
|
||||
contact_damage: $c,
|
||||
knockback_resistance: $k,
|
||||
horizontal_power: $h,
|
||||
vertical_power: $v,
|
||||
hit_sound: concat!("entity.sulfur_cube.", $n, ".hit"),
|
||||
push_sound: concat!("entity.sulfur_cube.", $n, ".push"),
|
||||
push_cooldown: $cd,
|
||||
push_threshold: $t,
|
||||
}
|
||||
};
|
||||
}
|
||||
/// `data/minecraft/sulfur_cube_archetype/*.json`.
|
||||
pub const ARCHETYPES: [Archetype; 12] = [
|
||||
arch!("bouncy", true, None, None, -2.0, 0.4125, 0.105, 0.7, 0.3),
|
||||
arch!(
|
||||
"explosive",
|
||||
true,
|
||||
Some((120, 3.0, false)),
|
||||
None,
|
||||
-1.0,
|
||||
0.4125,
|
||||
0.09,
|
||||
0.7,
|
||||
0.1
|
||||
),
|
||||
arch!(
|
||||
"fast_flat",
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
-1.0,
|
||||
0.9125,
|
||||
0.09,
|
||||
0.9,
|
||||
0.03
|
||||
),
|
||||
arch!(
|
||||
"fast_sliding",
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
0.5,
|
||||
0.6625,
|
||||
0.09,
|
||||
1.0,
|
||||
0.05
|
||||
),
|
||||
arch!(
|
||||
"high_resistance",
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
0.7,
|
||||
0.4125,
|
||||
0.09,
|
||||
0.7,
|
||||
0.03
|
||||
),
|
||||
arch!("hot", true, None, Some(1.0), -1.0, 0.4125, 0.09, 0.7, 0.2),
|
||||
arch!("light", true, None, None, -1.0, 0.4125, 0.18, 0.7, 0.2),
|
||||
arch!("regular", true, None, None, -1.0, 0.4125, 0.09, 0.5, 0.2),
|
||||
arch!(
|
||||
"slow_bouncy",
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
0.4,
|
||||
0.4125,
|
||||
0.24,
|
||||
0.5,
|
||||
0.05
|
||||
),
|
||||
arch!(
|
||||
"slow_flat",
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
0.5,
|
||||
0.4125,
|
||||
0.105,
|
||||
0.9,
|
||||
0.03
|
||||
),
|
||||
arch!(
|
||||
"slow_sliding",
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
0.8,
|
||||
0.4125,
|
||||
0.09,
|
||||
1.0,
|
||||
0.02
|
||||
),
|
||||
arch!("sticky", false, None, None, -2.0, 0.4125, 0.09, 0.5, 0.05),
|
||||
];
|
||||
/// `SulfurCubeArchetype.DEFAULT_*`: no block swallowed.
|
||||
const DEFAULT_PUSH: (&str, f32, f32) = ("entity.sulfur_cube.regular.push", 0.5, 0.2);
|
||||
static ITEMS: OnceLock<Vec<HashSet<String>>> = OnceLock::new();
|
||||
/// The items of each archetype's `#sulfur_cube_archetype/<name>` tag.
|
||||
pub fn load_archetype_items(tags: &HashMap<String, HashSet<String>>) {
|
||||
let _ = ITEMS.set(
|
||||
ARCHETYPES
|
||||
.iter()
|
||||
.map(|a| {
|
||||
tags.get(&format!("minecraft:sulfur_cube_archetype/{}", a.name))
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
/// `matchingArchetypes`: the last one wins (as `collectEquipmentChanges`
|
||||
/// leaves it), buoyancy if any.
|
||||
pub fn archetype_of(item: &str) -> Option<&'static Archetype> {
|
||||
let items = ITEMS.get()?;
|
||||
ARCHETYPES
|
||||
.iter()
|
||||
.zip(items)
|
||||
.rev()
|
||||
.find(|(_, set)| set.contains(item))
|
||||
.map(|(a, _)| a)
|
||||
}
|
||||
/// `isSwallowableItem`: the `sulfur_cube_swallowable` tag.
|
||||
pub fn swallowable(m: &Mob, item: &str) -> bool {
|
||||
m.kind.tempt.iter().any(|t| t == item)
|
||||
}
|
||||
pub fn has_body(m: &Mob) -> bool {
|
||||
m.extra.head.is_some()
|
||||
}
|
||||
pub fn archetype(m: &Mob) -> Option<&'static Archetype> {
|
||||
m.extra.head.as_deref().and_then(archetype_of)
|
||||
}
|
||||
pub fn fuse(m: &Mob) -> i32 {
|
||||
m.extra.counter2 - 1
|
||||
}
|
||||
pub fn primed(m: &Mob) -> bool {
|
||||
fuse(m) >= 0
|
||||
}
|
||||
fn can_explode(m: &Mob) -> bool {
|
||||
archetype(m).is_some_and(|a| a.explosion.is_some()) && m.alive() && !primed(m)
|
||||
}
|
||||
pub fn register(m: &mut Mob) {
|
||||
use super::cube;
|
||||
m.ai.goals.add(1, cube::CubeFloat);
|
||||
m.ai.goals.add(2, SulfurTempt { player: None });
|
||||
m.ai.goals.add(3, SearchForItems);
|
||||
m.ai.goals.add(4, cube::CubeRandomDirection::default());
|
||||
m.ai.goals.add(5, cube::CubeKeepJumping);
|
||||
m.ai.mov.kind = MoveKind::Custom;
|
||||
m.ai.nav.can_float = true;
|
||||
m.extra.vector[0] = f64::from(180.0 * m.yaw / std::f32::consts::PI);
|
||||
// Created at size 1 (finalizeSpawn sizes it); not made a baby here.
|
||||
set_size(m, 1, false);
|
||||
m.health = m.attrs.max_health;
|
||||
}
|
||||
/// `setSize`: health 4 per size, speed 0.2 + 0.1 * size; size 1 makes an
|
||||
/// adult a baby.
|
||||
pub fn set_size(m: &mut Mob, size: i32, update_health: bool) {
|
||||
let size = size.clamp(1, 127);
|
||||
m.extra.size = size;
|
||||
m.attrs.max_health = (4 * size) as f32;
|
||||
m.attrs.speed = f64::from(0.2f32 + 0.1f32 * size as f32);
|
||||
if update_health {
|
||||
m.health = m.attrs.max_health;
|
||||
if size == 1 && !m.is_baby() {
|
||||
m.extra.age = -24000;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `setSpawnSize`: babies are size 1, adults size 2.
|
||||
pub fn finalize(m: &mut Mob) {
|
||||
let size = if m.is_baby() { 1 } else { 2 };
|
||||
set_size(m, size, true);
|
||||
}
|
||||
/// `getSplitCount`: two babies, none from a primed cube.
|
||||
pub fn split_count(m: &Mob) -> i32 {
|
||||
if primed(m) { 0 } else { 2 }
|
||||
}
|
||||
pub fn tiny(m: &Mob) -> bool {
|
||||
m.extra.size <= 1
|
||||
}
|
||||
pub fn jump_sound(m: &Mob) -> &'static str {
|
||||
if tiny(m) {
|
||||
"entity.small_sulfur_cube.jump"
|
||||
} else {
|
||||
"entity.sulfur_cube.jump"
|
||||
}
|
||||
}
|
||||
pub fn squish_sound(m: &Mob) -> &'static str {
|
||||
if tiny(m) {
|
||||
"entity.small_sulfur_cube.squish"
|
||||
} else if has_body(m) {
|
||||
"entity.sulfur_cube.bounce"
|
||||
} else {
|
||||
"entity.sulfur_cube.squish"
|
||||
}
|
||||
}
|
||||
/// The hurt and death sounds by size.
|
||||
pub fn sounds(m: &Mob) -> [&'static str; 3] {
|
||||
if tiny(m) {
|
||||
[
|
||||
"",
|
||||
"entity.small_sulfur_cube.hurt",
|
||||
"entity.small_sulfur_cube.death",
|
||||
]
|
||||
} else {
|
||||
["", "entity.sulfur_cube.hurt", "entity.sulfur_cube.death"]
|
||||
}
|
||||
}
|
||||
/// `primeTime`: light the fuse (short when an explosion did it).
|
||||
pub fn prime(m: &mut Mob, imminent: bool) -> bool {
|
||||
let Some((fuse, _, _)) = archetype(m).and_then(|a| a.explosion) else {
|
||||
return false;
|
||||
};
|
||||
if !m.alive() || primed(m) {
|
||||
return false;
|
||||
}
|
||||
let t = if imminent {
|
||||
m.random.next_int_bound((fuse / 4).max(1)).unwrap_or(0) + fuse / 8
|
||||
} else {
|
||||
fuse
|
||||
};
|
||||
m.invulnerable_flag = true;
|
||||
m.extra.counter2 = t + 1;
|
||||
m.extra.scratch[1] = 1;
|
||||
true
|
||||
}
|
||||
/// `hurtServer`: fire or explosions light an explosive cube; with a block
|
||||
/// it shrugs off blows, falls and explosions and is only knocked about.
|
||||
pub fn accepts_damage(m: &mut Mob, source: &Damage, amount: f32) -> bool {
|
||||
if !has_body(m) {
|
||||
return true;
|
||||
}
|
||||
if can_explode(m) && !primed(m) {
|
||||
if source.is_fire() {
|
||||
prime(m, false);
|
||||
} else if source.kind == DamageKind::Explosion {
|
||||
prime(m, true);
|
||||
}
|
||||
}
|
||||
let immune = matches!(
|
||||
source.kind,
|
||||
DamageKind::PlayerAttack
|
||||
| DamageKind::MobAttack
|
||||
| DamageKind::Arrow
|
||||
| DamageKind::Thrown
|
||||
| DamageKind::Explosion
|
||||
| DamageKind::Fall
|
||||
| DamageKind::Sting
|
||||
| DamageKind::Cactus
|
||||
);
|
||||
if immune {
|
||||
if let Some(from) = source.from {
|
||||
knockback(m, from, amount);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
/// `SulfurCube.knockback` with a block: the archetype's powers, turned by
|
||||
/// where the blow came from (the attacker taken to aim at its centre).
|
||||
pub fn knockback(m: &mut Mob, from: [f64; 3], damage: f32) -> bool {
|
||||
let Some(a) = archetype(m) else {
|
||||
return false;
|
||||
};
|
||||
let (h0, v0) = (a.horizontal_power, a.vertical_power);
|
||||
let (xd, zd) = (from[0] - m.position.x, from[2] - m.position.z);
|
||||
// applyVerticalPositionAnglePowerRotation from feet to feet.
|
||||
let d = [
|
||||
m.position.x - from[0],
|
||||
m.position.y - from[1],
|
||||
m.position.z - from[2],
|
||||
];
|
||||
let angle = (-d[1]).atan2((d[0] * d[0] + d[2] * d[2]).sqrt()) as f32;
|
||||
let rot = -angle * 0.8;
|
||||
let (s, c) = (rot.sin(), rot.cos());
|
||||
let (mut h, mut v) = (h0 * c - v0 * s, h0 * s + v0 * c);
|
||||
let hr = if h0 > 0.0 { h.abs() / h0 } else { 0.0 };
|
||||
let vr = if v0 > 0.0 { v.abs() / v0 } else { 0.0 };
|
||||
let max = hr.max(vr);
|
||||
if max > 1.0 {
|
||||
h /= max;
|
||||
v /= max;
|
||||
}
|
||||
let k = damage.sqrt();
|
||||
let resist = a.knockback_resistance.clamp(0.0, 1.0) as f32;
|
||||
h *= k * (1.0 - resist) * 0.4;
|
||||
v *= k * (1.0 - resist);
|
||||
let (h, v) = (h.clamp(-128.0, 128.0), v.clamp(-128.0, 128.0));
|
||||
let len = (xd * xd + zd * zd).sqrt().max(1.0e-4);
|
||||
m.velocity = Vec3::new(
|
||||
m.velocity.x - xd / len * f64::from(h),
|
||||
m.velocity.y + f64::from(v) * 1.2,
|
||||
m.velocity.z - zd / len * f64::from(h),
|
||||
);
|
||||
// The hit sound plays on the next tick (no event queue here).
|
||||
m.extra.scratch[1] = 2;
|
||||
true
|
||||
}
|
||||
/// `SulfurCube.tick` and `customServerAiStep` additions after the cube's
|
||||
/// own: the fuse, the timers, a swallowed block's stillness, buoyancy and
|
||||
/// facing, growing up, and players pushing it.
|
||||
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
match m.extra.scratch[1] {
|
||||
1 => events.push(MobEvent::Sound("entity.tnt.primed", m.center(), 1.0, 1.0)),
|
||||
2 => {
|
||||
if let Some(a) = archetype(m) {
|
||||
events.push(MobEvent::Sound(a.hit_sound, m.center(), 1.0, 1.0));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
m.extra.scratch[1] = 0;
|
||||
// tickFuse.
|
||||
if m.extra.counter2 > 1 {
|
||||
m.extra.counter2 -= 1;
|
||||
}
|
||||
if fuse(m) == 0
|
||||
&& let Some((_, power, _)) = archetype(m).and_then(|a| a.explosion)
|
||||
{
|
||||
events.push(MobEvent::Explode(
|
||||
[m.position.x, m.position.y + 0.0625, m.position.z],
|
||||
power,
|
||||
));
|
||||
m.removed = true;
|
||||
return;
|
||||
}
|
||||
if m.extra.ints[3] > 0 {
|
||||
m.extra.ints[3] -= 1;
|
||||
}
|
||||
if m.extra.scratch[2] > 0 {
|
||||
m.extra.scratch[2] -= 1;
|
||||
}
|
||||
// ageBoundaryReached: a grown baby is size 2 (and a baby made by
|
||||
// feeding, summoning or the egg is size 1, as `getBreedOffspring` makes it).
|
||||
if !m.is_baby() && m.extra.size == 1 && m.extra.age == 0 && m.age > 1 {
|
||||
set_size(m, 2, true);
|
||||
} else if m.is_baby() && m.extra.size > 1 {
|
||||
set_size(m, 1, true);
|
||||
}
|
||||
let body = has_body(m);
|
||||
// collectEquipmentChanges: a swallowed block takes every goal away.
|
||||
if body {
|
||||
m.ai.goals.disabled |= MOVE | LOOK | JUMP;
|
||||
m.ai.speed = 0.0;
|
||||
// SulfurCubeLookControl: square to the nearest quarter turn.
|
||||
let close = (m.yaw + 45.0).rem_euclid(90.0) - 45.0;
|
||||
m.yaw -= close;
|
||||
m.head_yaw = m.yaw;
|
||||
} else {
|
||||
m.ai.goals.disabled &= !(MOVE | LOOK | JUMP);
|
||||
}
|
||||
// travelInFluid: a buoyant block bobs up.
|
||||
if body && m.is_in_liquid() && archetype(m).is_some_and(|a| a.buoyant) {
|
||||
let vibe = 0.2 * (m.age as f32 * 0.4).sin();
|
||||
let height = if m.fluids.in_water {
|
||||
m.fluids.water
|
||||
} else {
|
||||
m.fluids.lava
|
||||
};
|
||||
let immersion = height - f64::from(m.height()) * 0.2 + f64::from(vibe);
|
||||
if immersion > 0.0 {
|
||||
m.velocity.y += immersion.min(1.0) * f64::from(0.04f32);
|
||||
}
|
||||
}
|
||||
if body && let Some(p) = &w.player {
|
||||
player_push(m, p, events);
|
||||
}
|
||||
}
|
||||
/// `playerTouch` / `playerPush`: a cube holding a block is shoved by a
|
||||
/// player walking into it (and burns them when hot).
|
||||
fn player_push(m: &mut Mob, p: &super::PlayerView, events: &mut Vec<MobEvent>) {
|
||||
if !p.alive || p.spectator {
|
||||
return;
|
||||
}
|
||||
let touch = p.bounds.inflate(Vec3::new(1.0, 0.5, 1.0));
|
||||
if !m.bounds().intersects(touch) {
|
||||
return;
|
||||
}
|
||||
let (dx, dz) = (m.position.x - p.position.x, m.position.z - p.position.z);
|
||||
let horizontal = (dx * dx + dz * dz).sqrt();
|
||||
let (bottom, top) = (m.position.y, m.position.y + f64::from(m.height()));
|
||||
let player_top = p.bounds.max_position().y;
|
||||
if !(horizontal < f64::from(1.3f32) && p.position.y <= top && player_top > bottom) {
|
||||
return;
|
||||
}
|
||||
let a = archetype(m);
|
||||
let kb = (1.0 - a.map_or(0.0, |a| a.knockback_resistance.clamp(0.0, 1.0))).max(0.0);
|
||||
let len = horizontal.max(1.0e-4);
|
||||
let speed = (p.velocity.length() * 2.0 * f64::from(0.3f32)).clamp(0.0, 0.5);
|
||||
let push = Vec3::new(
|
||||
dx / len * kb * speed,
|
||||
if m.on_ground {
|
||||
kb * f64::from(0.3f32) * speed
|
||||
} else {
|
||||
0.0
|
||||
},
|
||||
dz / len * kb * speed,
|
||||
);
|
||||
let (sound, cooldown, threshold) = a.map_or(DEFAULT_PUSH, |a| {
|
||||
(a.push_sound, a.push_cooldown, a.push_threshold)
|
||||
});
|
||||
if push.length_squared() > f64::from(threshold * threshold) && m.extra.scratch[2] <= 0 {
|
||||
m.extra.scratch[2] = (cooldown * 20.0) as i32;
|
||||
events.push(MobEvent::Sound(sound, m.center(), 1.0, 1.0));
|
||||
}
|
||||
m.velocity = m.velocity.add_vector(push);
|
||||
if let Some(amount) = a.and_then(|a| a.contact_damage) {
|
||||
events.push(MobEvent::DamagePlayer {
|
||||
amount,
|
||||
from: [m.position.x, m.position.y, m.position.z],
|
||||
kind: "minecraft:sulfur_cube_hot",
|
||||
});
|
||||
}
|
||||
}
|
||||
/// `SulfurCubeRenderer.scale` (after the cube's size and squish, flat when
|
||||
/// holding a block): the fuse swell, half size for an adult and the lift.
|
||||
pub fn scale(m: &Mob, alpha: f32) -> glam::Mat4 {
|
||||
let size = m.extra.size.max(1) as f32;
|
||||
let squish = if has_body(m) {
|
||||
0.0
|
||||
} else {
|
||||
m.anim.lerp(0, alpha) / (size * 0.5 + 1.0)
|
||||
};
|
||||
let w = 1.0 / (squish + 1.0);
|
||||
let mut t = glam::Mat4::from_scale(glam::Vec3::splat(0.999))
|
||||
* glam::Mat4::from_translation(glam::Vec3::new(0.0, 0.001, 0.0))
|
||||
* glam::Mat4::from_scale(glam::Vec3::new(w * size, 1.0 / w * size, w * size));
|
||||
let fuse = if primed(m) {
|
||||
fuse(m) as f32 - alpha + 1.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
if fuse < 10.0 && fuse > 0.0 {
|
||||
let g = (1.0 - fuse / 10.0).clamp(0.0, 1.0);
|
||||
let s = 1.0 + g * g * g * g * 0.3;
|
||||
t *= glam::Mat4::from_scale(glam::Vec3::splat(s));
|
||||
}
|
||||
let baby = m.is_baby();
|
||||
let (offset, down) = if baby { (1.24, 1.0) } else { (0.98, 0.5) };
|
||||
t * glam::Mat4::from_scale(glam::Vec3::splat(down))
|
||||
* glam::Mat4::from_translation(glam::Vec3::new(0.0, offset - 1.0 / 16.0, 0.0))
|
||||
}
|
||||
/// The outer body model and texture.
|
||||
pub fn body(m: &Mob) -> (String, String) {
|
||||
if m.is_baby() {
|
||||
(
|
||||
"sulfur_cube_small#main".into(),
|
||||
"entity/sulfur_cube/sulfur_cube_outer_small".into(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
"sulfur_cube#main".into(),
|
||||
"entity/sulfur_cube/sulfur_cube_outer".into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
/// `SulfurCubeInnerLayer`: the inner cube when no block is held.
|
||||
pub fn inner(m: &Mob) -> Option<(&'static str, &'static str)> {
|
||||
if has_body(m) {
|
||||
return None;
|
||||
}
|
||||
Some(if m.is_baby() {
|
||||
(
|
||||
"sulfur_cube_small#inner",
|
||||
"entity/sulfur_cube/sulfur_cube_inner_small",
|
||||
)
|
||||
} else {
|
||||
("sulfur_cube#inner", "entity/sulfur_cube/sulfur_cube_inner")
|
||||
})
|
||||
}
|
||||
/// `SulfurCubeTemptGoal` (`TemptGoal.ForNonPathfinders`): face a player
|
||||
/// holding slime balls (babies) or something to swallow (adults) and hop.
|
||||
#[derive(Clone, Debug)]
|
||||
struct SulfurTempt {
|
||||
player: Option<[f64; 3]>,
|
||||
}
|
||||
impl Goal for SulfurTempt {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
LOOK
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
let Some(p) = &cx.w.player else { return false };
|
||||
let wants = |i: &Option<std::sync::Arc<str>>| {
|
||||
i.as_deref().is_some_and(|i| {
|
||||
if m.is_baby() {
|
||||
m.kind.food.iter().any(|f| f == i)
|
||||
} else {
|
||||
swallowable(m, i)
|
||||
}
|
||||
})
|
||||
};
|
||||
// Attributes.TEMPT_RANGE 8.
|
||||
let ok = p.alive
|
||||
&& !p.spectator
|
||||
&& (wants(&p.main_hand) || wants(&p.off_hand))
|
||||
&& m.distance_sqr(p.position) <= 64.0;
|
||||
self.player = ok.then_some(p.eye);
|
||||
ok
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let Some(p) = &cx.w.player else { return };
|
||||
if m.distance_sqr(p.position) < 1.0 {
|
||||
super::cube::set_wanted(m, 0.0);
|
||||
return;
|
||||
}
|
||||
m.turn_to(p.eye, 10.0, 10.0);
|
||||
let yaw = m.yaw;
|
||||
super::cube::set_direction(m, yaw, true);
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
super::cube::set_wanted(m, 0.0);
|
||||
}
|
||||
}
|
||||
/// `SulfurCubeSearchForItemsGoal`: hop toward the nearest thing it could
|
||||
/// swallow (the game marks it in `point`).
|
||||
#[derive(Clone, Debug)]
|
||||
struct SearchForItems;
|
||||
impl Goal for SearchForItems {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
LOOK
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
!m.is_baby() && m.extra.ints[3] <= 0 && m.extra.point.is_some()
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
let Some(p) = m.extra.point else { return };
|
||||
m.turn_to(p, 10.0, 10.0);
|
||||
let yaw = m.yaw;
|
||||
super::cube::set_direction(m, yaw, true);
|
||||
}
|
||||
}
|
||||
/// `addAdditionalSaveData`: the cube's size, the timers and the fuse.
|
||||
pub fn to_nbt(m: &Mob, map: &mut horizon_world::nbt::Compound) {
|
||||
use horizon_world::nbt::Tag;
|
||||
map.insert("Size".into(), Tag::Int(m.extra.size.max(1) - 1));
|
||||
map.insert("wasOnGround".into(), Tag::Byte(i8::from(m.extra.flag2)));
|
||||
map.insert("pickup_timer".into(), Tag::Int(m.extra.ints[3]));
|
||||
map.insert(
|
||||
"from_bucket".into(),
|
||||
Tag::Byte(i8::from(m.extra.scratch[3] != 0)),
|
||||
);
|
||||
map.insert("fuse".into(), Tag::Int(fuse(m)));
|
||||
for (key, value) in [
|
||||
("Age", Tag::Int(m.extra.age)),
|
||||
("AgeLocked", Tag::Byte(i8::from(m.extra.age_locked))),
|
||||
] {
|
||||
map.insert(key.into(), value);
|
||||
}
|
||||
map.entry("ForcedAge".into()).or_insert(Tag::Int(0));
|
||||
}
|
||||
pub fn from_nbt(m: &mut Mob, tag: &horizon_world::nbt::Tag) {
|
||||
use horizon_world::nbt::Tag;
|
||||
let int = |k: &str| match tag.get(k) {
|
||||
Some(Tag::Int(v)) => Some(*v),
|
||||
Some(Tag::Byte(v)) => Some(i32::from(*v)),
|
||||
_ => None,
|
||||
};
|
||||
m.extra.age = int("Age").unwrap_or(0);
|
||||
m.extra.age_locked = int("AgeLocked").unwrap_or(0) != 0;
|
||||
let health = m.health;
|
||||
set_size(m, int("Size").unwrap_or(0) + 1, false);
|
||||
m.health = health;
|
||||
m.extra.flag2 = int("wasOnGround").unwrap_or(0) != 0;
|
||||
m.extra.ints[3] = int("pickup_timer").unwrap_or(0);
|
||||
m.extra.scratch[3] = int("from_bucket").unwrap_or(0);
|
||||
m.extra.counter2 = int("fuse").unwrap_or(-1).max(-1) + 1;
|
||||
if primed(m) {
|
||||
m.invulnerable_flag = true;
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,11 @@ except ImportError:
|
||||
import test_rust_parity as base
|
||||
|
||||
# Entity types that are not mobs (or are players): Horizon models them outside the mob table.
|
||||
# Horizon models these differently on purpose: slimes/magma cubes are created already sized (size 1,
|
||||
# Horizon models these differently on purpose: slimes/magma/sulfur cubes are created already sized (size 1,
|
||||
# vanilla applies setSize at spawn), and the phantom keeps its move control speed in attrs.speed.
|
||||
KNOWN = {('minecraft:slime', k) for k in ('max_health', 'movement_speed', 'attack_damage')} | \
|
||||
{('minecraft:magma_cube', k) for k in ('max_health', 'movement_speed', 'attack_damage')} | {('minecraft:phantom', 'movement_speed')}
|
||||
{('minecraft:magma_cube', k) for k in ('max_health', 'movement_speed', 'attack_damage')} | \
|
||||
{('minecraft:sulfur_cube', k) for k in ('max_health', 'movement_speed')} | {('minecraft:phantom', 'movement_speed')}
|
||||
|
||||
|
||||
def parse(path):
|
||||
|
||||
Reference in New Issue
Block a user