aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java33
-rw-r--r--src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java11
-rw-r--r--src/main/java/com/raeids/stratus/mixin/GuiUtilRenderComponentsMixin.java26
-rw-r--r--src/main/kotlin/com/raeids/stratus/Stratus.kt42
-rw-r--r--src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt (renamed from src/main/kotlin/com/raeids/stratus/hook/ChatHook.kt)0
-rw-r--r--src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt92
-rw-r--r--src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt109
-rw-r--r--src/main/kotlin/com/raeids/stratus/hook/ChatTabsJson.kt6
-rw-r--r--src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt58
-rw-r--r--src/main/resources/mixins.stratus.json1
10 files changed, 342 insertions, 36 deletions
diff --git a/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java
index be04586..4f9b2eb 100644
--- a/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java
+++ b/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java
@@ -1,7 +1,9 @@
package com.raeids.stratus.mixin;
import com.raeids.stratus.config.StratusConfig;
-import com.raeids.stratus.hook.ChatHookKt;
+import com.raeids.stratus.hook.ChatSearchingKt;
+import com.raeids.stratus.hook.ChatTab;
+import com.raeids.stratus.hook.ChatTabs;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiScreen;
import org.spongepowered.asm.mixin.Mixin;
@@ -15,46 +17,49 @@ public abstract class GuiChatMixin extends GuiScreen {
@Inject(method = "initGui", at = @At("TAIL"))
private void init(CallbackInfo ci) {
if (StratusConfig.INSTANCE.getChatSearch()) {
- ChatHookKt.initGui();
+ ChatSearchingKt.initGui();
+ }
+ for (ChatTab chatTab : ChatTabs.INSTANCE.getTabs()) {
+ buttonList.add(chatTab.getButton());
}
}
@Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiTextField;drawTextBox()V", shift = At.Shift.AFTER))
private void yeah(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
- if (ChatHookKt.getInputField() != null) {
- ChatHookKt.getInputField().drawTextBox();
+ if (ChatSearchingKt.getInputField() != null) {
+ ChatSearchingKt.getInputField().drawTextBox();
}
}
@Inject(method = "onGuiClosed", at = @At("TAIL"))
private void onGuiClosed(CallbackInfo ci) {
- ChatHookKt.setInputField(null);
- ChatHookKt.setPrevText("");
+ ChatSearchingKt.setInputField(null);
+ ChatSearchingKt.setPrevText("");
}
@Inject(method = "updateScreen", at = @At("HEAD"))
private void updateScreen(CallbackInfo ci) {
- ChatHookKt.updateScreen();
+ ChatSearchingKt.updateScreen();
}
@Inject(method = "keyTyped", at = @At("HEAD"), cancellable = true)
private void keyTyped(char typedChar, int keyCode, CallbackInfo ci) {
- if (ChatHookKt.getInputField() != null) {
- if (ChatHookKt.getInputField().isFocused()) {
+ if (ChatSearchingKt.getInputField() != null) {
+ if (ChatSearchingKt.getInputField().isFocused()) {
ci.cancel();
- if (keyCode == 1 && ChatHookKt.getInputField().isFocused()) {
- ChatHookKt.getInputField().setFocused(false);
+ if (keyCode == 1 && ChatSearchingKt.getInputField().isFocused()) {
+ ChatSearchingKt.getInputField().setFocused(false);
return;
}
- ChatHookKt.getInputField().textboxKeyTyped(typedChar, keyCode);
+ ChatSearchingKt.getInputField().textboxKeyTyped(typedChar, keyCode);
}
}
}
@Inject(method = "mouseClicked", at = @At("HEAD"))
private void mouseClicked(int mouseX, int mouseY, int mouseButton, CallbackInfo ci) {
- if (ChatHookKt.getInputField() != null) {
- ChatHookKt.getInputField().mouseClicked(mouseX, mouseY, mouseButton);
+ if (ChatSearchingKt.getInputField() != null) {
+ ChatSearchingKt.getInputField().mouseClicked(mouseX, mouseY, mouseButton);
}
}
}
diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
index 48e2525..bbe1e9b 100644
--- a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
+++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
@@ -1,10 +1,12 @@
package com.raeids.stratus.mixin;
import com.raeids.stratus.Stratus;
-import com.raeids.stratus.hook.ChatHookKt;
+import com.raeids.stratus.hook.ChatSearchingKt;
+import com.raeids.stratus.hook.ChatTabs;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ChatLine;
import net.minecraft.client.gui.GuiNewChat;
+import net.minecraft.util.IChatComponent;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -21,6 +23,11 @@ import java.util.List;
public class GuiNewChatMixin {
@Shadow @Final private Minecraft mc;
+ @Inject(method = "setChatLine", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;floor_float(F)I", shift = At.Shift.AFTER))
+ private void setDoing(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
+ ChatTabs.INSTANCE.setDoing(true);
+ }
+
@Inject(method = "drawChat", at = @At("HEAD"))
private void checkScreenshotKeybind(int j2, CallbackInfo ci) {
if (Stratus.INSTANCE.getKeybind().isPressed()) {
@@ -44,6 +51,6 @@ public class GuiNewChatMixin {
@Redirect(method = "drawChat", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/GuiNewChat;drawnChatLines:Ljava/util/List;", opcode = Opcodes.GETFIELD))
private List<ChatLine> injected(GuiNewChat instance) {
- return ChatHookKt.filterMessages(drawnChatLines);
+ return ChatSearchingKt.filterMessages(drawnChatLines);
}
}
diff --git a/src/main/java/com/raeids/stratus/mixin/GuiUtilRenderComponentsMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiUtilRenderComponentsMixin.java
new file mode 100644
index 0000000..05378cd
--- /dev/null
+++ b/src/main/java/com/raeids/stratus/mixin/GuiUtilRenderComponentsMixin.java
@@ -0,0 +1,26 @@
+package com.raeids.stratus.mixin;
+
+import com.raeids.stratus.hook.ChatTabs;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.GuiUtilRenderComponents;
+import net.minecraft.util.IChatComponent;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import java.util.Collections;
+import java.util.List;
+
+@Mixin(GuiUtilRenderComponents.class)
+public class GuiUtilRenderComponentsMixin {
+ @Inject(method = "splitText", at = @At("HEAD"), cancellable = true)
+ private static void cancelText(IChatComponent k, int s1, FontRenderer chatcomponenttext, boolean l, boolean chatcomponenttext2, CallbackInfoReturnable<List<IChatComponent>> cir) {
+ if (ChatTabs.INSTANCE.isDoing()) {
+ ChatTabs.INSTANCE.setDoing(false);
+ if (!ChatTabs.INSTANCE.shouldRender(k.getUnformattedTextForChat())) {
+ cir.setReturnValue(Collections.emptyList());
+ }
+ }
+ }
+}
diff --git a/src/main/kotlin/com/raeids/stratus/Stratus.kt b/src/main/kotlin/com/raeids/stratus/Stratus.kt
index 3c8984b..653c265 100644
--- a/src/main/kotlin/com/raeids/stratus/Stratus.kt
+++ b/src/main/kotlin/com/raeids/stratus/Stratus.kt
@@ -2,6 +2,7 @@ package com.raeids.stratus
import com.raeids.stratus.command.StratusCommand
import com.raeids.stratus.config.StratusConfig
+import com.raeids.stratus.hook.ChatTabs
import com.raeids.stratus.mixin.GuiNewChatAccessor
import com.raeids.stratus.updater.Updater
import com.raeids.stratus.utils.RenderHelper
@@ -43,6 +44,8 @@ object Stratus {
lateinit var jarFile: File
private set
+ private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'")
+
val modDir = File(File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME)
@Mod.EventHandler
@@ -51,7 +54,25 @@ object Stratus {
jarFile = event.sourceFile
}
- private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'")
+ @Mod.EventHandler
+ fun onInitialization(event: FMLInitializationEvent) {
+ StratusConfig.preload()
+ StratusCommand.register()
+ ClientRegistry.registerKeyBinding(keybind)
+ EVENT_BUS.register(this)
+ ChatTabs.initialize()
+ Updater.update()
+ }
+
+ @SubscribeEvent
+ fun onTickEvent(event: TickEvent.ClientTickEvent) {
+ if (event.phase == TickEvent.Phase.START && Minecraft.getMinecraft().theWorld != null && Minecraft.getMinecraft().thePlayer != null && (Minecraft.getMinecraft().currentScreen == null || Minecraft.getMinecraft().currentScreen is GuiChat)) {
+ if (doTheThing) {
+ screenshot()
+ doTheThing = false
+ }
+ }
+ }
private fun screenshot() {
val hud = Minecraft.getMinecraft().ingameGUI
@@ -93,23 +114,4 @@ object Stratus {
}
}
}
-
- @Mod.EventHandler
- fun onInitialization(event: FMLInitializationEvent) {
- StratusConfig.preload()
- StratusCommand.register()
- ClientRegistry.registerKeyBinding(keybind)
- EVENT_BUS.register(this)
- Updater.update()
- }
-
- @SubscribeEvent
- fun onTickEvent(event: TickEvent.ClientTickEvent) {
- if (event.phase == TickEvent.Phase.START && Minecraft.getMinecraft().theWorld != null && Minecraft.getMinecraft().thePlayer != null && (Minecraft.getMinecraft().currentScreen == null || Minecraft.getMinecraft().currentScreen is GuiChat)) {
- if (doTheThing) {
- screenshot()
- doTheThing = false
- }
- }
- }
}
diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatHook.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt
index c056161..c056161 100644
--- a/src/main/kotlin/com/raeids/stratus/hook/ChatHook.kt
+++ b/src/main/kotlin/com/raeids/stratus/hook/ChatSearching.kt
diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt
new file mode 100644
index 0000000..f2fd0fc
--- /dev/null
+++ b/src/main/kotlin/com/raeids/stratus/hook/ChatTab.kt
@@ -0,0 +1,92 @@
+package com.raeids.stratus.hook
+
+import com.google.gson.annotations.SerializedName
+import kotlinx.coroutines.runBlocking
+import net.minecraft.client.Minecraft
+
+data class ChatTab(
+ @SerializedName("name") val name: String,
+ @SerializedName("starts") val startsWith: List<String>?,
+ @SerializedName("contains") val contains: List<String>?,
+ @SerializedName("ends") val endsWith: List<String>?,
+ @SerializedName("equals") val equals: List<String>?,
+ @SerializedName("regex") val uncompiledRegex: List<String>?,
+ @SerializedName("prefix") val prefix: String
+) {
+ lateinit var button: CleanButton
+ var compiledRegex: MutableList<Regex> = arrayListOf()
+
+ //Ugly hack to make GSON not make button / regex null
+ fun initialize() {
+ compiledRegex = arrayListOf()
+ val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(name)
+ button = CleanButton(653452, runBlocking {
+ val returnValue = x - 2
+ x += 6 + width
+ return@runBlocking returnValue
+ }, 0, width + 4, 12, this)
+ if (uncompiledRegex != null && uncompiledRegex.isNotEmpty()) {
+ uncompiledRegex.forEach {
+ compiledRegex.add(Regex(it))
+ }
+ }
+ }
+
+ fun shouldRender(message: String): Boolean {
+ if (startsWith == null && equals == null && endsWith == null && contains == null && uncompiledRegex == null) {
+ return true
+ }
+ equals?.forEach {
+ if (message == it) {
+ return true
+ }
+ }
+ startsWith?.forEach {
+ if (message.startsWith(it)) {
+ return true
+ }
+ }
+ endsWith?.forEach {
+ if (message.endsWith(it)) {
+ return true
+ }
+ }
+ contains?.forEach {
+ if (message.contains(it)) {
+ return true
+ }
+ }
+ if ((uncompiledRegex != null) && uncompiledRegex.isNotEmpty()) {
+ try {
+ compiledRegex.forEach {
+ if (it.matches(message)) {
+ return true
+ }
+ }
+ } catch (_: Throwable) {
+
+ }
+ }
+ return false
+ }
+
+ override fun equals(other: Any?): Boolean {
+ return other is ChatTab && name == other.name && startsWith == other.startsWith && contains == other.contains && endsWith == other.endsWith && equals == other.equals && compiledRegex == other.compiledRegex
+ }
+
+ override fun hashCode(): Int {
+ var result = name.hashCode()
+ result = 31 * result + (startsWith?.hashCode() ?: 0)
+ result = 31 * result + (contains?.hashCode() ?: 0)
+ result = 31 * result + (endsWith?.hashCode() ?: 0)
+ result = 31 * result + (equals?.hashCode() ?: 0)
+ result = 31 * result + (uncompiledRegex?.hashCode() ?: 0)
+ result = 31 * result + prefix.hashCode()
+ result = 31 * result + button.hashCode()
+ return result
+ }
+
+ companion object {
+ private var x = 4
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt
new file mode 100644
index 0000000..638f8b8
--- /dev/null
+++ b/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt
@@ -0,0 +1,109 @@
+package com.raeids.stratus.hook
+
+import com.google.gson.*
+import com.raeids.stratus.Stratus
+import net.minecraft.client.Minecraft
+import java.io.File
+
+object ChatTabs {
+ private val GSON = GsonBuilder().setPrettyPrinting().create()
+ private val PARSER = JsonParser()
+ val tabs = arrayListOf<ChatTab>()
+ var isDoing = false
+ var currentTab: ChatTab? = null
+ set(value) {
+ if (value != null) {
+ field = value
+ if (Minecraft.getMinecraft().theWorld != null) {
+ Minecraft.getMinecraft().ingameGUI.chatGUI.refreshChat()
+ }
+ println("current tab: ${value.name}")
+ }
+ }
+
+ private val tabFile = File(Stratus.modDir, "chattabs.json")
+
+ fun initialize() {
+ if (!tabFile.exists()) {
+ generateNewFile()
+ } else {
+ try {
+ val chatTabJson = GSON.fromJson(tabFile.readText(), ChatTabsJson::class.java)
+ chatTabJson.tabs.forEach {
+ tabs.add(GSON.fromJson(it.toString(), ChatTab::class.java))
+ }
+ } catch (e: Throwable) {
+ e.printStackTrace()
+ tabFile.delete()
+ generateNewFile()
+ }
+ }
+ tabs.forEach {
+ it.initialize()
+ }
+ currentTab = tabs[0]
+ }
+
+ fun shouldRender(message: String): Boolean {
+ return currentTab?.shouldRender(message) ?: true
+ }
+
+ private fun generateNewFile() {
+ tabFile.createNewFile()
+ val jsonObject = JsonObject()
+ val defaultTabs = generateDefaultTabs()
+ jsonObject.add("tabs", defaultTabs)
+ jsonObject.addProperty("version", 1)
+ tabFile.writeText(jsonObject.toString())
+ }
+
+ private fun generateDefaultTabs(): JsonArray {
+ val all = ChatTab("ALL", null, null, null, null, null, "")
+ val party = ChatTab(
+ "PARTY",
+ listOf("§r§9Party §8> ", "§r§9P §8> ", "§eThe party was transferred to §r", "§eKicked §r"),
+ null,
+ listOf(
+ "§r§ehas invited you to join their party!",
+ "§r§eto the party! They have §r§c60 §r§eseconds to accept.§r",
+ "§r§ehas disbanded the party!§r",
+ "§r§ehas disconnected, they have §r§c5 §r§eminutes to rejoin before they are removed from the party.§r",
+ " §r§ejoined the party.§r",
+ " §r§ehas left the party.§r",
+ " §r§ehas been removed from the party.§r",
+ "§r§e because they were offline.§r"
+ ),
+ listOf("§cThe party was disbanded because all invites expired and the party was empty§r"),
+ null,
+ "/pc "
+ )
+ val guild = ChatTab(
+ "GUILD",
+ listOf("§r§2Guild > ", "§r§2G > "),
+ null,
+ null,
+ null,
+ null,
+ "/gc "
+ )
+ val pm = ChatTab(
+ "PM",
+ listOf("§dTo ", "§dFrom "),
+ null,
+ null,
+ null,
+ null,
+ "/r "
+ )
+ tabs.add(all)
+ tabs.add(party)
+ tabs.add(guild)
+ tabs.add(pm)
+ val jsonArray = JsonArray()
+ jsonArray.add(PARSER.parse(GSON.toJson(all)).asJsonObject)
+ jsonArray.add(PARSER.parse(GSON.toJson(party)).asJsonObject)
+ jsonArray.add(PARSER.parse(GSON.toJson(guild)).asJsonObject)
+ jsonArray.add(PARSER.parse(GSON.toJson(pm)).asJsonObject)
+ return jsonArray
+ }
+}
diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTabsJson.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatTabsJson.kt
new file mode 100644
index 0000000..ede73ad
--- /dev/null
+++ b/src/main/kotlin/com/raeids/stratus/hook/ChatTabsJson.kt
@@ -0,0 +1,6 @@
+package com.raeids.stratus.hook
+
+import com.google.gson.JsonArray
+import com.google.gson.annotations.SerializedName
+
+data class ChatTabsJson(@SerializedName("tabs") val tabs: JsonArray, @SerializedName("version") val version: Int) \ No newline at end of file
diff --git a/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt b/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt
new file mode 100644
index 0000000..3c15842
--- /dev/null
+++ b/src/main/kotlin/com/raeids/stratus/hook/CleanButton.kt
@@ -0,0 +1,58 @@
+package com.raeids.stratus.hook
+
+import gg.essential.universal.UResolution
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.GuiButton
+import net.minecraft.client.renderer.GlStateManager
+import java.awt.Color
+
+/**
+ * Taken from ChatShortcuts under MIT License
+ * https://github.com/P0keDev/ChatShortcuts/blob/master/LICENSE
+ * @author P0keDev
+ */
+class CleanButton(buttonId: Int, x: Int, y: Int, widthIn: Int, heightIn: Int, private val chatTab: ChatTab) :
+ GuiButton(buttonId, x, y, widthIn, heightIn, chatTab.name) {
+
+ override fun mousePressed(mc: Minecraft, mouseX: Int, mouseY: Int): Boolean {
+ val isPressed =
+ enabled && visible && mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height
+ if (isPressed) {
+ ChatTabs.currentTab = chatTab
+ }
+ return isPressed
+ }
+
+ override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) {
+ enabled = chatTab != ChatTabs.currentTab
+ yPosition = UResolution.scaledHeight - 26
+ if (visible) {
+ val fontrenderer = mc.fontRendererObj
+ GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
+ hovered =
+ mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height
+ drawRect(
+ xPosition,
+ yPosition,
+ xPosition + width,
+ yPosition + height,
+ if (hovered) hoveredColor else color
+ )
+ mouseDragged(mc, mouseX, mouseY)
+ var j = 14737632
+ if (packedFGColour != 0) {
+ j = packedFGColour
+ } else if (!enabled) {
+ j = 10526880
+ } else if (hovered) {
+ j = 16777120
+ }
+ drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, j)
+ }
+ }
+
+ companion object {
+ private val hoveredColor = Color(255, 255, 255, 128).rgb
+ private val color = Color(0, 0, 0, 128).rgb
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/mixins.stratus.json b/src/main/resources/mixins.stratus.json
index d9c91e5..574b29e 100644
--- a/src/main/resources/mixins.stratus.json
+++ b/src/main/resources/mixins.stratus.json
@@ -6,6 +6,7 @@
"mixins": [
"GuiChatMixin",
"GuiNewChatAccessor",
+ "GuiUtilRenderComponentsMixin",
"GuiNewChatMixin"
],
"verbose": true