Save the armadillo scute timer and reset it only when a scute can drop
This commit is contained in:
@@ -1097,6 +1097,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
block_tags: &items.block_tags,
|
||||
biomes: &biomes,
|
||||
mob_griefing: true,
|
||||
mob_drops: true,
|
||||
difficulty: LocalDifficulty::new(s.difficulty, world.day_time, 0, 0.0),
|
||||
end: false,
|
||||
world_seed: 0,
|
||||
|
||||
@@ -445,6 +445,10 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
map.insert("anger".into(), Tag::compound(Vec::<(&str, Tag)>::new()));
|
||||
}
|
||||
}
|
||||
// Armadillo.addAdditionalSaveData: the time left to the next scute.
|
||||
"minecraft:armadillo" => {
|
||||
map.insert("scute_time".into(), Tag::Int(m.extra.egg_time));
|
||||
}
|
||||
"minecraft:ravager" => {
|
||||
map.insert("AttackTick".into(), Tag::Int(m.extra.counter));
|
||||
map.insert("StunTick".into(), Tag::Int(m.extra.counter2));
|
||||
@@ -876,6 +880,12 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
st.vibration = crate::sculk::Data::from_nbt(listener);
|
||||
}
|
||||
}
|
||||
// Armadillo.readAdditionalSaveData: keeps the constructor's time when absent.
|
||||
if m.species() == crate::mobs::Species::Armadillo
|
||||
&& let Some(t) = number(tag.get("scute_time"))
|
||||
{
|
||||
m.extra.egg_time = t as i32;
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Ravager {
|
||||
m.extra.counter = number(tag.get("AttackTick")).unwrap_or(0) as i32;
|
||||
m.extra.counter2 = number(tag.get("StunTick")).unwrap_or(0) as i32;
|
||||
|
||||
@@ -416,6 +416,7 @@ impl Game<'_> {
|
||||
block_tags: &self.res.items().block_tags,
|
||||
biomes: self.res.biomes(),
|
||||
mob_griefing: self.ui.rules.bool("mob_griefing"),
|
||||
mob_drops: self.ui.rules.bool("mob_drops"),
|
||||
end: self.dim == Dim::End,
|
||||
world_seed: self.level.seed,
|
||||
sea_level: if self.dim == Dim::Nether { 32 } else { 63 },
|
||||
@@ -1222,22 +1223,20 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
MobEvent::ShedScute { mob, at, pitch } => {
|
||||
// shouldDropLoot: the `mob_drops` rule.
|
||||
if self.ui.rules.bool("mob_drops") {
|
||||
let table = "minecraft:gameplay/armadillo_shed";
|
||||
let drops = self.sequence_loot(table, table, None);
|
||||
for d in drops {
|
||||
self.spawn_at_location(Vec3::new(at[0], at[1], at[2]), 0.0, d);
|
||||
}
|
||||
self.audio.play(
|
||||
"minecraft:entity.armadillo.scute_drop",
|
||||
Some(at),
|
||||
1.0,
|
||||
pitch,
|
||||
);
|
||||
let ctx = self.who_context(Some(Who::Mob(mob)), None);
|
||||
self.post_game_event("minecraft:entity_place", at, ctx);
|
||||
// The mob already checked `shouldDropLoot` (a baby, `mob_drops`).
|
||||
let table = "minecraft:gameplay/armadillo_shed";
|
||||
let drops = self.sequence_loot(table, table, None);
|
||||
for d in drops {
|
||||
self.spawn_at_location(Vec3::new(at[0], at[1], at[2]), 0.0, d);
|
||||
}
|
||||
self.audio.play(
|
||||
"minecraft:entity.armadillo.scute_drop",
|
||||
Some(at),
|
||||
1.0,
|
||||
pitch,
|
||||
);
|
||||
let ctx = self.who_context(Some(Who::Mob(mob)), None);
|
||||
self.post_game_event("minecraft:entity_place", at, ctx);
|
||||
}
|
||||
MobEvent::GiftLoot { table, at } => {
|
||||
let drops =
|
||||
|
||||
@@ -1501,6 +1501,8 @@ pub struct MobWorld<'a> {
|
||||
pub biomes: &'a crate::biome::Biomes,
|
||||
/// The `mob_griefing` game rule.
|
||||
pub mob_griefing: bool,
|
||||
/// The `mob_drops` game rule (`shouldDropLoot`).
|
||||
pub mob_drops: bool,
|
||||
/// `getCurrentDifficultyAt` near the player.
|
||||
pub difficulty: spawning::LocalDifficulty,
|
||||
/// The End (its dimension type's monster spawn light rules).
|
||||
|
||||
@@ -938,26 +938,27 @@ fn server_ai_step(
|
||||
fn next_scute_time(m: &mut Mob) -> i32 {
|
||||
m.random.next_int_bound(20 * 60 * 5).unwrap_or(0) + 20 * 60 * 5
|
||||
}
|
||||
/// `Armadillo.customServerAiStep`: the scute timer. A baby only resets it
|
||||
/// (`shouldDropLoot`); the game checks the `mob_drops` rule.
|
||||
fn armadillo_server_ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
/// `Armadillo.customServerAiStep`: the scute timer keeps counting down and is
|
||||
/// only reset once `shouldDropLoot` (not a baby, `mob_drops` on) lets it shed.
|
||||
fn armadillo_server_ai_step(m: &mut Mob, mob_drops: bool, events: &mut Vec<MobEvent>) {
|
||||
if !m.alive() {
|
||||
return;
|
||||
}
|
||||
m.extra.egg_time -= 1;
|
||||
if m.alive() && m.extra.egg_time <= 0 {
|
||||
if !m.is_baby() {
|
||||
let pitch = (m.random.next_float() - m.random.next_float()) * 0.2 + 1.0;
|
||||
events.push(MobEvent::ShedScute {
|
||||
mob: m.id,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
pitch,
|
||||
});
|
||||
}
|
||||
if m.extra.egg_time <= 0 && !m.is_baby() && mob_drops {
|
||||
let pitch = (m.random.next_float() - m.random.next_float()) * 0.2 + 1.0;
|
||||
events.push(MobEvent::ShedScute {
|
||||
mob: m.id,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
pitch,
|
||||
});
|
||||
m.extra.egg_time = next_scute_time(m);
|
||||
}
|
||||
}
|
||||
fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
match m.species() {
|
||||
Species::Rabbit => super::rabbit::server_ai_step(m),
|
||||
Species::Armadillo => armadillo_server_ai_step(m, cx.events),
|
||||
Species::Armadillo => armadillo_server_ai_step(m, cx.w.mob_drops, cx.events),
|
||||
Species::Sheep => {}
|
||||
Species::Zombie
|
||||
| Species::Husk
|
||||
|
||||
Reference in New Issue
Block a user