Turtles: a fixed home from spawn or load, one breeding orb
Turtle.finalizeSpawn sets homePos to where it spawns, and loading falls back to the block it stands on; the home no longer moves with a turtle that had none, which let it lay eggs anywhere. TurtleBreedGoal.breed adds one ExperienceOrb of 1 to 7 drawn from the mother's random. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -856,10 +856,14 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
if m.species() == crate::mobs::Species::Turtle {
|
||||
// Turtle.readAdditionalSaveData: `home_pos` (else where it stands) and `has_egg`.
|
||||
m.extra.flag = flag(tag, "has_egg");
|
||||
m.extra.home = match tag.get("home_pos") {
|
||||
Some(Tag::IntArray(home)) if home.len() == 3 => Some([home[0], home[1], home[2]]),
|
||||
_ => None,
|
||||
};
|
||||
m.extra.home = Some(match tag.get("home_pos") {
|
||||
Some(Tag::IntArray(home)) if home.len() == 3 => [home[0], home[1], home[2]],
|
||||
_ => [
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
],
|
||||
});
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Wither {
|
||||
m.extra.counter = number(tag.get("Invul")).unwrap_or(0) as i32;
|
||||
|
||||
@@ -1360,9 +1360,13 @@ impl Game<'_> {
|
||||
// TurtleBreedGoal.breed: the goal gave the mother her egg; only the
|
||||
// experience is left, and only with mob loot on.
|
||||
if p.species() == Species::Turtle {
|
||||
if self.ui.rules.bool("mob_drops") {
|
||||
let xp = 1 + self.world.random.next_int_bound(7).unwrap_or(0) as u32;
|
||||
self.spawn_orbs([p.position.x, p.position.y, p.position.z], xp);
|
||||
// One `new ExperienceOrb` of 1 to 7 from the mother's random (not
|
||||
// split up as `ExperienceOrb.award` does).
|
||||
if self.ui.rules.bool("mob_drops")
|
||||
&& let Some(m) = self.mobs.iter_mut().find(|m| m.id == parent)
|
||||
{
|
||||
let xp = 1 + m.random.next_int_bound(7).unwrap_or(0) as u32;
|
||||
self.add_orb([p.position.x, p.position.y, p.position.z], xp);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,6 +148,14 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts, difficulty: &LocalDifficulty) {
|
||||
S::Pig | S::Cow | S::Chicken => m.extra.variant = climate_index,
|
||||
S::Sheep => m.extra.color = super::farm::sheep_color(biome.climate, &mut m.random),
|
||||
S::Mooshroom => m.extra.variant = 0,
|
||||
// Turtle.finalizeSpawn: home is where it spawned.
|
||||
S::Turtle => {
|
||||
m.extra.home = Some([
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
])
|
||||
}
|
||||
S::Frog => m.extra.variant = biome.frog,
|
||||
S::Wolf => m.extra.variant = biome.wolf,
|
||||
S::Cat => m.extra.variant = super::tame::cat_variant(m, biome.full_moon),
|
||||
|
||||
@@ -23,8 +23,8 @@ fn set_laying_egg(m: &mut Mob, on: bool) {
|
||||
m.extra.counter = i32::from(on);
|
||||
m.extra.flag2 = on;
|
||||
}
|
||||
/// `homePos.closerToCenterThan(position, distance)`; a turtle that never
|
||||
/// had a home is at home where it stands.
|
||||
/// `homePos.closerToCenterThan(position, distance)`. Spawning, hatching and
|
||||
/// loading all set a home; one made any other way is at home where it stands.
|
||||
fn close_to_home(m: &Mob, distance: f64) -> bool {
|
||||
let home = m.extra.home.unwrap_or([
|
||||
m.position.x.floor() as i32,
|
||||
|
||||
Reference in New Issue
Block a user