Merge pull request #2201 from kacpherek/fix/raider-and-zombie-doors
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `BreakDoorGoal` (the difficulty gate, 240 ticks, the crack progress that your last commit now sends to nearby players) and the vindicators' door rules in raids. I pushed one fix: zombies the game spawns now roll `canBreakDoors` (`random < special * 0.1`), as `Zombie.finalizeSpawn` does. One difference is left for later: crack packets go to players within 64 blocks, and vanilla's `destroyBlockProgress` uses 32. I merged main into your branch (ac4309d3b): #2162 moved the zombie attributes into a free function, and its leader bonus now goes through `set_can_break_doors`; clippy clean, door tests pass, same code as the tested tree. Gate: this wave's 55 PRs merged on main in one tree: clippy `-D warnings` clean, 1186 horizon-client and 163 horizon-world tests pass, and of the 101 harnesses `parity.py --changed-files` picked, 100 pass (`block_removal` failed on one spawner case from #2199's orb merging, fixed there). `lan_e2e.py` passes 24 checks with the host on its server thread and in-frame (chest, xp, pvp, doors, villagers, beds, frames, projectiles, arrows, fishing, damage, mobs, blast, drops, elytra, breath, predict, cracks, barter, kills, hurt, contacts, underwater, plates), plus forced-levels on the server thread. Thanks @kacpherek!
This commit is contained in:
@@ -495,7 +495,6 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
"minecraft:zombie" => {
|
||||
map.insert("IsBaby".into(), Tag::Byte(i8::from(m.is_baby())));
|
||||
for (key, value) in [
|
||||
("CanBreakDoors", Tag::Byte(0)),
|
||||
("DrownedConversionTime", Tag::Int(-1)),
|
||||
("InWaterTime", Tag::Int(-1)),
|
||||
] {
|
||||
@@ -520,6 +519,13 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// Zombie.addAdditionalSaveData: CanBreakDoors.
|
||||
if crate::mobs::doors::is_zombie(m.species()) {
|
||||
map.insert(
|
||||
"CanBreakDoors".into(),
|
||||
Tag::Byte(i8::from(m.extra.can_break_doors)),
|
||||
);
|
||||
}
|
||||
crate::mobs::raider::write_nbt(m, map);
|
||||
crate::mobs::riders::write_nbt(m, map);
|
||||
// LivingEntity equipment: what the mob holds now.
|
||||
@@ -948,6 +954,10 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
if !crate::mobs::finalize::ageable(m.species()) && flag(tag, "IsBaby") {
|
||||
crate::mobs::finalize::set_baby(&mut m, true);
|
||||
}
|
||||
// Zombie.readAdditionalSaveData: setCanBreakDoors.
|
||||
if crate::mobs::doors::is_zombie(m.species()) {
|
||||
crate::mobs::doors::set_can_break_doors(&mut m, flag(tag, "CanBreakDoors"));
|
||||
}
|
||||
crate::mobs::raider::read_nbt(&mut m, tag);
|
||||
crate::mobs::riders::read_nbt(&mut m, tag);
|
||||
// A mob saved mid-death finishes dying; one saved dead is dropped.
|
||||
|
||||
@@ -2954,6 +2954,9 @@ impl Game<'_> {
|
||||
1501 => Some(("minecraft:block.lava.extinguish", 0.5)),
|
||||
1009 => Some(("minecraft:block.fire.extinguish", 0.5)),
|
||||
1502 => Some(("minecraft:block.redstone_torch.burnout", 0.5)),
|
||||
// LevelEvent.SOUND_ZOMBIE_WOODEN_DOOR (attack, break).
|
||||
1019 => Some(("minecraft:entity.zombie.attack_wooden_door", 2.0)),
|
||||
1021 => Some(("minecraft:entity.zombie.break_wooden_door", 2.0)),
|
||||
1030 => Some(("minecraft:block.anvil.use", 1.0)),
|
||||
1029 => Some(("minecraft:block.anvil.destroy", 1.0)),
|
||||
1031 => Some(("minecraft:block.anvil.land", 0.3)),
|
||||
@@ -2973,9 +2976,14 @@ impl Game<'_> {
|
||||
1029 | 1030 | 1042 | 1043 | 1044 => {
|
||||
self.world.random.next_float() * 0.1 + 0.9
|
||||
}
|
||||
1019 | 1021 => {
|
||||
(self.world.random.next_float() - self.world.random.next_float())
|
||||
* 0.2
|
||||
+ 1.0
|
||||
}
|
||||
_ => 1.0,
|
||||
};
|
||||
if matches!(id, 1029 | 1030) {
|
||||
if matches!(id, 1019 | 1021 | 1029 | 1030) {
|
||||
// Clients play the anvil sound from its level event;
|
||||
// capturing it also sends a duplicate sound packet.
|
||||
self.audio.play_unshared(name, c, volume, pitch);
|
||||
|
||||
@@ -1110,6 +1110,40 @@ impl Game<'_> {
|
||||
self.with_level(|b, level, ticks| b.set_door_open(level, ticks, pos, open));
|
||||
self.process_level_events()?;
|
||||
}
|
||||
MobEvent::BreakDoor { pos } => {
|
||||
// BreakDoorGoal.tick: removeBlock, then level events 1021
|
||||
// and 2001 with the state that is there now.
|
||||
let air = self.world.air;
|
||||
let at = BlockPos::new(pos[0], pos[1], pos[2]);
|
||||
self.with_level(|b, level, ticks| b.set_block(level, ticks, at, air, 3));
|
||||
self.process_level_events()?;
|
||||
self.level_event_at(1021, pos, 0);
|
||||
let left = self.world.block(pos[0], pos[1], pos[2]);
|
||||
self.level_event_at(2001, pos, left.0 as i32);
|
||||
}
|
||||
MobEvent::DestroyProgress { mob, pos, progress } => {
|
||||
self.destroy_block_progress(mob as i32, pos, progress);
|
||||
// ServerLevel.destroyBlockProgress: every player nearby sees it.
|
||||
if let Some(host) = self.lan.as_ref() {
|
||||
host.hub.broadcast_near(
|
||||
[f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])],
|
||||
64.0,
|
||||
&horizon_protocol::packets::play::Clientbound::BlockDestruction(
|
||||
horizon_protocol::packets::play::BlockDestruction {
|
||||
id: mob as i32,
|
||||
pos,
|
||||
progress: if (0..10).contains(&progress) {
|
||||
progress as u8
|
||||
} else {
|
||||
255
|
||||
},
|
||||
},
|
||||
),
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
MobEvent::LevelEvent { id, pos, data } => self.level_event_at(id, pos, data),
|
||||
MobEvent::SetBlockName { pos, name, effect } => {
|
||||
if effect {
|
||||
let old = self.world.block(pos[0], pos[1], pos[2]);
|
||||
|
||||
@@ -796,6 +796,8 @@ impl Game<'_> {
|
||||
let s = m.extra.raider.get_or_insert_with(Box::default);
|
||||
s.rider = has_rider;
|
||||
s.in_village = in_village;
|
||||
// Vindicator.customServerAiStep: `ServerLevel.isRaided`.
|
||||
s.raided = species == Species::Vindicator && raids.nearby(block).is_some();
|
||||
if s.raid_id.is_some_and(|id| raids.get(id).is_none()) {
|
||||
s.raid_id = None;
|
||||
s.ticks_outside_raid = 0;
|
||||
|
||||
@@ -25,6 +25,7 @@ pub mod creaking;
|
||||
pub mod creaking_heart;
|
||||
pub mod cube;
|
||||
pub mod data;
|
||||
pub mod doors;
|
||||
pub mod drops;
|
||||
pub mod enderman;
|
||||
pub mod equine;
|
||||
@@ -1019,6 +1020,24 @@ pub enum MobEvent {
|
||||
pos: [i32; 3],
|
||||
open: bool,
|
||||
},
|
||||
/// `BreakDoorGoal.tick` at its end: the door is removed (`removeBlock`),
|
||||
/// then level events 1021 and 2001 with the state that is left there.
|
||||
BreakDoor {
|
||||
pos: [i32; 3],
|
||||
},
|
||||
/// `Level.destroyBlockProgress` for a mob's crack on a block (`-1`
|
||||
/// clears it).
|
||||
DestroyProgress {
|
||||
mob: u32,
|
||||
pos: [i32; 3],
|
||||
progress: i32,
|
||||
},
|
||||
/// `Level.levelEvent`: the game plays and sends the event.
|
||||
LevelEvent {
|
||||
id: i32,
|
||||
pos: [i32; 3],
|
||||
data: i32,
|
||||
},
|
||||
/// Destroy a block, dropping nothing (sheep eating grass becomes dirt via SetBlock).
|
||||
BreakBlock {
|
||||
pos: [i32; 3],
|
||||
|
||||
@@ -944,6 +944,7 @@ fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
| Species::Parched
|
||||
| Species::WitherSkeleton
|
||||
| Species::ZombifiedPiglin => undead::custom_server_ai_step(m, cx),
|
||||
Species::Vindicator => super::illager::vindicator_server_ai_step(m),
|
||||
Species::Enderman => super::enderman::custom_server_ai_step(m, cx),
|
||||
Species::Blaze => super::nether::blaze_server_ai_step(m, cx),
|
||||
Species::ElderGuardian => super::guardian::elder_server_ai_step(m, cx),
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
//! Doors a mob gets through on its own: `DoorInteractGoal` with its two
|
||||
//! users, `BreakDoorGoal` (zombies that can break doors, vindicators in a
|
||||
//! raid) and `OpenDoorGoal` (`AbstractIllager.RaiderOpenDoorGoal`).
|
||||
use super::{
|
||||
Mob, MobEvent, MobWorld, Species,
|
||||
goals::{Cx, Goal, MOVE, goal_clone, reduced},
|
||||
nav::NavKind,
|
||||
raider,
|
||||
};
|
||||
use horizon_core::{geometry::Vec3, random::RandomSource};
|
||||
|
||||
/// `DefaultDoorBreakTime`: `BreakDoorGoal.getDoorBreakTime` is
|
||||
/// `max(240, doorBreakTime)`, and the vindicator's 6 is below it.
|
||||
const DOOR_BREAK_TIME: i32 = 240;
|
||||
|
||||
/// `GoalUtils.hasGroundPathNavigation`: ground, wall-climbing and
|
||||
/// amphibious navigations walk.
|
||||
pub fn can_navigate_ground(m: &Mob) -> bool {
|
||||
matches!(
|
||||
m.ai.nav.kind,
|
||||
NavKind::Ground | NavKind::WallClimber | NavKind::Amphibious
|
||||
)
|
||||
}
|
||||
/// `Zombie.setCanBreakDoors`: only a mob that walks can break doors, and
|
||||
/// then its navigation opens them.
|
||||
pub fn set_can_break_doors(m: &mut Mob, can_break: bool) {
|
||||
let can_break = can_break && can_navigate_ground(m);
|
||||
m.extra.can_break_doors = can_break;
|
||||
m.ai.nav.can_open_doors = can_break;
|
||||
}
|
||||
/// The species that extend `Zombie` (`CanBreakDoors` is theirs to save).
|
||||
pub fn is_zombie(s: Species) -> bool {
|
||||
matches!(
|
||||
s,
|
||||
Species::Zombie
|
||||
| Species::Husk
|
||||
| Species::Drowned
|
||||
| Species::ZombieVillager
|
||||
| Species::ZombifiedPiglin
|
||||
)
|
||||
}
|
||||
/// `DoorBlock.isWoodenDoor`: a door a hand opens, which is any but iron.
|
||||
fn wooden_door(w: &MobWorld, p: [i32; 3]) -> bool {
|
||||
let name = w.block_name(p[0], p[1], p[2]);
|
||||
name.ends_with("_door") && name != "minecraft:iron_door"
|
||||
}
|
||||
/// `DoorInteractGoal`'s door: where it is and whether one is there.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct Interact {
|
||||
door: [i32; 3],
|
||||
has_door: bool,
|
||||
}
|
||||
impl Interact {
|
||||
/// `DoorInteractGoal.canUse`: the mob bumped into something and a
|
||||
/// wooden door is on its path within 1.5 blocks, or at its own head.
|
||||
fn can_use(&mut self, m: &Mob, w: &MobWorld) -> bool {
|
||||
if !can_navigate_ground(m) || !m.horizontal_collision {
|
||||
return false;
|
||||
}
|
||||
let Some(path) = m.ai.nav.path.as_ref().filter(|p| !p.is_done()) else {
|
||||
return false;
|
||||
};
|
||||
for node in path
|
||||
.nodes
|
||||
.iter()
|
||||
.take((path.next + 2).min(path.nodes.len()))
|
||||
{
|
||||
self.door = [node.x, node.y + 1, node.z];
|
||||
let dx = m.position.x - f64::from(node.x);
|
||||
let dz = m.position.z - f64::from(node.z);
|
||||
if dx * dx + dz * dz <= 2.25 {
|
||||
self.has_door = wooden_door(w, self.door);
|
||||
if self.has_door {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
let at = m.position;
|
||||
self.door = [
|
||||
at.x.floor() as i32,
|
||||
at.y.floor() as i32 + 1,
|
||||
at.z.floor() as i32,
|
||||
];
|
||||
self.has_door = wooden_door(w, self.door);
|
||||
self.has_door
|
||||
}
|
||||
/// `DoorInteractGoal.isOpen`: the door is still there and open.
|
||||
fn is_open(&mut self, w: &MobWorld) -> bool {
|
||||
if !self.has_door {
|
||||
return false;
|
||||
}
|
||||
let d = self.door;
|
||||
if !w.block_name(d[0], d[1], d[2]).ends_with("_door") {
|
||||
self.has_door = false;
|
||||
return false;
|
||||
}
|
||||
w.prop(d[0], d[1], d[2], "open") == Some("true")
|
||||
}
|
||||
/// `DoorInteractGoal.setOpen`.
|
||||
fn set_open(&self, cx: &mut Cx, open: bool) {
|
||||
let d = self.door;
|
||||
if self.has_door && cx.w.block_name(d[0], d[1], d[2]).ends_with("_door") {
|
||||
cx.events.push(MobEvent::SetDoorOpen { pos: d, open });
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `BlockPos.closerToCenterThan`.
|
||||
fn closer_to_center(p: [i32; 3], at: Vec3, distance: f64) -> bool {
|
||||
Vec3::new(
|
||||
f64::from(p[0]) + 0.5,
|
||||
f64::from(p[1]) + 0.5,
|
||||
f64::from(p[2]) + 0.5,
|
||||
)
|
||||
.distance_squared(at)
|
||||
< distance * distance
|
||||
}
|
||||
|
||||
/// `BreakDoorGoal`: crack the door in the way for 240 ticks, then remove it.
|
||||
/// A zombie does it on hard only; `Vindicator.VindicatorBreakDoorGoal` on
|
||||
/// normal and hard, in a raid, and holds the mob's movement.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BreakDoor {
|
||||
interact: Interact,
|
||||
vindicator: bool,
|
||||
break_time: i32,
|
||||
last_break_progress: i32,
|
||||
}
|
||||
impl BreakDoor {
|
||||
/// `Zombie.breakDoorGoal`, added when the zombie can break doors.
|
||||
pub fn zombie() -> Self {
|
||||
Self::new(false)
|
||||
}
|
||||
/// `Vindicator.VindicatorBreakDoorGoal`.
|
||||
pub fn vindicator() -> Self {
|
||||
Self::new(true)
|
||||
}
|
||||
fn new(vindicator: bool) -> Self {
|
||||
Self {
|
||||
interact: Interact::default(),
|
||||
vindicator,
|
||||
break_time: 0,
|
||||
last_break_progress: -1,
|
||||
}
|
||||
}
|
||||
/// `DOOR_BREAKING_PREDICATE`.
|
||||
fn valid_difficulty(&self, w: &MobWorld) -> bool {
|
||||
if self.vindicator {
|
||||
w.difficulty.normal || w.difficulty.hard
|
||||
} else {
|
||||
w.difficulty.hard
|
||||
}
|
||||
}
|
||||
/// `BreakDoorGoal.canUse` after `DoorInteractGoal.canUse`.
|
||||
fn can_break(&mut self, m: &Mob, w: &MobWorld) -> bool {
|
||||
self.interact.can_use(m, w)
|
||||
&& w.mob_griefing
|
||||
&& self.valid_difficulty(w)
|
||||
&& !self.interact.is_open(w)
|
||||
}
|
||||
}
|
||||
impl Goal for BreakDoor {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
if self.vindicator { MOVE } else { 0 }
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
if self.vindicator {
|
||||
return raider::has_active_raid(m)
|
||||
&& m.random.next_int_bound(reduced(10)).unwrap_or(1) == 0
|
||||
&& self.can_break(m, cx.w);
|
||||
}
|
||||
m.extra.can_break_doors && self.can_break(m, cx.w)
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
(!self.vindicator || raider::has_active_raid(m))
|
||||
&& self.break_time <= DOOR_BREAK_TIME
|
||||
&& !self.interact.is_open(cx.w)
|
||||
&& closer_to_center(self.interact.door, m.position, 2.0)
|
||||
&& self.valid_difficulty(cx.w)
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, _cx: &mut Cx) {
|
||||
self.break_time = 0;
|
||||
if self.vindicator {
|
||||
m.ai.no_action_time = 0;
|
||||
}
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
cx.events.push(MobEvent::DestroyProgress {
|
||||
mob: m.id,
|
||||
pos: self.interact.door,
|
||||
progress: -1,
|
||||
});
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let door = self.interact.door;
|
||||
if m.random.next_int_bound(20).unwrap_or(1) == 0 {
|
||||
cx.events.push(MobEvent::LevelEvent {
|
||||
id: 1019,
|
||||
pos: door,
|
||||
data: 0,
|
||||
});
|
||||
if !m.ai.swinging {
|
||||
m.swing();
|
||||
}
|
||||
}
|
||||
self.break_time += 1;
|
||||
let progress = (self.break_time as f32 / DOOR_BREAK_TIME as f32 * 10.0) as i32;
|
||||
if progress != self.last_break_progress {
|
||||
cx.events.push(MobEvent::DestroyProgress {
|
||||
mob: m.id,
|
||||
pos: door,
|
||||
progress,
|
||||
});
|
||||
self.last_break_progress = progress;
|
||||
}
|
||||
if self.break_time == DOOR_BREAK_TIME && self.valid_difficulty(cx.w) {
|
||||
cx.events.push(MobEvent::BreakDoor { pos: door });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `AbstractIllager.RaiderOpenDoorGoal` (`OpenDoorGoal` that does not wait
|
||||
/// to close): open the door in the way during a raid. It never continues, so
|
||||
/// it closes the door again as soon as it stops.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct RaiderOpenDoor {
|
||||
interact: Interact,
|
||||
}
|
||||
impl Goal for RaiderOpenDoor {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
0
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
self.interact.can_use(m, cx.w) && raider::has_active_raid(m)
|
||||
}
|
||||
fn can_continue(&mut self, _m: &mut Mob, _cx: &mut Cx) -> bool {
|
||||
false
|
||||
}
|
||||
fn start(&mut self, _m: &mut Mob, cx: &mut Cx) {
|
||||
self.interact.set_open(cx, true);
|
||||
}
|
||||
fn stop(&mut self, _m: &mut Mob, cx: &mut Cx) {
|
||||
self.interact.set_open(cx, false);
|
||||
}
|
||||
}
|
||||
@@ -663,7 +663,7 @@ pub fn zombie_attributes(m: &mut Mob, special: f32, reason: Reason) {
|
||||
) {
|
||||
m.health = max_health(m);
|
||||
}
|
||||
m.extra.can_break_doors = true;
|
||||
super::doors::set_can_break_doors(m, true);
|
||||
}
|
||||
}
|
||||
pub fn max_health(m: &Mob) -> f32 {
|
||||
@@ -1213,7 +1213,8 @@ impl<L: FinalizeLevel + ?Sized, R: RandomSource> Ctx<'_, L, R> {
|
||||
}
|
||||
}
|
||||
}
|
||||
m.extra.can_break_doors = self.float() < special * 0.1;
|
||||
let can_break_doors = self.float() < special * 0.1;
|
||||
super::doors::set_can_break_doors(m, can_break_doors);
|
||||
if reason != Reason::Conversion {
|
||||
self.populate(m);
|
||||
self.enchant(m);
|
||||
|
||||
@@ -72,6 +72,8 @@ pub fn register_vindicator(m: &mut Mob) {
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(0, Float);
|
||||
g.add(1, avoid_creaking(1.0, 1.2));
|
||||
g.add(2, super::doors::BreakDoor::vindicator());
|
||||
g.add(3, super::doors::RaiderOpenDoor::default());
|
||||
g.add(4, super::raider::HoldGroundAttack::new(10.0));
|
||||
g.add(5, MeleeAttack::new(1.0, false));
|
||||
g.add(8, Stroll::new(0.6));
|
||||
@@ -86,6 +88,13 @@ pub fn register_vindicator(m: &mut Mob) {
|
||||
.when(|m, _| m.custom_name.as_deref() == Some("Johnny")),
|
||||
);
|
||||
}
|
||||
/// `Vindicator.customServerAiStep`: its navigation opens doors while a raid
|
||||
/// is at its position.
|
||||
pub fn vindicator_server_ai_step(m: &mut Mob) {
|
||||
if super::doors::can_navigate_ground(m) {
|
||||
m.ai.nav.can_open_doors = super::raider::state(m).is_some_and(|s| s.raided);
|
||||
}
|
||||
}
|
||||
// Evoker state: `counter` spellCastingTickCount, `variant2` the spell
|
||||
// being cast (0 none, 1 vexes, 2 fangs, 3 wololo), `counter2` the wololo
|
||||
// sheep's id.
|
||||
|
||||
@@ -30,6 +30,9 @@ pub struct State {
|
||||
pub celebrating: bool,
|
||||
/// The raid is active (`hasActiveRaid`); set by the game every tick.
|
||||
pub active_raid: bool,
|
||||
/// A raid is active within 96 blocks (`ServerLevel.isRaided`); set by
|
||||
/// the game every tick for vindicators.
|
||||
pub raided: bool,
|
||||
/// The raid is won or lost (`Raid.isOver`), lost (`isLoss`).
|
||||
pub raid_over: bool,
|
||||
pub raid_loss: bool,
|
||||
|
||||
@@ -35,6 +35,8 @@ pub fn placement_ok(species: Species, w: &MobWorld, x: i32, y: i32, z: i32) -> b
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct LocalDifficulty {
|
||||
pub effective: f32,
|
||||
/// The world difficulty is normal.
|
||||
pub normal: bool,
|
||||
/// The world difficulty is hard.
|
||||
pub hard: bool,
|
||||
}
|
||||
@@ -45,9 +47,11 @@ impl LocalDifficulty {
|
||||
/// the overworld clock, the chunk's inhabited time and the moon.
|
||||
pub fn new(base: u8, total: i64, inhabited: i64, moon: f32) -> Self {
|
||||
let hard = base == 3;
|
||||
let normal = base == 2;
|
||||
if base == 0 {
|
||||
return Self {
|
||||
effective: 0.0,
|
||||
normal,
|
||||
hard,
|
||||
};
|
||||
}
|
||||
@@ -60,6 +64,7 @@ impl LocalDifficulty {
|
||||
}
|
||||
Self {
|
||||
effective: f32::from(base) * (0.75 + global + local),
|
||||
normal,
|
||||
hard,
|
||||
}
|
||||
}
|
||||
@@ -158,6 +163,9 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts, difficulty: &LocalDifficulty) {
|
||||
if m.random.next_float() < 0.05 {
|
||||
m.extra.age = i32::MIN / 2;
|
||||
}
|
||||
// setCanBreakDoors(nextFloat() < special * 0.1), before the gear.
|
||||
let can_break_doors = m.random.next_float() < difficulty.special() * 0.1;
|
||||
super::doors::set_can_break_doors(m, can_break_doors);
|
||||
if m.species() != S::Drowned {
|
||||
populate_armor(m, difficulty);
|
||||
}
|
||||
@@ -191,6 +199,9 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts, difficulty: &LocalDifficulty) {
|
||||
// ZombifiedPiglin.populateDefaultEquipmentSlots: a golden sword, or
|
||||
// one time in 20 a golden spear.
|
||||
S::ZombifiedPiglin => {
|
||||
// Zombie.finalizeSpawn's setCanBreakDoors.
|
||||
let can_break_doors = m.random.next_float() < difficulty.special() * 0.1;
|
||||
super::doors::set_can_break_doors(m, can_break_doors);
|
||||
let spear = m.random.next_int_bound(20).unwrap_or(1) == 0;
|
||||
m.extra.main_hand = Some(
|
||||
if spear {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//! stray, bogged, wither skeleton): goals, bow attacks, water conversion.
|
||||
use super::{
|
||||
Damage, Mob, MobEvent, Species, Who,
|
||||
doors::BreakDoor,
|
||||
goals::{
|
||||
Avoid, AvoidEntity, Cx, FleeSun, Goal, HurtByTarget, LOOK, LookAtPlayer, MOVE, MeleeAttack,
|
||||
NearestTarget, RandomLookAround, RestrictSun, Stroll, goal_clone,
|
||||
@@ -25,6 +26,7 @@ pub fn register(m: &mut Mob) {
|
||||
match m.species() {
|
||||
S::Zombie | S::Husk | S::ZombieVillager => {
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(1, BreakDoor::zombie());
|
||||
g.add(4, AttackTurtleEgg::default());
|
||||
g.add(8, LookAtPlayer::new(8.0));
|
||||
g.add(8, RandomLookAround::default());
|
||||
@@ -52,6 +54,7 @@ pub fn register(m: &mut Mob) {
|
||||
S::ZombifiedPiglin => {
|
||||
// ZombifiedPiglin.addBehaviourGoals: neutral until provoked.
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(1, BreakDoor::zombie());
|
||||
g.add(8, LookAtPlayer::new(8.0));
|
||||
g.add(8, RandomLookAround::default());
|
||||
g.add(2, MeleeAttack::new(1.0, false).zombie());
|
||||
@@ -68,6 +71,7 @@ pub fn register(m: &mut Mob) {
|
||||
S::Drowned => {
|
||||
// Zombie.registerGoals, then Drowned.addBehaviourGoals.
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(1, BreakDoor::zombie());
|
||||
g.add(4, AttackTurtleEgg::default());
|
||||
g.add(8, LookAtPlayer::new(8.0));
|
||||
g.add(8, RandomLookAround::default());
|
||||
|
||||
Reference in New Issue
Block a user