Skip to content

Commit

Permalink
rewrite trim line separator
Browse files Browse the repository at this point in the history
make hide locraw messages better
  • Loading branch information
Wyvest committed Jan 2, 2022
1 parent 5c66266 commit 7923bef
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
id "java"
}

version = "1.1.1-beta2"
version = "1.2.0"
group = modGroup
archivesBaseName = "Hytilities-Reborn"

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/wyvest/hytilities/Hytilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class Hytilities {

public static final String MOD_ID = "hytilities-reborn";
public static final String MOD_NAME = "Hytilities Reborn";
public static final String VERSION = "1.1.1-beta2";
public static final String VERSION = "1.2.0";

@Mod.Instance(MOD_ID)
public static Hytilities INSTANCE;
Expand All @@ -99,6 +99,7 @@ public class Hytilities {
private final LocrawUtil locrawUtil = new LocrawUtil();
private final AutoQueue autoQueue = new AutoQueue();

public boolean isPatcher;
private boolean loadedCall;

@Mod.EventHandler
Expand Down Expand Up @@ -130,6 +131,7 @@ public void postInit(FMLPostInitializationEvent event) {
if (Loader.isModLoaded("tabulous")) {
config.hideTabulous();
}
isPatcher = Loader.isModLoaded("patcher");
}

@Mod.EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,58 @@
package net.wyvest.hytilities.mixin;

import gg.essential.api.EssentialAPI;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ChatLine;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.util.IChatComponent;
import net.wyvest.hytilities.Hytilities;
import net.wyvest.hytilities.config.HytilitiesConfig;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(GuiNewChat.class)
public class GuiNewChatMixin_LocrawHider {
public abstract class GuiNewChatMixin_LocrawHider {
@Shadow @Final private Minecraft mc;

@Shadow @Final private List<ChatLine> chatLines;

@SuppressWarnings({"FieldCanBeLocal", "unused"})
private float percentComplete;

@Shadow public abstract void deleteChatLine(int id);

@Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"), cancellable = true)
private void handlePrintChatMessage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) {
handleHytilsMessage(chatComponent, chatLineId, mc.ingameGUI.getUpdateCounter(), false, ci);
}

@Inject(method = "setChatLine", at = @At("HEAD"), cancellable = true)
private void hideLocrawMessages(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
private void handleSetChatLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
handleHytilsMessage(chatComponent, chatLineId, updateCounter, displayOnly, ci);
}

private void handleHytilsMessage(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
if (HytilitiesConfig.hideLocraw && EssentialAPI.getMinecraftUtil().isHypixel() && chatComponent.getUnformattedTextForChat().startsWith("{") && chatComponent.getUnformattedTextForChat().endsWith("}")) {
percentComplete = 1.0F;
if (chatLineId != 0) {
deleteChatLine(chatLineId);
}
if (!displayOnly) {
chatLines.add(0, new ChatLine(updateCounter, chatComponent, chatLineId));
while (this.chatLines.size() > (100 + (Hytilities.INSTANCE.isPatcher ? 32667 : 0)))
{
this.chatLines.remove(this.chatLines.size() - 1);
}
}
ci.cancel();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,50 @@

package net.wyvest.hytilities.mixin;

import net.wyvest.hytilities.config.HytilitiesConfig;
import net.minecraft.client.gui.GuiUtilRenderComponents;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.wyvest.hytilities.config.HytilitiesConfig;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.ArrayList;
import java.util.List;

@Mixin(GuiUtilRenderComponents.class)
public class GuiUtilRenderComponentsMixin_TrimLineBreaker {

@Dynamic
@Redirect(method = "splitText", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V", remap = false))
private static void redirectSplit(List<Object> instance, int i, Object e) {
if (HytilitiesConfig.lineBreakerTrim) {
String s = EnumChatFormatting.getTextWithoutFormattingCodes(((ChatComponentText) e).getUnformattedTextForChat());
if ((s.startsWith("-") && s.endsWith("-")) || (s.startsWith("▬") && s.endsWith("▬")) || (s.startsWith("≡") && s.endsWith("≡"))) {
return;
@Redirect(method = "splitText", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 1))
private static boolean trimLineSeperator(List<IChatComponent> list, Object obj) {
boolean value = false;
if (obj instanceof IChatComponent) {
value = list.add((IChatComponent) obj);
if (HytilitiesConfig.lineBreakerTrim) {
boolean seperatorFound = false;
int i = -1;
List<Integer> remove = new ArrayList<>();
for (IChatComponent component : list) {
i++;
String s = EnumChatFormatting.getTextWithoutFormattingCodes(component.getUnformattedText());

if ((s.startsWith("-") && s.endsWith("-")) || (s.startsWith("▬") && s.endsWith("▬")) || (s.startsWith("≡") && s.endsWith("≡"))) {
if (seperatorFound) {
remove.add(i);
} else {
seperatorFound = true;
}
} else if (seperatorFound) {
seperatorFound = false;
}
}
for (Integer removed : remove) {
list.remove((int) removed);
}
}
}
instance.add(i, e);
return value;
}
}

0 comments on commit 7923bef

Please sign in to comment.