Merge pull request #2018 from rdbtCVS/fix/peaceful-mob-despawn-1942

🤖 Agent: contrib-gate-17 verified this head (26.3 sources, integration tree build, clippy, tests, parity; details in the PR comment). Thanks @rdbtCVS!
This commit is contained in:
Ludovic Marie
2026-10-26 13:55:47 +01:00
committed by GitHub
4 changed files with 40 additions and 2 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;
};
@@ -60,6 +60,7 @@ import net.minecraft.util.debugchart.SampleLogger;
import net.minecraft.world.clock.WorldClocks;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntitySpawnRequest;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.entity.monster.creaking.Creaking;
@@ -159,6 +160,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 +206,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 +497,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);
@@ -537,7 +541,9 @@ public final class VanillaMobAiOracle {
int id = 100000;
for (MobSpec spec : s.mobs) {
EntityType<?> type = BuiltInRegistries.ENTITY_TYPE.getValue(net.minecraft.resources.Identifier.parse(spec.type));
Mob mob = (Mob) type.create(level, EntitySpawnReason.COMMAND);
// Ignore canSpawn: a Peaceful scenario's hostile mob is one that was already
// in the world when the difficulty changed (create returns null at Peaceful).
Mob mob = (Mob) type.create(level, new EntitySpawnRequest(EntitySpawnReason.COMMAND, true));
if (tracing(s)) field(Entity.class, "random").set(mob, new TracingRandom(0L, TRACE, ENTS.size()));
mob.setId(id++);
mob.snapTo(spec.x, spec.y, spec.z, spec.yaw, 0.0F);
@@ -553,6 +559,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"))));
+17
View File
@@ -311,6 +311,23 @@ 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')
# Not slime, piglin or bee: a slime made without finalizeSpawn keeps 20 health, the probe
# doesn't model a piglin's brain, and a NoAI bee's flower cooldown differs (none of it Peaceful).
for species in ('skeleton', 'creeper', 'warden', 'wither', 'shulker', '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