Skip to content

Commit

Permalink
fixed things
Browse files Browse the repository at this point in the history
  • Loading branch information
Globox1997 committed Dec 22, 2023
1 parent 7b81425 commit 111fba9
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 51 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Added:
-
- Added max check config option
### Fixed:
- Fixed bugs by belcar-s
- Fixed advancement bubble
- Fixed command bubble
### Changed:
- Updated to mc 1.20.1
-
2 changes: 2 additions & 0 deletions src/main/java/net/talkbubbles/config/TalkBubblesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class TalkBubblesConfig implements ConfigData {
public float backgroundRed = 1.0F;
public float backgroundGreen = 1.0F;
public float backgroundBlue = 1.0F;
@Comment("0 = disabled")
public int maxUUIDWordCheck = 0;
public boolean showOwnBubble = false;

}
115 changes: 68 additions & 47 deletions src/main/java/net/talkbubbles/mixin/ChatHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,72 +38,93 @@ public class ChatHudMixin {
// onChatMessage is now done in MessageHandler.class
@Inject(method = "Lnet/minecraft/client/gui/hud/ChatHud;addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("HEAD"))
private void addMessageMixin(Text message, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator, CallbackInfo info) {
if (client != null && client.player != null && !extractSender(message).isEmpty()) {
if (client != null && client.player != null) {
String detectedSenderName = extractSender(message);
UUID senderUUID = this.client.getSocialInteractionsManager().getUuid(detectedSenderName);

List<AbstractClientPlayerEntity> list = client.world.getEntitiesByClass(AbstractClientPlayerEntity.class, client.player.getBoundingBox().expand(TalkBubbles.CONFIG.chatRange),
EntityPredicates.EXCEPT_SPECTATOR);

if (!TalkBubbles.CONFIG.showOwnBubble)
list.remove(client.player);
for (int i = 0; i < list.size(); i++)
if (list.get(i).getUuid().equals(senderUUID)) {
String stringMessage = message.getString();
stringMessage = stringMessage.replaceFirst("[\\s\\S]*" + detectedSenderName + "([^\\w§]|(§.)?)+\\s+", "");
String[] string = stringMessage.split(" ");
List<String> stringList = new ArrayList<>();
String stringCollector = "";

int width = 0;
int height = 0;
for (int u = 0; u < string.length; u++) {
if (client.textRenderer.getWidth(stringCollector) < TalkBubbles.CONFIG.maxChatWidth
&& client.textRenderer.getWidth(stringCollector) + client.textRenderer.getWidth(string[u]) <= TalkBubbles.CONFIG.maxChatWidth) {
stringCollector = stringCollector + " " + string[u];
if (u == string.length - 1) {
stringList.add(stringCollector);
height++;
if (width < client.textRenderer.getWidth(stringCollector))
width = client.textRenderer.getWidth(stringCollector);
}
} else {
stringList.add(stringCollector);

height++;
if (width < client.textRenderer.getWidth(stringCollector))
width = client.textRenderer.getWidth(stringCollector);
if (!detectedSenderName.isEmpty()) {
UUID senderUUID = this.client.getSocialInteractionsManager().getUuid(detectedSenderName);

stringCollector = string[u];
List<AbstractClientPlayerEntity> list = client.world.getEntitiesByClass(AbstractClientPlayerEntity.class, client.player.getBoundingBox().expand(TalkBubbles.CONFIG.chatRange),
EntityPredicates.EXCEPT_SPECTATOR);

if (u == string.length - 1) {
if (!TalkBubbles.CONFIG.showOwnBubble) {
list.remove(client.player);
}
for (int i = 0; i < list.size(); i++)
if (list.get(i).getUuid().equals(senderUUID)) {
String stringMessage = message.getString();
stringMessage = stringMessage.replaceFirst("[\\s\\S]*" + detectedSenderName + "([^\\w§]|(§.)?)+\\s+", "");
String[] string = stringMessage.split(" ");
List<String> stringList = new ArrayList<>();
String stringCollector = "";

int width = 0;
int height = 0;
for (int u = 0; u < string.length; u++) {
if (client.textRenderer.getWidth(stringCollector) < TalkBubbles.CONFIG.maxChatWidth
&& client.textRenderer.getWidth(stringCollector) + client.textRenderer.getWidth(string[u]) <= TalkBubbles.CONFIG.maxChatWidth) {
stringCollector = stringCollector + " " + string[u];
if (u == string.length - 1) {
stringList.add(stringCollector);
height++;
if (width < client.textRenderer.getWidth(stringCollector)) {
width = client.textRenderer.getWidth(stringCollector);
}
}
} else {
stringList.add(stringCollector);

height++;
if (width < client.textRenderer.getWidth(stringCollector))
if (width < client.textRenderer.getWidth(stringCollector)) {
width = client.textRenderer.getWidth(stringCollector);
}

stringCollector = string[u];

if (u == string.length - 1) {
stringList.add(stringCollector);
height++;
if (width < client.textRenderer.getWidth(stringCollector)) {
width = client.textRenderer.getWidth(stringCollector);
}
}
}
}
}

if (width % 2 != 0)
width++;
((AbstractClientPlayerEntityAccessor) list.get(i)).setChatText(stringList, list.get(i).age, width, height);
break;
}
if (width % 2 != 0) {
width++;
}
((AbstractClientPlayerEntityAccessor) list.get(i)).setChatText(stringList, list.get(i).age, width, height);
break;
}
}
}

}

private String extractSender(Text text) {
String[] words = text.getString().split("(§.)|[^\\w§]+");
String[] parts = text.toString().split("key='");

if (parts.length > 1) {
String translationKey = parts[1].split("'")[0];
if (translationKey.contains("commands")) {
return "";
} else if (translationKey.contains("advancement")) {
return "";
}
}

for (String word : words) {
if (word.isEmpty())
for (int i = 0; i < words.length; i++) {
if (words[i].isEmpty()) {
continue;
}
if (TalkBubbles.CONFIG.maxUUIDWordCheck != 0 && i >= TalkBubbles.CONFIG.maxUUIDWordCheck) {
return "";
}

UUID possibleUUID = this.client.getSocialInteractionsManager().getUuid(word);
UUID possibleUUID = this.client.getSocialInteractionsManager().getUuid(words[i]);
if (possibleUUID != Util.NIL_UUID) {
return word;
return words[i];
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/talkbubbles/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"text.autoconfig.talkbubbles.option.backgroundRed": "Background Red",
"text.autoconfig.talkbubbles.option.backgroundGreen": "Background Green",
"text.autoconfig.talkbubbles.option.backgroundBlue": "Background Blue",
"text.autoconfig.talkbubbles.option.showOwnBubble": "Show Own Bubble"
"text.autoconfig.talkbubbles.option.showOwnBubble": "Show Own Bubble",
"text.autoconfig.talkbubbles.option.maxUUIDWordCheck": "Max UUID Word Check"
}

0 comments on commit 111fba9

Please sign in to comment.