Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some message util methods #765

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/main/java/com/Nxer/TwistSpaceTechnology/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
import java.util.function.IntFunction;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -293,6 +297,40 @@ public static String i18n(String key) {
return translateToLocalFormatted(key);
}

/**
* Send a string to player's chat area directly.
*/
public static void sendTextToPlayer(EntityPlayer player, String text) {
if (player instanceof EntityPlayerMP && text != null) {
player.addChatComponentMessage(new ChatComponentText(text));
}
}

/**
* Send localized message to player.
*
* @param player the player
* @param translationKey the message's localization key
*/
public static void sendMessageToPlayerLocalized(EntityPlayer player, String translationKey) {
if (player instanceof EntityPlayerMP && translationKey != null) {
player.addChatComponentMessage(new ChatComponentTranslation(translationKey));
}
}

/**
* Send localized message to player.
*
* @param player the player
* @param translationKey the message's localization key
* @param formatArgs extra arguments
*/
public static void sendMessageToPlayerLocalized(EntityPlayer player, String translationKey, Object... formatArgs) {
if (player instanceof EntityPlayerMP && translationKey != null) {
player.addChatComponentMessage(new ChatComponentTranslation(translationKey, formatArgs));
}
}

// endregion

// region Rewrites
Expand Down