diff --git a/build.gradle b/build.gradle index 5f6936d0..e2290519 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ plugins { id "java" } -version = "1.1.1-beta2" +version = "1.2.0" group = modGroup archivesBaseName = "Hytilities-Reborn" diff --git a/src/main/java/net/wyvest/hytilities/Hytilities.java b/src/main/java/net/wyvest/hytilities/Hytilities.java index a6f32c85..c1891885 100644 --- a/src/main/java/net/wyvest/hytilities/Hytilities.java +++ b/src/main/java/net/wyvest/hytilities/Hytilities.java @@ -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; @@ -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 @@ -130,6 +131,7 @@ public void postInit(FMLPostInitializationEvent event) { if (Loader.isModLoaded("tabulous")) { config.hideTabulous(); } + isPatcher = Loader.isModLoaded("patcher"); } @Mod.EventHandler diff --git a/src/main/java/net/wyvest/hytilities/mixin/GuiNewChatMixin_LocrawHider.java b/src/main/java/net/wyvest/hytilities/mixin/GuiNewChatMixin_LocrawHider.java index cc9a7667..0595c9b9 100644 --- a/src/main/java/net/wyvest/hytilities/mixin/GuiNewChatMixin_LocrawHider.java +++ b/src/main/java/net/wyvest/hytilities/mixin/GuiNewChatMixin_LocrawHider.java @@ -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 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(); } } + + } diff --git a/src/main/java/net/wyvest/hytilities/mixin/GuiUtilRenderComponentsMixin_TrimLineBreaker.java b/src/main/java/net/wyvest/hytilities/mixin/GuiUtilRenderComponentsMixin_TrimLineBreaker.java index 13ae96a0..c0c3a8b9 100644 --- a/src/main/java/net/wyvest/hytilities/mixin/GuiUtilRenderComponentsMixin_TrimLineBreaker.java +++ b/src/main/java/net/wyvest/hytilities/mixin/GuiUtilRenderComponentsMixin_TrimLineBreaker.java @@ -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 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 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 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; } }