Skip to main content

steel_core/command/builtins/
seed.rs

1use steel_utils::{Identifier, translations};
2use text_components::{
3    Modifier, TextComponent,
4    format::Color,
5    interactivity::{ClickEvent, HoverEvent},
6};
7
8use super::super::{
9    brigadier::{CommandNodeBuilder, CommandSyntaxError},
10    execution::{CommandSource, SteelCommandContext, SteelCommandRuntime, literal},
11    registration::CommandRegistration,
12};
13
14pub(super) fn registration() -> CommandRegistration<CommandSource> {
15    CommandRegistration::new(Identifier::vanilla_static("seed"), |_| command())
16}
17
18fn command() -> CommandNodeBuilder<CommandSource, SteelCommandRuntime> {
19    literal("seed").executes(send_seed)
20}
21
22#[expect(
23    clippy::unnecessary_wraps,
24    reason = "Command executors use a shared fallible callback signature."
25)]
26fn send_seed(context: &SteelCommandContext<CommandSource>) -> Result<i32, CommandSyntaxError> {
27    let seed = context.source().world().seed();
28    let seed_text = seed.to_string();
29    let message = translations::COMMANDS_SEED_SUCCESS
30        .message([TextComponent::from(seed_text.clone())
31            .color(Color::Green)
32            .hover_event(HoverEvent::show_text(&translations::CHAT_COPY_CLICK))
33            .click_event(ClickEvent::CopyToClipboard {
34                value: seed_text.into(),
35            })])
36        .component();
37    context.source().send_success(&message, false);
38    Ok(seed as i32)
39}