From aa1238430bd0f103f040ed31baadc029bb09529e Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 24 Sep 2024 16:41:49 +0200 Subject: snapshot --- build.gradle.kts | 24 ++++++---- sharedVariables/src/Versions.kt | 2 +- .../ultranotifier/mixin/ChatHudMessageAdded.java | 22 ++++----- src/main/kotlin/AllModules.kt | 4 +- src/main/kotlin/ChatStore.kt | 16 +++++++ src/main/kotlin/Constants.kt | 8 +++- src/main/kotlin/UltraNotifier.kt | 4 +- src/main/kotlin/UltraNotifierEntryPoint.kt | 4 +- src/main/kotlin/commands/BrigadierPatchbay.kt | 17 ++++++- src/main/kotlin/commands/Commands.kt | 22 ++++++--- src/main/kotlin/event/ChatGuiLineEvent.kt | 8 +++- src/main/kotlin/event/TickEvent.kt | 26 +++++++++++ src/main/kotlin/gui/BaseScreen.kt | 52 ---------------------- src/main/kotlin/gui/MessageUi.kt | 27 ++++++++++- src/main/kotlin/gui/ScreenUtil.kt | 19 ++++++++ versions/mapping-1.12.2-1.8.9.txt | 2 + versions/mapping-1.14.4-1.14.4-forge.txt | 0 versions/mapping-1.14.4-forge-1.8.9.txt | 7 --- versions/mapping-1.16.2-forge-1.12.2.txt | 6 +++ versions/mapping-1.20.6-1.14.4.txt | 0 20 files changed, 173 insertions(+), 97 deletions(-) create mode 100644 src/main/kotlin/event/TickEvent.kt delete mode 100644 src/main/kotlin/gui/BaseScreen.kt create mode 100644 src/main/kotlin/gui/ScreenUtil.kt create mode 100644 versions/mapping-1.12.2-1.8.9.txt delete mode 100644 versions/mapping-1.14.4-1.14.4-forge.txt delete mode 100644 versions/mapping-1.14.4-forge-1.8.9.txt create mode 100644 versions/mapping-1.16.2-forge-1.12.2.txt delete mode 100644 versions/mapping-1.20.6-1.14.4.txt diff --git a/build.gradle.kts b/build.gradle.kts index e95fde4..aedae03 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,6 +34,7 @@ java.toolchain.languageVersion.set(mcJavaVersion) preprocess.run { vars.put("MC", version.minecraftVersion.versionNumber) vars.put("FORGE", if ((version.forgeDep != null)) 1 else 0) + vars.put("FABRIC", if ((version.forgeDep != null)) 0 else 1) vars.put("JAVA", mcJavaVersion.asInt()) } loom.run { @@ -60,11 +61,14 @@ val shadowImpl by configurations.creating { val shadowModImpl by configurations.creating { modImplementation.extendsFrom(this) } -val include = if (version.forgeDep != null) configurations.getByName("include") else shadowModImpl +val include = if (version.forgeDep != null) configurations.create("includeModImpl") { + configurations.getByName("include").extendsFrom(this) + modImplementation.extendsFrom(this) +} else shadowModImpl val devauthVersion = "1.1.2" dependencies { "minecraft"("com.mojang:minecraft:" + version.minecraftVersion.versionName) - "mappings"(if(version.mappingDependency=="official") loom.officialMojangMappings() else version.mappingDependency) + "mappings"(if (version.mappingDependency == "official") loom.officialMojangMappings() else version.mappingDependency) if (version.forgeDep != null) { "forge"(version.forgeDep!!) runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:$devauthVersion") @@ -118,7 +122,7 @@ tasks.shadowJar { tasks.processResources { inputs.property("java", mcJavaVersion.asInt().toString()) - inputs.property("mcVersion", version.minecraftVersion) + inputs.property("mcVersion", version.minecraftVersion.versionName) inputs.property("version", project.version.toString()) inputs.property("modName", "Ultra Notifier") inputs.property("description", "Ultra Notifications") @@ -150,9 +154,11 @@ tasks.named("runClient", RunGameTask::class) { }) } -tasks.withType { - onlyIf { false } -} -tasks.withType { - onlyIf { false } -} +if (version == Versions.MC116Forge) { + tasks.withType { + onlyIf { false } + } + tasks.withType { + onlyIf { false } + } +} \ No newline at end of file diff --git a/sharedVariables/src/Versions.kt b/sharedVariables/src/Versions.kt index 447ac33..4de930e 100644 --- a/sharedVariables/src/Versions.kt +++ b/sharedVariables/src/Versions.kt @@ -38,7 +38,7 @@ enum class Versions( yarn("1.16.2+build.47"), MappingStyle.YARN, null, - "0.20.1+build.401-1.16", + "0.42.0+1.16", "MC12006" ), MC12006( diff --git a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java index 2b65282..12eedba 100644 --- a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java +++ b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java @@ -3,7 +3,7 @@ package moe.nea.ultranotifier.mixin; import moe.nea.ultranotifier.event.ChatGuiLineEvent; import moe.nea.ultranotifier.event.UltraNotifierEvents; import net.minecraft.client.gui.hud.ChatHud; -//#if MC > 11404 +//#if MC >= 1.20 import net.minecraft.client.gui.hud.MessageIndicator; import net.minecraft.network.message.MessageSignatureData; //#endif @@ -18,22 +18,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; ) public class ChatHudMessageAdded { @Inject( -//#if MC <= 11404 -//#if FORGE -//$$ method = "printChatMessageWithOptionalDeletion", -//#else -//$$ method = "addMessage(Lnet/minecraft/text/Text;I)V", -//#endif -//#else +//#if MC >= 1.20 method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", +//#elseif MC >= 1.16 +//$$ method = "addMessage(Lnet/minecraft/text/Text;IIZ)V", +//#else +//$$ method = "printChatMessageWithOptionalDeletion", //#endif at = @At("HEAD"), cancellable = true) private void onAddMessage( Text message, -//#if MC <= 11404 -//$$ int chatLineId, -//#else +//#if MC >= 1.20 MessageSignatureData signatureData, MessageIndicator indicator, +//#elseif MC >= 1.16 +//$$ int chatLineId, int timestamp, boolean bl, +//#else +//$$ int chatLineId, //#endif CallbackInfo ci ) { 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 = 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 @@ -30,6 +36,16 @@ object ChatStore : SubscriptionTarget { insertChatLine(event.component).isDisplayed = true } + @UltraSubscribe + fun registerCommands(event: CommandRegistrationEvent) { + event.dispatcher.register(LiteralArgumentBuilder.literal("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, //$$ val node: CommandNode //$$) : 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) = "${node.name} ${args.joinToString(" ")}".trim() +//$$ +//$$ +//#if MC < 1.12 +//$$ override fun processCommand(sender: ICommandSender, args: Array) { +//#else //$$ override fun execute(server: MinecraftServer, sender: ICommandSender, args: Array) { +//#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 + } + } +} diff --git a/versions/mapping-1.12.2-1.8.9.txt b/versions/mapping-1.12.2-1.8.9.txt new file mode 100644 index 0000000..9551655 --- /dev/null +++ b/versions/mapping-1.12.2-1.8.9.txt @@ -0,0 +1,2 @@ +net.minecraftforge.event.TickEvent net.minecraftforge.fml.common.gameevent.TickEvent +net.minecraftforge.event.TickEvent$ClientTickEvent net.minecraftforge.fml.common.gameevent.TickEvent$ClientTickEvent diff --git a/versions/mapping-1.14.4-1.14.4-forge.txt b/versions/mapping-1.14.4-1.14.4-forge.txt deleted file mode 100644 index e69de29..0000000 diff --git a/versions/mapping-1.14.4-forge-1.8.9.txt b/versions/mapping-1.14.4-forge-1.8.9.txt deleted file mode 100644 index 2c4adf0..0000000 --- a/versions/mapping-1.14.4-forge-1.8.9.txt +++ /dev/null @@ -1,7 +0,0 @@ -net.minecraft.client.gui.NewChatGui net.minecraft.client.gui.GuiNewChat -net.minecraft.util.text.ITextComponent net.minecraft.util.IChatComponent -net.minecraft.util.text.ITextComponent getString() getUnformattedText() -net.minecraftforge.eventbus.api.Event net.minecraftforge.fml.common.eventhandler.Event -net.minecraftforge.eventbus.api.SubscribeEvent net.minecraftforge.fml.common.eventhandler.SubscribeEvent -net.minecraft.client.gui.screen.Screen net.minecraft.client.gui.GuiScreen -com.mojang.blaze3d.platform.GlStateManager net.minecraft.client.renderer.GlStateManager \ No newline at end of file diff --git a/versions/mapping-1.16.2-forge-1.12.2.txt b/versions/mapping-1.16.2-forge-1.12.2.txt new file mode 100644 index 0000000..f0d15d6 --- /dev/null +++ b/versions/mapping-1.16.2-forge-1.12.2.txt @@ -0,0 +1,6 @@ +net.minecraft.network.chat.Component net.minecraft.util.text.ITextComponent +net.minecraft.network.chat.Component getString() getUnformattedText() +net.minecraftforge.eventbus.api.Event net.minecraftforge.fml.common.eventhandler.Event +net.minecraftforge.eventbus.api.SubscribeEvent net.minecraftforge.fml.common.eventhandler.SubscribeEvent +net.minecraft.client.gui.screens.Screen net.minecraft.client.gui.GuiScreen + diff --git a/versions/mapping-1.20.6-1.14.4.txt b/versions/mapping-1.20.6-1.14.4.txt deleted file mode 100644 index e69de29..0000000 -- cgit