Merge pull request #4014 from jdbool/1.19.2

Add useMessageTag setting
This commit is contained in:
leijurv 2023-06-21 18:55:06 -07:00 committed by GitHub
commit 944405e4df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -17,10 +17,12 @@
package baritone.api;
import baritone.api.utils.Helper;
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 +774,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 +1148,10 @@ 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<Consumer<Component>> logger = new Setting<>((msg) -> {
final GuiMessageTag tag = useMessageTag.value ? Helper.MESSAGE_TAG : null;
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();
@ -160,8 +167,10 @@ public interface Helper {
*/
default void logDirect(boolean logAsToast, Component... components) {
MutableComponent component = Component.literal("");
if (!logAsToast && !BaritoneAPI.getSettings().useMessageTag.value) {
component.append(getPrefix());
component.append(Component.literal(" "));
}
Arrays.asList(components).forEach(component::append);
if (logAsToast) {
logToast(getPrefix(), component);