top.hendrixshen.magiclib.util.minecraft.InfoUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magiclib-minecraft-api-1.19.3-fabric Show documentation
Show all versions of magiclib-minecraft-api-1.19.3-fabric Show documentation
Unleash magic into Minecraft, infuse souls, ascend to heaven!
package top.hendrixshen.magiclib.util.minecraft;
import net.fabricmc.api.Environment;
import net.minecraft.class_2561;
import net.minecraft.class_310;
import org.jetbrains.annotations.NotNull;
import top.hendrixshen.magiclib.util.collect.ValueContainer;
//#if MC > 11802 && MC < 11903
//#if MC > 11900
//$$ import net.minecraft.Util;
//#endif
//$$ import net.minecraft.client.gui.chat.ClientChatPreview;
//#endif
@Environment(net.fabricmc.api.EnvType.CLIENT)
public class InfoUtil {
public static void displayClientMessage(class_2561 component, boolean useActionBar) {
ValueContainer.ofNullable(class_310.method_1551().field_1724).ifPresent(p ->
p.method_7353(component, useActionBar));
}
public static void displayActionBarMessage(class_2561 component) {
InfoUtil.displayClientMessage(component, true);
}
public static void displayChatMessage(class_2561 component) {
InfoUtil.displayClientMessage(component, false);
}
public static void send(@NotNull String text) {
if (text.startsWith("/")) {
InfoUtil.sendCommand(text);
} else {
InfoUtil.sendChat(text);
}
}
public static void sendChat(@NotNull String message) {
ValueContainer.ofNullable(class_310.method_1551().field_1724).ifPresent(player -> {
String realText = message.trim();
if (!realText.isEmpty()) {
//#if MC > 11902
player.field_3944.method_45729(message.trim());
//#elseif MC > 11802
//$$ player.chatSigned(message, InfoUtil.getSign(message));
//#else
//$$ player.chat(message.trim());
//#endif
}
});
}
public static void sendCommand(@NotNull String command) {
ValueContainer.ofNullable(class_310.method_1551().field_1724).ifPresent(player -> {
String realText = command.trim();
if (!realText.isEmpty()) {
//#if MC > 11902
player.field_3944.method_45730(command.trim());
//#elseif MC > 11802
//$$ player.commandSigned(command, InfoUtil.getSign(command));
//#else
//$$ player.chat(String.format("/%s", command.trim()));
//#endif
}
});
}
//#if MC > 11802 && MC < 11903
//$$ public static Component getSign(String text) {
//$$ ClientChatPreview ccp = new ClientChatPreview(Minecraft.getInstance());
//#if MC > 11900
//$$ return Util.mapNullable(ccp.pull(text), ClientChatPreview.Preview::response);
//#else
//$$ return ccp.pull(text);
//#endif
//$$ }
//#endif
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy