summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-09-24 13:16:55 +0200
committerLinnea Gräf <nea@nea.moe>2024-09-24 13:16:55 +0200
commitfb40ab45f0b4979420bae066da2244f4fdd52db8 (patch)
tree66afc558aade18c996b23da47a02f6726fb656aa /src/main
parent8a5c5d45f87f38d9a7484b73c0505b95e63a21f1 (diff)
downloadultra-notifier-fb40ab45f0b4979420bae066da2244f4fdd52db8.tar.gz
ultra-notifier-fb40ab45f0b4979420bae066da2244f4fdd52db8.tar.bz2
ultra-notifier-fb40ab45f0b4979420bae066da2244f4fdd52db8.zip
snapshot
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/AllModules.kt11
-rw-r--r--src/main/kotlin/ChatStore.kt37
-rw-r--r--src/main/kotlin/UltraNotifier.kt8
-rw-r--r--src/main/kotlin/commands/BrigadierPatchbay.kt27
-rw-r--r--src/main/kotlin/commands/Commands.kt6
-rw-r--r--src/main/kotlin/event/SubscriptionTarget.kt5
-rw-r--r--src/main/kotlin/event/UltraNotifierEvents.kt2
-rw-r--r--src/main/kotlin/gui/BaseScreen.kt52
-rw-r--r--src/main/kotlin/gui/MessageUi.kt6
-rw-r--r--src/main/kotlin/util/IdentityCharacteristics.kt15
10 files changed, 144 insertions, 25 deletions
diff --git a/src/main/kotlin/AllModules.kt b/src/main/kotlin/AllModules.kt
new file mode 100644
index 0000000..9befea9
--- /dev/null
+++ b/src/main/kotlin/AllModules.kt
@@ -0,0 +1,11 @@
+package moe.nea.ultranotifier
+
+import moe.nea.ultranotifier.commands.Commands
+import moe.nea.ultranotifier.event.SubscriptionTarget
+
+object AllModules {
+ val allModules: List<SubscriptionTarget> = listOf(
+ ChatStore,
+ Commands
+ )
+}
diff --git a/src/main/kotlin/ChatStore.kt b/src/main/kotlin/ChatStore.kt
new file mode 100644
index 0000000..2d9ff30
--- /dev/null
+++ b/src/main/kotlin/ChatStore.kt
@@ -0,0 +1,37 @@
+package moe.nea.ultranotifier
+
+import moe.nea.ultranotifier.event.ChatGuiLineEvent
+import moe.nea.ultranotifier.event.PacketChatLineEvent
+import moe.nea.ultranotifier.event.SubscriptionTarget
+import moe.nea.ultranotifier.event.UltraSubscribe
+import moe.nea.ultranotifier.util.IdentityCharacteristics
+import net.minecraft.text.Text
+
+object ChatStore : SubscriptionTarget {
+
+ data class ChatLine(
+ val text: Text,
+ var fromPacket: Boolean = false,
+ var isDisplayed: Boolean = false,
+ )
+
+ val allLines = object : LinkedHashMap<IdentityCharacteristics<Text>, ChatLine>() {
+ override fun removeEldestEntry(eldest: MutableMap.MutableEntry<IdentityCharacteristics<Text>, ChatLine>?): Boolean {
+ return size > 500 // TODO: config
+ }
+ }
+
+ fun insertChatLine(text: Text): ChatLine {
+ return allLines.getOrPut(IdentityCharacteristics(text)) { ChatLine(text) }
+ }
+
+ @UltraSubscribe
+ fun onMessageDisplayed(event: ChatGuiLineEvent) {
+ insertChatLine(event.component).isDisplayed = true
+ }
+
+ @UltraSubscribe
+ fun onMessageReceived(event: PacketChatLineEvent) {
+ insertChatLine(event.component).fromPacket = true
+ }
+}
diff --git a/src/main/kotlin/UltraNotifier.kt b/src/main/kotlin/UltraNotifier.kt
index f1bb8ff..cce83e9 100644
--- a/src/main/kotlin/UltraNotifier.kt
+++ b/src/main/kotlin/UltraNotifier.kt
@@ -1,7 +1,8 @@
package moe.nea.ultranotifier
-import moe.nea.ultranotifier.commands.Commands
import moe.nea.ultranotifier.event.RegistrationFinishedEvent
+import moe.nea.ultranotifier.event.UltraEvent
+import moe.nea.ultranotifier.event.UltraNotifierEvents
import moe.nea.ultranotifier.init.NeaMixinConfig
import java.io.File
@@ -18,7 +19,10 @@ object UltraNotifier {
for (mixinPlugin in NeaMixinConfig.getMixinPlugins()) {
logger.info("Loaded ${mixinPlugin.mixins.size} mixins for ${mixinPlugin.mixinPackage}.")
}
- Commands.init()
+ AllModules.allModules.forEach {
+ UltraNotifierEvents.register(it)
+ it.init()
+ }
RegistrationFinishedEvent().post()
diff --git a/src/main/kotlin/commands/BrigadierPatchbay.kt b/src/main/kotlin/commands/BrigadierPatchbay.kt
index 7396b6c..a6c9f6a 100644
--- a/src/main/kotlin/commands/BrigadierPatchbay.kt
+++ b/src/main/kotlin/commands/BrigadierPatchbay.kt
@@ -1,6 +1,6 @@
package moe.nea.ultranotifier.commands
-//#if FORGE
+//#if MC < 1.16
//$$import com.mojang.brigadier.CommandDispatcher
//$$import com.mojang.brigadier.builder.LiteralArgumentBuilder
//$$import com.mojang.brigadier.tree.CommandNode
@@ -12,8 +12,7 @@ package moe.nea.ultranotifier.commands
//$$import net.minecraft.command.CommandBase
//$$import net.minecraft.command.CommandHandler
//$$import net.minecraft.command.ICommandSender
-//$$import net.minecraft.util.BlockPos
-//$$import net.minecraft.util.ChatComponentText
+//$$import net.minecraft.server.MinecraftServer
//$$import net.minecraft.util.text.ITextComponent
//$$import net.minecraftforge.client.ClientCommandHandler
//$$
@@ -23,7 +22,7 @@ package moe.nea.ultranotifier.commands
//$$ val sender: ICommandSender
//$$) : UltraCommandSource {
//$$ override fun sendFeedback(text: ITextComponent) {
-//$$ sender.addChatMessage(text)
+//$$ sender.sendMessage(text)
//$$ }
//$$}
//$$
@@ -31,37 +30,27 @@ package moe.nea.ultranotifier.commands
//$$ val dispatcher: CommandDispatcher<UltraCommandSource>,
//$$ val node: CommandNode<UltraCommandSource>
//$$) : CommandBase() {
-//$$ override fun addTabCompletionOptions(
-//$$ sender: ICommandSender?,
-//$$ args: Array<out String>?,
-//$$ pos: BlockPos?
-//$$ ): MutableList<String> {
-//$$ return super.addTabCompletionOptions(sender, args, pos)
-//$$ }
-//$$
-//$$ override fun canCommandSenderUseCommand(sender: ICommandSender?): Boolean {
-//$$ // TODO: proper check here maybe?
+//$$ override fun checkPermission(server: MinecraftServer, sender: ICommandSender): Boolean {
//$$ return true
//$$ }
//$$
-//$$ override fun getCommandName(): String {
+//$$ override fun getName(): String {
//$$ return node.name
//$$ }
//$$
-//$$ override fun getCommandUsage(sender: ICommandSender?): String {
+//$$ override fun getUsage(sender: ICommandSender): String {
//$$ return ""
//$$ }
//$$
//$$ private fun getCommandLineText(args: Array<out String>) = "${node.name} ${args.joinToString(" ")}".trim()
-//$$
-//$$ override fun processCommand(sender: ICommandSender, args: Array<out String>) {
+//$$ override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<out String>) {
//$$ val source = BridgedCommandSource(sender)
//$$ val results = dispatcher.parse(getCommandLineText(args), source)
//$$ kotlin.runCatching {
//$$ dispatcher.execute(results)
//$$ Unit
//$$ }.recoverCatching {
-//$$ source.sendFeedback(ChatComponentText("Could not execute ultra command: ${it.message}"))
+//$$ source.sendFeedback(literalText("Could not execute ultra command: ${it.message}"))
//$$ }
//$$ }
//$$}
diff --git a/src/main/kotlin/commands/Commands.kt b/src/main/kotlin/commands/Commands.kt
index 4509fcf..95e8685 100644
--- a/src/main/kotlin/commands/Commands.kt
+++ b/src/main/kotlin/commands/Commands.kt
@@ -3,6 +3,7 @@ package moe.nea.ultranotifier.commands
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import moe.nea.ultranotifier.UltraNotifier
import moe.nea.ultranotifier.event.CommandRegistrationEvent
+import moe.nea.ultranotifier.event.SubscriptionTarget
import moe.nea.ultranotifier.event.UltraNotifierEvents
import moe.nea.ultranotifier.event.UltraSubscribe
import net.minecraft.text.Text
@@ -35,7 +36,7 @@ fun literalText(string: String): Text =
//$$ net.minecraft.util.ChatComponentText(string)
//#endif
-object Commands {
+object Commands : SubscriptionTarget {
@UltraSubscribe
fun registerTestCommand(event: CommandRegistrationEvent) {
event.dispatcher.register(LiteralArgumentBuilder.literal<UltraCommandSource>("hello")
@@ -45,8 +46,7 @@ object Commands {
})
}
- fun init() {
- UltraNotifierEvents.register(this)
+ override fun init() {
//#if FORGE
//$$ UltraNotifierEvents.register(BrigadierPatchbay)
//#else
diff --git a/src/main/kotlin/event/SubscriptionTarget.kt b/src/main/kotlin/event/SubscriptionTarget.kt
new file mode 100644
index 0000000..e66eb94
--- /dev/null
+++ b/src/main/kotlin/event/SubscriptionTarget.kt
@@ -0,0 +1,5 @@
+package moe.nea.ultranotifier.event
+
+interface SubscriptionTarget {
+ fun init() = Unit
+}
diff --git a/src/main/kotlin/event/UltraNotifierEvents.kt b/src/main/kotlin/event/UltraNotifierEvents.kt
index 34d1769..7190b63 100644
--- a/src/main/kotlin/event/UltraNotifierEvents.kt
+++ b/src/main/kotlin/event/UltraNotifierEvents.kt
@@ -16,7 +16,7 @@ object UltraNotifierEvents {
return event
}
- fun register(obj: Any) {
+ fun register(obj: SubscriptionTarget) {
//#if FORGE
//$$ eventBus.register(obj)
//#else
diff --git a/src/main/kotlin/gui/BaseScreen.kt b/src/main/kotlin/gui/BaseScreen.kt
new file mode 100644
index 0000000..06aafb9
--- /dev/null
+++ b/src/main/kotlin/gui/BaseScreen.kt
@@ -0,0 +1,52 @@
+package moe.nea.ultranotifier.gui
+
+import net.minecraft.client.gui.DrawContext
+import net.minecraft.client.gui.screen.Screen
+import net.minecraft.text.Text
+//#if MC < 1.20.4
+//$$import com.mojang.blaze3d.platform.GlStateManager
+//#endif
+
+class DrawingContext(
+//#if MC > 1.20.4
+ val vanilla: DrawContext,
+//#endif
+) {
+ fun pushMatrix() {
+//#if MC > 1.20.4
+ vanilla.matrices.push()
+//#else
+//$$ GlStateManager.pushMatrix()
+//#endif
+ }
+ fun popMatrix() {
+//#if MC > 1.20.4
+ vanilla.matrices.pop()
+//#else
+//$$ GlStateManager.popMatrix()
+//#endif
+ }
+ fun translate(x: Double, y: Double, z: Double) {
+//#if MC > 1.20.4
+ vanilla.matrices.translate(x, y, z)
+//#else
+//$$ GlStateManager.translate(x, y, z)
+//#endif
+ }
+ fun scale(x: Float, y: Float, z: Float) {
+//#if MC > 1.20.4
+ vanilla.matrices.scale(x, y, z)
+//#else
+//$$ GlStateManager.scale(x, y, z)
+//#endif
+ }
+
+}
+
+abstract class BaseScreen(title: Text) : Screen(
+//#if MC >= 11400
+ title
+//#endif
+) {
+
+}
diff --git a/src/main/kotlin/gui/MessageUi.kt b/src/main/kotlin/gui/MessageUi.kt
new file mode 100644
index 0000000..78965b3
--- /dev/null
+++ b/src/main/kotlin/gui/MessageUi.kt
@@ -0,0 +1,6 @@
+package moe.nea.ultranotifier.gui
+
+import moe.nea.ultranotifier.commands.literalText
+
+class MessageUi : BaseScreen(literalText("Messages")) {
+}
diff --git a/src/main/kotlin/util/IdentityCharacteristics.kt b/src/main/kotlin/util/IdentityCharacteristics.kt
new file mode 100644
index 0000000..d3f5294
--- /dev/null
+++ b/src/main/kotlin/util/IdentityCharacteristics.kt
@@ -0,0 +1,15 @@
+package moe.nea.ultranotifier.util
+
+class IdentityCharacteristics<T>(val value: T) {
+ override fun hashCode(): Int {
+ return System.identityHashCode(value)
+ }
+
+ override fun equals(other: Any?): Boolean {
+ return value === other
+ }
+
+ override fun toString(): String {
+ return "IdentityCharacteristics($value)"
+ }
+}