Fix Peaceful removal of existing hostile mobs

Apply the vanilla Mob.checkDespawn Peaceful gate before persistence and player distance checks. Extend the mob AI parity harness with difficulty, persistence, name-tag and NoAI regressions and allowed-type controls.

Fixes #1942

Co-Authored-By: OpenAI Codex (GPT-6.1 Sol) <noreply@openai.com>
This commit is contained in:
rdbtCVS
2026-10-26 04:18:54 +00:00
parent 88d061ec9b
commit 03a3c48a71
4 changed files with 35 additions and 1 deletions
@@ -49,6 +49,7 @@ struct Scenario {
name: String,
ticks: i32,
time: i64,
difficulty: u8,
rain: bool,
thunder: bool,
origin: [i32; 2],
@@ -85,11 +86,13 @@ fn parse(text: &str) -> Vec<Scenario> {
"scenario" => {
s.name = f[1].to_owned();
s.time = 6000;
s.difficulty = 2;
for kv in &f[2..] {
let (k, v) = kv.split_once('=').unwrap_or((kv, ""));
match k {
"ticks" => s.ticks = v.parse().unwrap(),
"time" => s.time = v.parse().unwrap(),
"difficulty" => s.difficulty = v.parse().unwrap(),
"rain" => s.rain = true,
"thunder" => s.thunder = true,
"levelseed" => {}
@@ -954,6 +957,10 @@ pub fn main() -> horizon_client::Result<()> {
for flag in &spec.flags {
match flag.as_str() {
"persistent" => m.persistent = true,
"named" => {
m.custom_name = Some("Peaceful regression".into());
m.persistent = true;
}
"ridden" => {
m.extra.head = Some("minecraft:red_harness".into());
m.rider = Some(horizon_client::mobs::equine::Rider::default());
@@ -1090,7 +1097,7 @@ pub fn main() -> horizon_client::Result<()> {
block_tags: &items.block_tags,
biomes: &biomes,
mob_griefing: true,
difficulty: LocalDifficulty::new(2, world.day_time, 0, 0.0),
difficulty: LocalDifficulty::new(s.difficulty, world.day_time, 0, 0.0),
end: false,
world_seed: 0,
// FlatLevelSource.getSeaLevel.
+4
View File
@@ -1024,6 +1024,10 @@ fn check_despawn(m: &mut Mob, w: &MobWorld) -> bool {
if m.species() == Species::Mannequin {
return true;
}
// Mob.checkDespawn discards disallowed types even when persistent or NoAI.
if w.difficulty.effective == 0.0 && !super::spawn_rules::allowed_in_peaceful(m.species()) {
return false;
}
let Some(p) = w.nearest_player else {
return true;
};
@@ -159,6 +159,7 @@ public final class VanillaMobAiOracle {
static final class Scenario {
String name;
int ticks;
int difficulty = 2;
long time = 6000;
boolean rain, thunder;
int originX, originZ;
@@ -204,6 +205,7 @@ public final class VanillaMobAiOracle {
switch (kv[0]) {
case "ticks" -> s.ticks = Integer.parseInt(kv[1]);
case "time" -> s.time = Long.parseLong(kv[1]);
case "difficulty" -> s.difficulty = Integer.parseInt(kv[1]);
case "rain" -> s.rain = true;
case "thunder" -> s.thunder = true;
case "levelseed" -> s.levelSeed = Long.parseLong(kv[1]);
@@ -494,6 +496,7 @@ public final class VanillaMobAiOracle {
}
void run(Scenario s, ServerLevel level) throws Exception {
this.setDifficulty(net.minecraft.world.Difficulty.byId(s.difficulty), true);
out.println("== " + s.name);
var clock = level.registryAccess().lookupOrThrow(Registries.WORLD_CLOCK).getOrThrow(WorldClocks.OVERWORLD);
this.clockManager().setTotalTicks(clock, s.time);
@@ -553,6 +556,10 @@ public final class VanillaMobAiOracle {
String v = kv.length > 1 ? kv[1] : "";
switch (kv[0]) {
case "persistent" -> mob.setPersistenceRequired();
case "named" -> {
mob.setCustomName(net.minecraft.network.chat.Component.literal("Peaceful regression"));
mob.setPersistenceRequired();
}
case "ridden" -> mob.setItemSlot(net.minecraft.world.entity.EquipmentSlot.BODY,
new net.minecraft.world.item.ItemStack(BuiltInRegistries.ITEM.getValue(
net.minecraft.resources.Identifier.parse("minecraft:red_harness"))));
+16
View File
@@ -311,6 +311,22 @@ def scenarios():
add('villager_golem_panic', 100, ['fill -2 -60 -3 4 -60 4 minecraft:oak_fence', 'fill -1 -60 -2 3 -60 3 minecraft:air',
'player 14.5 -60 0.5'] + golem_callers[:3]
+ ['mob minecraft:zombie 6.5 -60 0.5 90 86 persistent noai'], 'time=18000')
# Mob.checkDespawn removes disallowed types before persistence/NoAI checks.
# Keep the non-Peaceful controls and the allowed hostile/neutral exceptions.
for difficulty in range(4):
for flags in ('', 'persistent', 'named', 'noai', 'persistent noai'):
suffix = flags.replace(' ', '_') or 'ordinary'
add(f'peaceful_zombie_{difficulty}_{suffix}', 1, [
'player 6.5 -60 0.5',
f'mob minecraft:zombie 0.5 -60 0.5 0 1 {flags}',
], f'difficulty={difficulty} time=18000')
for species in ('skeleton', 'creeper', 'slime', 'warden', 'wither',
'piglin', 'shulker', 'bee', 'wolf', 'iron_golem', 'cow'):
add(f'peaceful_type_{species}', 1, [
'player 6.5 -60 0.5',
f'mob minecraft:{species} 0.5 -60 0.5 0 1 persistent noai',
], 'difficulty=0 time=18000')
return s