Commands: fail summon when a mod rejects a mob or minecart

Return None when a spawn's join callback removes the mob, propagate it through summon, and flush minecart joins before reporting success while watching the new cart's ID.

Fixes #7184

Co-Authored-By: Codex <[email protected]>
This commit is contained in:
masa-masa-0314andCodex committed 2026-11-02 21:24:26 +08:00
1 parent 2f35078b3a
commit d9ae51fe46
2 files changed
+9 -1

No files matched your search

+6 -1
View File
@@ -2175,7 +2175,8 @@ impl Game<'_> {
if self.ui.difficulty == 0 && t.category == "monster" {
return Err(err("commands.summon.failed.peaceful", &[]));
}
self.spawn_mob_spawned(&short, pos);
self.spawn_mob_spawned(&short, pos)
.ok_or_else(|| err("commands.summon.failed.uuid", &[]))?;
name = Text::translate(&entity_name_key(&kind), &[]);
} else {
match short.as_str() {
@@ -2250,7 +2251,11 @@ impl Game<'_> {
let empty = horizon_world::nbt::Tag::Compound(Default::default());
cart.spawner = Some(Box::new(Spawner::load(&empty)));
}
let id = cart.id;
self.carts.push(cart);
if !self.native_joins_flush(false, id) {
return Err(err("commands.summon.failed.uuid", &[]));
}
name = Text::translate(&format!("entity.minecraft.{k}"), &[]);
}
// SummonCommand.createEntity: any other type from an empty compound.
@@ -427,6 +427,9 @@ impl Game<'_> {
let id = mob.id;
self.mobs.push(mob);
self.native_mobs_joined(self.mobs.len() - 1, false);
if !self.mobs.iter().any(|m| m.id == id) {
return None;
}
self.enchant_spawn_equipment(id);
self.halloween_spawn_head(id);
if !persistent && !scripted {