Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
1.19 release
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkKronicle committed Jul 28, 2022
1 parent 4d2a5fa commit 3a9209e
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 247 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ dependencies {
modImplementation "fi.dy.masa.malilib:malilib-fabric-1.19.0:${project.malilib_version}"
modCompileOnly "io.github.prospector:modmenu:1.16.8"

modImplementation "com.github.DarkKronicle:KommandLib:${project.kommandlib_version}"

implementation "com.github.DarkKronicle.Konstruct:addons:${project.konstruct_version}"
implementation "com.github.DarkKronicle.Konstruct:core:${project.konstruct_version}"
include "com.github.DarkKronicle:KommandLib:${project.kommandlib_version}"

implementation 'com.electronwill.night-config:toml:3.6.5'
// Transitive
Expand Down
9 changes: 4 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.19
yarn_mappings=1.19+build.4
minecraft_version=1.19.1
yarn_mappings=1.19.1+build.1
loader_version=0.14.8
fabric_api_version=0.57.0+1.19
fabric_api_version=0.58.5+1.19.1

mod_version=1.5.4
mod_version=1.5.5
maven_group=io.github.darkkronicle
archives_base_name=AdvancedChatCore

kommandlib_version=1.0.0-build2
malilib_version=0.13.0
konstruct_version=2.0.3-build1
mxparser_version=4.4.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import fi.dy.masa.malilib.interfaces.IInitializationHandler;
import fi.dy.masa.malilib.util.InfoUtils;
import io.github.darkkronicle.advancedchatcore.chat.*;
import io.github.darkkronicle.advancedchatcore.config.CommandsHandler;
import io.github.darkkronicle.advancedchatcore.config.ConfigStorage;
import io.github.darkkronicle.advancedchatcore.config.gui.GuiConfig;
import io.github.darkkronicle.advancedchatcore.config.gui.GuiConfigHandler;
Expand Down Expand Up @@ -101,7 +100,6 @@ public void registerModHandlers() {
"advancedchatcore.findtype.custom.profanity",
"advancedchatcore.findtype.custom.info.profanity");

CommandsHandler.getInstance().setup();
InputHandler.getInstance().addDisplayName("core_general", "advancedchatcore.config.tab.hotkeysgeneral");
InputHandler.getInstance().add("core_general", ConfigStorage.Hotkeys.OPEN_CHAT.config, (action, key) -> {
if (MinecraftClient.getInstance().world == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
import io.github.darkkronicle.advancedchatcore.util.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

import io.github.darkkronicle.advancedchatcore.util.RowList;
import lombok.Getter;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.client.gui.screen.ChatPreviewBackground;
import net.minecraft.client.network.ChatPreviewer;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.client.option.ChatPreviewMode;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.option.ServerList;
import net.minecraft.client.toast.SystemToast;
Expand All @@ -41,7 +44,9 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;

public class AdvancedChatScreen extends GuiBase {

Expand All @@ -68,13 +73,17 @@ public class AdvancedChatScreen extends GuiBase {
private final RowList<ButtonBase> leftSideButtons = new RowList<>();

// TODO chat preview somewhere else
private static final Text CHAT_PREVIEW_WARNING_TOAST_TITLE = Text.translatable("chatPreview.warning.toast.title");
private static final Text CHAT_PREVIEW_WARNING_TOAST_TEXT = Text.translatable("chatPreview.warning.toast");
private static final Text CHAT_PREVIEW_PLACEHOLDER_TEXT = Text.translatable("chat.preview").formatted(Formatting.DARK_GRAY);
private static final Text CHAT_PREVIEW_INPUT_TEXT = Text.translatable("chat.previewInput", Text.translatable("key.keyboard.enter"));


@Getter
private ChatPreviewer chatPreviewer;

@Getter
private boolean missingPreview;

private final ChatPreviewBackground chatPreviewBackground = new ChatPreviewBackground();

@Override
protected void closeGui(boolean showParent) {
if (ConfigStorage.ChatScreen.PERSISTENT_TEXT.config.getBooleanValue()) {
Expand Down Expand Up @@ -193,12 +202,16 @@ protected MutableText getNarrationMessage() {
setChatFromHistory(-startHistory - 1);
}
ServerInfo serverInfo = this.client.getCurrentServerEntry();
if (serverInfo != null && this.client.options.getChatPreview().getValue()) {
if (serverInfo != null && this.client.options.getChatPreview().getValue() == ChatPreviewMode.LIVE) {
ServerInfo.ChatPreview chatPreview = serverInfo.getChatPreview();
if (chatPreview != null && serverInfo.shouldPreviewChat() && chatPreview.showToast()) {
ServerList.updateServerListEntry(serverInfo);
}
}

if (client.options.getChatPreview().getValue() == ChatPreviewMode.CONFIRM) {
this.missingPreview = this.originalChatText.startsWith("/") && !this.client.player.hasSignedArgument(this.originalChatText.substring(1));
}
}

public void resize(MinecraftClient client, int width, int height) {
Expand Down Expand Up @@ -252,7 +265,7 @@ private void tryRequestCommandPreview(String chatText) {
private boolean shouldPreviewChat() {
if (this.client.player == null) {
return false;
} else if (!this.client.options.getChatPreview().getValue()) {
} else if (this.client.options.getChatPreview().getValue() == ChatPreviewMode.OFF) {
return false;
} else {
ServerInfo serverInfo = this.client.getCurrentServerEntry();
Expand All @@ -265,6 +278,12 @@ private void onChatFieldUpdate(String chatText) {
for (AdvancedChatScreenSection section : sections) {
section.onChatFieldUpdate(chatText, string);
}
if (client.options.getChatPreview().getValue() == ChatPreviewMode.LIVE) {
this.updatePreviewer(string);
} else if (client.options.getChatPreview().getValue() == ChatPreviewMode.CONFIRM && !this.chatPreviewer.equalsLastPreviewed(string)) {
this.missingPreview = string.startsWith("/") && !this.client.player.hasSignedArgument(string.substring(1));
this.chatPreviewer.tryRequest("");
}
}

@Override
Expand Down Expand Up @@ -295,7 +314,13 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == KeyCodes.KEY_ENTER || keyCode == KeyCodes.KEY_KP_ENTER) {
String string = this.chatField.getText().trim();
// Strip message and send
Text text = this.chatPreviewer.tryConsumeResponse(this.chatField.getText());
if (this.client.options.getChatPreview().getValue() == ChatPreviewMode.CONFIRM && !this.missingPreview) {
if (!this.chatPreviewer.equalsLastPreviewed(string)) {
this.updatePreviewer(string);
return false;
}
}
Text text = getPreviewText();
MessageSender.getInstance().sendMessage(string, text);
this.chatField.setText("");
last = "";
Expand Down Expand Up @@ -449,35 +474,69 @@ public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partia
if (style != null && style.getHoverEvent() != null) {
this.renderTextHoverEffect(matrixStack, style, mouseX, mouseY);
}
if (this.chatPreviewer.shouldRenderPreview()) {
this.renderChatPreview(matrixStack);
ChatPreviewBackground.RenderData renderData = this.chatPreviewBackground.computeRenderData(Util.getMeasuringTimeMs(), this.getPreviewScreenText());
if (renderData.preview() != null) {
this.renderChatPreview(matrixStack, renderData.preview(), renderData.alpha(), client.getProfileKeys().getSigner() != null);
}
}

public void renderChatPreview(MatrixStack matrices) {
int i = (int)(255.0 * (this.client.options.getChtOpacity().getValue() * 0.9F + 0.1F));
int j = (int)(255.0 * this.client.options.getTextBackgroundOpacity().getValue());
int k = this.getPreviewWidth();
List<OrderedText> list = this.getPreviewText();
int l = this.getPreviewHeight(list);
@Nullable
protected Text getPreviewScreenText() {
String string = this.chatField.getText();
if (string.isBlank()) {
return null;
} else {
Text text = this.getPreviewText();
return client.options.getChatPreview().getValue() == ChatPreviewMode.CONFIRM && !this.missingPreview
? (Text) Objects.requireNonNullElse(
text, this.chatPreviewer.equalsLastPreviewed(string) && !string.startsWith("/") ? Text.literal(string) : CHAT_PREVIEW_INPUT_TEXT
)
: text;
}
}

public void renderChatPreview(MatrixStack matrices, Text previewText, float alpha, boolean signable) {
int opacity = (int)(255.0 * (this.client.options.getChatOpacity().getValue() * 0.9F + 0.1F) * (double)alpha);
int j = (int)(
(double)(this.chatPreviewer.cannotConsumePreview() ? 127 : 255) * this.client.options.getTextBackgroundOpacity().getValue() * (double)alpha
);
int width = this.getPreviewWidth();
List<OrderedText> list = this.wrapPreviewText(previewText);
int height = this.getPreviewHeight(list);
int topY = this.getPreviewTop(height);
RenderSystem.enableBlend();
matrices.push();
matrices.translate((double)this.getPreviewLeft(), (double)this.getPreviewTop(l), 0.0);
fill(matrices, 0, 0, k, l, j << 24);
matrices.translate(2.0, 2.0, 0.0);

for(int m = 0; m < list.size(); ++m) {
OrderedText orderedText = list.get(m);
this.client.textRenderer.drawWithShadow(matrices, orderedText, 0.0F, (float)(m * 9), i << 24 | 16777215);
matrices.translate(this.getPreviewLeft(), topY, 0.0);
fill(matrices, 0, 0, width, height, j << 24);
if (opacity > 0) {
matrices.translate(2.0, 2.0, 0.0);

for (int n = 0; n < list.size(); ++n) {
OrderedText orderedText = list.get(n);
int o = n * 9;
this.textRenderer.drawWithShadow(matrices, orderedText, 0.0F, (float)o, opacity << 24 | 16777215);
}
}

matrices.pop();
RenderSystem.disableBlend();
if (signable && this.chatPreviewer.getPreviewText() != null) {
int n = this.chatPreviewer.cannotConsumePreview() ? 15118153 : 7844841;
int p = (int)(255.0F * alpha);
matrices.push();
fill(matrices, 0, topY, 2, this.getPreviewBottom(), p << 24 | n);
matrices.pop();
}

}

@Nullable
private Text getPreviewText() {
return Util.map(this.chatPreviewer.getPreviewText(), ChatPreviewer.Response::previewText);
}

private List<OrderedText> getPreviewText() {
Text text = this.chatPreviewer.getPreviewText();
return text != null ? this.textRenderer.wrapLines(text, this.getPreviewWidth()) : List.of(CHAT_PREVIEW_PLACEHOLDER_TEXT.asOrderedText());
private List<OrderedText> wrapPreviewText(Text preview) {
return this.textRenderer.wrapLines(preview, this.getPreviewWidth());
}

private int getPreviewWidth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.network.message.MessageSignatureData;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
Expand All @@ -26,17 +28,22 @@
@Environment(EnvType.CLIENT)
public class ChatHistoryProcessor implements IMessageProcessor {

private static boolean sendToHud(Text text) {
private static boolean sendToHud(Text text, @Nullable MessageSignatureData signature, MessageIndicator indicator) {
if (AdvancedChatCore.FORWARD_TO_HUD) {
((MixinChatHudInvoker) MinecraftClient.getInstance().inGameHud.getChatHud()).invokeAddMessage(
text, 0, MinecraftClient.getInstance().inGameHud.getTicks(), false);
text, signature, MinecraftClient.getInstance().inGameHud.getTicks(), indicator, false);
return true;
}
return false;
}

@Override
public boolean process(Text text, @Nullable Text unfiltered) {
return process(text, unfiltered, null, MessageIndicator.system());
}

@Override
public boolean process(Text text, @Nullable Text unfiltered, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator) {
if (unfiltered == null) {
unfiltered = text;
}
Expand Down Expand Up @@ -75,7 +82,7 @@ public boolean process(Text text, @Nullable Text unfiltered) {
.backgroundColor(new Color(0, 0, 0, 100))
.build();
if (ChatHistory.getInstance().add(line)) {
sendToHud(line.getDisplayText());
sendToHud(line.getDisplayText(), line.getSignature(), line.getIndicator());
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.network.message.MessageSignatureData;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -56,6 +58,11 @@ public class ChatMessage {
/** Split up lines for line breaks. */
protected List<AdvancedChatLine> lines;

@Nullable
protected MessageSignatureData signature;

protected MessageIndicator indicator;

/**
* Set's the display text of the message and formats the line breaks.
*
Expand Down Expand Up @@ -83,7 +90,9 @@ public ChatMessage shallowClone(int width) {
time,
backgroundColor,
width,
owner);
owner,
signature,
indicator);
message.setStacks(getStacks());
return message;
}
Expand Down Expand Up @@ -119,7 +128,9 @@ protected ChatMessage(
LocalTime time,
Color backgroundColor,
int width,
MessageOwner owner) {
MessageOwner owner,
@Nullable MessageSignatureData signature,
@Nullable MessageIndicator indicator) {
this.creationTick = creationTick;
this.displayText = displayText;
this.id = id;
Expand All @@ -129,6 +140,8 @@ protected ChatMessage(
this.uuid = UUID.randomUUID();
this.owner = owner;
this.originalText = originalText == null ? displayText : originalText;
this.signature = signature;
this.indicator = indicator == null ? MessageIndicator.system() : indicator;
formatChildren(width);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.CommandSuggestor;
import net.minecraft.client.gui.screen.ChatInputSuggestor;
import net.minecraft.client.util.math.MatrixStack;

/** Handles the CommandSuggestor for the chat */
@Environment(EnvType.CLIENT)
public class DefaultChatSuggestor extends AdvancedChatScreenSection {

private CommandSuggestor commandSuggestor;
private ChatInputSuggestor commandSuggestor;

public DefaultChatSuggestor(AdvancedChatScreen screen) {
super(screen);
Expand Down Expand Up @@ -65,7 +65,7 @@ public void initGui() {
MinecraftClient client = MinecraftClient.getInstance();
AdvancedChatScreen screen = getScreen();
this.commandSuggestor =
new CommandSuggestor(
new ChatInputSuggestor(
client,
screen,
screen.chatField,
Expand Down
Loading

0 comments on commit 3a9209e

Please sign in to comment.