diff options
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/AllModules.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/ChatStore.kt | 16 | ||||
-rw-r--r-- | src/main/kotlin/Constants.kt | 8 | ||||
-rw-r--r-- | src/main/kotlin/UltraNotifier.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/UltraNotifierEntryPoint.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/commands/BrigadierPatchbay.kt | 17 | ||||
-rw-r--r-- | src/main/kotlin/commands/Commands.kt | 22 | ||||
-rw-r--r-- | src/main/kotlin/event/ChatGuiLineEvent.kt | 8 | ||||
-rw-r--r-- | src/main/kotlin/event/TickEvent.kt | 26 | ||||
-rw-r--r-- | src/main/kotlin/gui/BaseScreen.kt | 52 | ||||
-rw-r--r-- | src/main/kotlin/gui/MessageUi.kt | 27 | ||||
-rw-r--r-- | src/main/kotlin/gui/ScreenUtil.kt | 19 |
12 files changed, 138 insertions, 69 deletions
diff --git a/src/main/kotlin/AllModules.kt b/src/main/kotlin/AllModules.kt index 9befea9..1626bea 100644 --- a/src/main/kotlin/AllModules.kt +++ b/src/main/kotlin/AllModules.kt @@ -2,10 +2,12 @@ package moe.nea.ultranotifier import moe.nea.ultranotifier.commands.Commands import moe.nea.ultranotifier.event.SubscriptionTarget +import moe.nea.ultranotifier.gui.ScreenUtil object AllModules { val allModules: List<SubscriptionTarget> = listOf( ChatStore, - Commands + Commands, + ScreenUtil, ) } diff --git a/src/main/kotlin/ChatStore.kt b/src/main/kotlin/ChatStore.kt index 2d9ff30..4cc6ee1 100644 --- a/src/main/kotlin/ChatStore.kt +++ b/src/main/kotlin/ChatStore.kt @@ -1,9 +1,15 @@ package moe.nea.ultranotifier +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import moe.nea.ultranotifier.commands.UltraCommandSource +import moe.nea.ultranotifier.commands.literalText import moe.nea.ultranotifier.event.ChatGuiLineEvent +import moe.nea.ultranotifier.event.CommandRegistrationEvent import moe.nea.ultranotifier.event.PacketChatLineEvent import moe.nea.ultranotifier.event.SubscriptionTarget import moe.nea.ultranotifier.event.UltraSubscribe +import moe.nea.ultranotifier.gui.MessageUi +import moe.nea.ultranotifier.gui.ScreenUtil import moe.nea.ultranotifier.util.IdentityCharacteristics import net.minecraft.text.Text @@ -31,6 +37,16 @@ object ChatStore : SubscriptionTarget { } @UltraSubscribe + fun registerCommands(event: CommandRegistrationEvent) { + event.dispatcher.register(LiteralArgumentBuilder.literal<UltraCommandSource?>("ultranotifier") + .executes { + it.source.sendFeedback(literalText("Opening screen")) + ScreenUtil.openScreen = (MessageUi()) + 0 + }) + } + + @UltraSubscribe fun onMessageReceived(event: PacketChatLineEvent) { insertChatLine(event.component).fromPacket = true } diff --git a/src/main/kotlin/Constants.kt b/src/main/kotlin/Constants.kt index a1903ce..d29d106 100644 --- a/src/main/kotlin/Constants.kt +++ b/src/main/kotlin/Constants.kt @@ -1,6 +1,6 @@ package moe.nea.ultranotifier - +// TODO: blossom this shit object Constants { const val MOD_ID = "ultranotifier" const val VERSION = "1.0.0" @@ -23,5 +23,11 @@ object Constants { "1.20.6" //#elseif MC == 11404 //$$ "1.14.4" +//#elseif MC == 11202 +//$$ "1.12.2" +//#elseif MC == 11605 +//$$ "1.16.5" +//#elseif MC == 11602 +//$$ "1.16.2" //#endif } diff --git a/src/main/kotlin/UltraNotifier.kt b/src/main/kotlin/UltraNotifier.kt index cce83e9..ddf8e87 100644 --- a/src/main/kotlin/UltraNotifier.kt +++ b/src/main/kotlin/UltraNotifier.kt @@ -8,7 +8,7 @@ import java.io.File object UltraNotifier { val logger = -//#if MC <= 11404 +//#if MC <= 1.17 //$$ org.apache.logging.log4j.LogManager.getLogger("UltraNotifier")!! //#else org.slf4j.LoggerFactory.getLogger("UltraNotifier")!! @@ -19,7 +19,9 @@ object UltraNotifier { for (mixinPlugin in NeaMixinConfig.getMixinPlugins()) { logger.info("Loaded ${mixinPlugin.mixins.size} mixins for ${mixinPlugin.mixinPackage}.") } + logger.info("All modules: ${AllModules.allModules}") AllModules.allModules.forEach { + logger.info("Registering $it") UltraNotifierEvents.register(it) it.init() } diff --git a/src/main/kotlin/UltraNotifierEntryPoint.kt b/src/main/kotlin/UltraNotifierEntryPoint.kt index 42ae064..aa84dc5 100644 --- a/src/main/kotlin/UltraNotifierEntryPoint.kt +++ b/src/main/kotlin/UltraNotifierEntryPoint.kt @@ -3,14 +3,14 @@ package moe.nea.ultranotifier //#if FORGE //$$import net.minecraftforge.fml.common.Mod //$$ -//#if MC == 10809 +//#if MC < 1.13 //$$import net.minecraftforge.fml.common.event.FMLInitializationEvent //$$@Mod(modid = Constants.MOD_ID, version = Constants.VERSION, useMetadata = true) //#else //$$@Mod(Constants.MOD_ID) //#endif //$$class UltraNotifierEntryPoint { -//#if MC == 10809 +//#if MC < 1.13 //$$ @Mod.EventHandler //$$ fun onInit(@Suppress("UNUSED_PARAMETER") event: FMLInitializationEvent) { //#else diff --git a/src/main/kotlin/commands/BrigadierPatchbay.kt b/src/main/kotlin/commands/BrigadierPatchbay.kt index a6c9f6a..424224b 100644 --- a/src/main/kotlin/commands/BrigadierPatchbay.kt +++ b/src/main/kotlin/commands/BrigadierPatchbay.kt @@ -8,6 +8,7 @@ package moe.nea.ultranotifier.commands //$$import moe.nea.ultranotifier.event.RegistrationFinishedEvent //$$import moe.nea.ultranotifier.event.UltraNotifierEvents //$$import moe.nea.ultranotifier.event.UltraSubscribe +//$$import moe.nea.ultranotifier.event.SubscriptionTarget //$$import moe.nea.ultranotifier.mixin.AccessorCommandHandler //$$import net.minecraft.command.CommandBase //$$import net.minecraft.command.CommandHandler @@ -30,9 +31,15 @@ package moe.nea.ultranotifier.commands //$$ val dispatcher: CommandDispatcher<UltraCommandSource>, //$$ val node: CommandNode<UltraCommandSource> //$$) : CommandBase() { -//$$ override fun checkPermission(server: MinecraftServer, sender: ICommandSender): Boolean { +//#if MC >= 1.12 +//$$ override fun checkPermission(server: MinecraftServer, sender: ICommandSender): Boolean { //$$ return true //$$ } +//#else +//$$ override fun canCommandSenderUseCommand(sender: ICommandSender): Boolean { +//$$ return true +//$$ } +//#endif //$$ //$$ override fun getName(): String { //$$ return node.name @@ -43,7 +50,13 @@ package moe.nea.ultranotifier.commands //$$ } //$$ //$$ private fun getCommandLineText(args: Array<out String>) = "${node.name} ${args.joinToString(" ")}".trim() +//$$ +//$$ +//#if MC < 1.12 +//$$ override fun processCommand(sender: ICommandSender, args: Array<out String>) { +//#else //$$ override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array<out String>) { +//#endif //$$ val source = BridgedCommandSource(sender) //$$ val results = dispatcher.parse(getCommandLineText(args), source) //$$ kotlin.runCatching { @@ -55,7 +68,7 @@ package moe.nea.ultranotifier.commands //$$ } //$$} //$$ -//$$object BrigadierPatchbay { +//$$object BrigadierPatchbay : SubscriptionTarget { //$$ //$$ @UltraSubscribe //$$ fun onAfterRegistration(event: RegistrationFinishedEvent) { diff --git a/src/main/kotlin/commands/Commands.kt b/src/main/kotlin/commands/Commands.kt index 95e8685..de6ded3 100644 --- a/src/main/kotlin/commands/Commands.kt +++ b/src/main/kotlin/commands/Commands.kt @@ -16,24 +16,25 @@ interface CustomSource { typealias UltraCommandSource = //#if FORGE //$$ CustomSource -//#else +//#elseif MC > 1.18 net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource - +//#else +//$$ net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource //#endif fun translatableText(key: String, vararg args: String) = -//#if MC > 11400 +//#if MC > 1.17 Text.translatable(key, *args) //#else -//$$ net.minecraft.util.ChatComponentTranslation(key, *args) +//$$ net.minecraft.text.TranslatableText(key, *args) //#endif fun literalText(string: String): Text = -//#if MC > 11400 +//#if MC > 1.17 Text.literal(string) //#else -//$$ net.minecraft.util.ChatComponentText(string) +//$$ net.minecraft.text.LiteralText(string) //#endif object Commands : SubscriptionTarget { @@ -46,10 +47,17 @@ object Commands : SubscriptionTarget { }) } +//#if MC <= 1.18 && FABRIC +//$$ @UltraSubscribe +//$$ fun registerEverythingOnce(event: moe.nea.ultranotifier.event.RegistrationFinishedEvent) { +//$$ CommandRegistrationEvent(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.DISPATCHER).post() +//$$ } +//#endif + override fun init() { //#if FORGE //$$ UltraNotifierEvents.register(BrigadierPatchbay) -//#else +//#elseif MC > 1.18 net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback.EVENT.register { dispatcher, registryAccess -> UltraNotifierEvents.post(CommandRegistrationEvent(dispatcher)) } diff --git a/src/main/kotlin/event/ChatGuiLineEvent.kt b/src/main/kotlin/event/ChatGuiLineEvent.kt index e37d31f..eb585dd 100644 --- a/src/main/kotlin/event/ChatGuiLineEvent.kt +++ b/src/main/kotlin/event/ChatGuiLineEvent.kt @@ -3,7 +3,13 @@ package moe.nea.ultranotifier.event import net.minecraft.text.Text class ChatGuiLineEvent(val component: Text) : UltraEvent() { - val string = component.string + val string = +//#if MC < 1.16 +//$$ component.unformattedText // Why does remap not do this automatically? hello? +//#else + component.string +//#endif + override fun toString(): String { return "ChatLineAddedEvent($string)" } diff --git a/src/main/kotlin/event/TickEvent.kt b/src/main/kotlin/event/TickEvent.kt new file mode 100644 index 0000000..8643261 --- /dev/null +++ b/src/main/kotlin/event/TickEvent.kt @@ -0,0 +1,26 @@ +package moe.nea.ultranotifier.event + +//#if FABRIC +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents +//#endif + +class TickEvent : UltraEvent() { + + companion object { + init { +//#if FABRIC + ClientTickEvents.END_CLIENT_TICK.register(ClientTickEvents.EndTick { + TickEvent().post() + }) +//#else +//$$ net.minecraftforge.common.MinecraftForge.EVENT_BUS.register(object { +//$$ @UltraSubscribe +//$$ fun onForgeEvent(event: net.minecraftforge.event.TickEvent.ClientTickEvent) { +//$$ if (event.phase == net.minecraftforge.event.TickEvent.Phase.END) +//$$ TickEvent().post() +//$$ } +//$$ }) +//#endif + } + } +} diff --git a/src/main/kotlin/gui/BaseScreen.kt b/src/main/kotlin/gui/BaseScreen.kt deleted file mode 100644 index 06aafb9..0000000 --- a/src/main/kotlin/gui/BaseScreen.kt +++ /dev/null @@ -1,52 +0,0 @@ -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 index 78965b3..f4012da 100644 --- a/src/main/kotlin/gui/MessageUi.kt +++ b/src/main/kotlin/gui/MessageUi.kt @@ -1,6 +1,29 @@ package moe.nea.ultranotifier.gui -import moe.nea.ultranotifier.commands.literalText +import gg.essential.universal.UGraphics +import gg.essential.universal.UMatrixStack +import gg.essential.universal.UScreen +import java.awt.Color + +class MessageUi : UScreen() { + override fun onDrawScreen(matrixStack: UMatrixStack, mouseX: Int, mouseY: Int, partialTicks: Float) { + super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks) + fillRect(matrixStack, + 0.0, 0.0, width.toDouble(), height.toDouble(), Color.RED) + } + + fun fillRect( + matrixStack: UMatrixStack, + left: Double, top: Double, right: Double, bottom: Double, + color: Color, + ) { + val buffer = UGraphics.getFromTessellator() + buffer.beginWithDefaultShader(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR) + buffer.pos(matrixStack, left, top, 0.0).color(color).endVertex() + buffer.pos(matrixStack, left, bottom, 0.0).color(color).endVertex() + buffer.pos(matrixStack, right, bottom, 0.0).color(color).endVertex() + buffer.pos(matrixStack, right, top, 0.0).color(color).endVertex() + buffer.drawDirect() + } -class MessageUi : BaseScreen(literalText("Messages")) { } diff --git a/src/main/kotlin/gui/ScreenUtil.kt b/src/main/kotlin/gui/ScreenUtil.kt new file mode 100644 index 0000000..bb3dfc3 --- /dev/null +++ b/src/main/kotlin/gui/ScreenUtil.kt @@ -0,0 +1,19 @@ +package moe.nea.ultranotifier.gui + +import gg.essential.universal.UScreen +import moe.nea.ultranotifier.event.SubscriptionTarget +import moe.nea.ultranotifier.event.TickEvent +import moe.nea.ultranotifier.event.UltraSubscribe +import net.minecraft.client.gui.screen.Screen + +object ScreenUtil : SubscriptionTarget { + var openScreen: Screen? = null + + @UltraSubscribe + fun onTick(event: TickEvent) { + openScreen?.let { + UScreen.displayScreen(it) + openScreen = null + } + } +} |