Add useMessageTag setting

This commit is contained in:
Mike 2023-06-21 15:14:54 -07:00
parent 6eeeeb3a1b
commit a5ca664a6a
2 changed files with 31 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import baritone.api.utils.NotificationHelper;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.TypeUtils;
import baritone.api.utils.gui.BaritoneToast;
import net.minecraft.client.GuiMessageTag;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Vec3i;
import net.minecraft.network.chat.Component;
@ -772,6 +773,11 @@ public final class Settings {
*/
public final Setting<Boolean> shortBaritonePrefix = new Setting<>(false);
/**
* Use a modern message tag instead of a prefix when logging to chat
*/
public final Setting<Boolean> useMessageTag = new Setting<>(false);
/**
* Echo commands to chat when they are run
*/
@ -1141,7 +1147,7 @@ public final class Settings {
* via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting
* {@link Setting#value};
*/
public final Setting<Consumer<Component>> logger = new Setting<>(msg -> Minecraft.getInstance().gui.getChat().addMessage(msg));
public final Setting<BiConsumer<Component, GuiMessageTag>> logger = new Setting<>((msg, tag) -> Minecraft.getInstance().gui.getChat().addMessage(msg, null, tag));
/**
* The function that is called when Baritone will send a desktop notification. This function can be added to

View File

@ -18,8 +18,10 @@
package baritone.api.utils;
import baritone.api.BaritoneAPI;
import baritone.api.Settings;
import baritone.api.utils.gui.BaritoneToast;
import net.minecraft.ChatFormatting;
import net.minecraft.client.GuiMessageTag;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
@ -48,6 +50,11 @@ public interface Helper {
*/
Minecraft mc = Minecraft.getInstance();
/**
* The tag to assign to chat messages when {@link Settings#useMessageTag} is {@code true}.
*/
GuiMessageTag MESSAGE_TAG = new GuiMessageTag(0xFF55FF, null, Component.literal("Baritone message."), "Baritone");
static Component getPrefix() {
// Inner text component
final Calendar now = Calendar.getInstance();
@ -156,20 +163,33 @@ public interface Helper {
* Send components to chat with the [Baritone] prefix
*
* @param logAsToast Whether to log as a toast notification
* @param useMessageTag Whether to use a message tag instead of a prefix
* @param components The components to send
*/
default void logDirect(boolean logAsToast, Component... components) {
default void logDirect(boolean logAsToast, boolean useMessageTag, Component... components) {
MutableComponent component = Component.literal("");
component.append(getPrefix());
component.append(Component.literal(" "));
if (!logAsToast && !useMessageTag) {
component.append(getPrefix());
component.append(Component.literal(" "));
}
Arrays.asList(components).forEach(component::append);
if (logAsToast) {
logToast(getPrefix(), component);
} else {
mc.execute(() -> BaritoneAPI.getSettings().logger.value.accept(component));
mc.execute(() -> BaritoneAPI.getSettings().logger.value.accept(component, useMessageTag ? MESSAGE_TAG : null));
}
}
/**
* Send components to chat with the [Baritone] prefix
*
* @param logAsToast Whether to log as a toast notification
* @param components The components to send
*/
default void logDirect(boolean logAsToast, Component... components) {
logDirect(logAsToast, BaritoneAPI.getSettings().useMessageTag.value, components);
}
/**
* Send components to chat with the [Baritone] prefix
*