Match vanilla's op warning on item tooltips

The warning was missing its bold first line and skipped spawn eggs of op-only entities. Vanilla: ItemStack.OP_NBT_WARNING, BlockItem and SpawnEggItem.shouldPrintOpWarning (non-block items never warn).
This commit is contained in:
Kacpherek
2026-10-27 21:45:45 +01:00
parent d485c688d6
commit 7acfc655e8
2 changed files with 37 additions and 8 deletions
@@ -35,6 +35,25 @@ pub fn op_warning(stack: &crate::items::ItemStack) -> bool {
data(stack).is_some_and(|(id, _)| OP_ONLY.contains(&id.as_str()))
}
/// `SpawnEggItem.shouldPrintOpWarning` for a player with game master
/// permission: a spawn egg carries data of an op-only entity type
/// (`EntityTypes.OP_ONLY_CUSTOM_DATA`).
pub fn spawn_egg_op_warning(stack: &crate::items::ItemStack) -> bool {
stack.item.ends_with("_spawn_egg")
&& matches!(
stack
.data()
.and_then(|d| d.other("minecraft:entity_data"))
.and_then(|data| data.get("id")),
Some(Tag::String(id)) if matches!(
id.to_string_lossy().as_str(),
"minecraft:falling_block"
| "minecraft:command_block_minecart"
| "minecraft:spawner_minecart"
)
)
}
/// `Spawner.getSpawnEntityDisplayName` (`SpawnData.entity.id` of the item's
/// data, which `ItemStack.addDetailsToTooltip` reads for spawners and trial
/// spawners alike): the entity type a spawner item spawns.
+18 -8
View File
@@ -2059,9 +2059,16 @@ impl Game<'_> {
);
}
}
// ItemStack.OP_NBT_WARNING, for a player with game master permission.
if !nested && self.ui.registries.permission >= 2 && block_entity_item::op_warning(stack) {
for (key, fallback) in [
// ItemStack.OP_NBT_WARNING: `BlockItem` and `SpawnEggItem`
// `.shouldPrintOpWarning` for a player with game master permission;
// a nested projectile has no player. The first line is bold.
if !nested
&& self.ui.registries.permission >= 2
&& (item_info.is_some_and(|i| i.block.is_some())
&& block_entity_item::op_warning(stack)
|| block_entity_item::spawn_egg_op_warning(stack))
{
for (i, (key, fallback)) in [
("item.op_warning.line1", "Warning:"),
(
"item.op_warning.line2",
@@ -2071,12 +2078,15 @@ impl Game<'_> {
"item.op_warning.line3",
"Do not use unless you know the exact contents!",
),
] {
push(
&mut lines,
self.translate(key, fallback),
]
.into_iter()
.enumerate()
{
let text = horizon_client::text::Text::legacy(&self.translate(key, fallback));
lines.push((
if i == 0 { text.bold() } else { text },
rgba(255, 85, 85, 255),
);
));
}
}
lines