diff --git a/build.gradle.kts b/build.gradle.kts index d0d5f4d..467128d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,18 +1,18 @@ @file:Suppress("UnstableApiUsage", "PropertyName") -import cc.polyfrost.gradle.util.noServerRunConfigs import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.polyfrost.gradle.util.noServerRunConfigs // Adds support for kotlin, and adds the Polyfrost Gradle Toolkit // which we use to prepare the environment. plugins { kotlin("jvm") - id("cc.polyfrost.multi-version") - id("cc.polyfrost.defaults.repo") - id("cc.polyfrost.defaults.java") - id("cc.polyfrost.defaults.loom") + id("org.polyfrost.multi-version") + id("org.polyfrost.defaults.repo") + id("org.polyfrost.defaults.java") + id("org.polyfrost.defaults.loom") id("com.github.johnrengelman.shadow") - id("net.kyori.blossom") version "1.3.0" + id("net.kyori.blossom") version "1.3.1" id("signing") java } @@ -39,7 +39,7 @@ blossom { version = mod_version // Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username. // e.g. com.github. or com. -group = "me.redth" +group = "org.polyfrost" // Sets the name of the output jar (the one you put in your mods folder and send to other people) // It outputs all versions of the mod into the `build` directory. @@ -53,16 +53,13 @@ loom { // If you're developing a server-side mod, you can remove this line. noServerRunConfigs() - // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.cc) + // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org) if (project.platform.isLegacyForge) { - launchConfigs.named("client") { - arg("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker") - - // This is enabled so OneConfig can read our Mixins and automatically apply them. - property( - "mixin.debug.export", - "true" - ) + runConfigs { + "client" { + programArgs("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker") + property("mixin.debug.export", "true") + } } } // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects. @@ -84,20 +81,28 @@ val shade: Configuration by configurations.creating { sourceSets { val dummy by creating main { - output.setResourcesDir(java.classesDirectory) + dummy.compileClasspath += compileClasspath compileClasspath += dummy.output + output.setResourcesDir(java.classesDirectory) } } // Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod. repositories { - maven("https://repo.polyfrost.cc/releases") + maven("https://repo.polyfrost.org/releases") } // Configures the libraries/dependencies for your mod. dependencies { // Adds the OneConfig library, so we can develop with it. - modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.0-alpha+") + modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.1-alpha+") + + val loaderPlatform = when { + platform.isFabric -> "fabric" + platform.isLegacyForge -> "forge-legacy" + else -> "forge-latest" + } + modRuntimeOnly("me.djtheredstoner:DevAuth-$loaderPlatform:1.1.2") // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier. if (platform.isLegacyForge) { compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") @@ -111,14 +116,10 @@ tasks { processResources { inputs.property("id", mod_id) inputs.property("name", mod_name) - val java = if (project.platform.mcMinor >= 18) { - 17 // If we are playing on version 1.18, set the java version to 17 - } else { - // Else if we are playing on version 1.17, use java 16. - if (project.platform.mcMinor == 17) - 16 - else - 8 // For all previous versions, we **need** java 8 (for Forge support). + val java = when (project.platform.mcMinor) { + in 18..99 -> 17 // If we are playing on version 1.18, set the java version to 17 + 17 -> 16 // Else if we are playing on version 1.17, use java 16. + else -> 8 // For all previous versions, we **need** java 8 (for Forge support). } val compatLevel = "JAVA_${java}" inputs.property("java", java) @@ -174,7 +175,7 @@ tasks { } remapJar { - input.set(shadowJar.get().archiveFile) + inputFile.set(shadowJar.get().archiveFile) archiveClassifier.set("") } @@ -185,7 +186,7 @@ tasks { "ModSide" to "CLIENT", // We aren't developing a server-side mod, so this is fine. "ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so. "TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible. - "MixinConfigs" to "mixin.${mod_id}.json", // We want to use our mixin configuration, so we specify it here. + "MixinConfigs" to "mixins.${mod_id}.json", // We want to use our mixin configuration, so we specify it here. "TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper. ) } diff --git a/gradle.properties b/gradle.properties index 0d7847d..c2e3e9a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ mod_name=MMCUtils # Sets the id of your mod that mod loaders use to recognize it. mod_id=mmcutils # Sets the version of your mod. Make sure to update this when you make changes according to semver. -mod_version=0.1.9 +mod_version=0.2.0 # Sets the name of the jar file that you put in your 'mods' folder. mod_archives_name=MMCUtils diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 819d2a6..3fa8f86 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists - -networkTimeout=30000 diff --git a/root.gradle.kts b/root.gradle.kts index f7289ec..d641543 100644 --- a/root.gradle.kts +++ b/root.gradle.kts @@ -1,9 +1,11 @@ plugins { - kotlin("jvm") version "1.6.21" apply false - id("cc.polyfrost.multi-version.root") + kotlin("jvm") version "1.8.22" apply false + id("org.polyfrost.multi-version.root") id("com.github.johnrengelman.shadow") version "7.1.2" apply false } preprocess { +// "1.12.2-forge"(11202, "srg") { "1.8.9-forge"(10809, "srg") -} \ No newline at end of file +// } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index b57ea41..cc35c6a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,11 +4,11 @@ pluginManagement { repositories { gradlePluginPortal() mavenCentral() - maven("https://repo.polyfrost.cc/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit + maven("https://repo.polyfrost.org/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit } plugins { - val pgtVersion = "0.1.28" // Sets the default versions for Polyfrost Gradle Toolkit - id("cc.polyfrost.multi-version.root") version pgtVersion + val pgtVersion = "0.2.9" // Sets the default versions for Polyfrost Gradle Toolkit + id("org.polyfrost.multi-version.root") version pgtVersion } } @@ -21,6 +21,7 @@ rootProject.buildFileName = "root.gradle.kts" // Adds all of our build target versions to the classpath if we need to add version-specific code. listOf( "1.8.9-forge", // Update this if you want to remove/add a version, along with `build.gradle.kts` and `root.gradle.kts`. +// "1.12.2-forge" ).forEach { version -> include(":$version") project(":$version").apply { diff --git a/src/dummy/java/net/optifine/render/RenderEnv.java b/src/dummy/java/net/optifine/render/RenderEnv.java index bda01f6..5fddc48 100644 --- a/src/dummy/java/net/optifine/render/RenderEnv.java +++ b/src/dummy/java/net/optifine/render/RenderEnv.java @@ -1,4 +1,4 @@ package net.optifine.render; -public interface RenderEnv { +public class RenderEnv { } diff --git a/src/main/java/me/redth/mmcutils/mixin/BlockModelRendererMixin.java b/src/main/java/me/redth/mmcutils/mixin/BlockModelRendererMixin.java index 8848a41..c15e9f7 100644 --- a/src/main/java/me/redth/mmcutils/mixin/BlockModelRendererMixin.java +++ b/src/main/java/me/redth/mmcutils/mixin/BlockModelRendererMixin.java @@ -1,6 +1,6 @@ package me.redth.mmcutils.mixin; -import me.redth.mmcutils.Hooks; +import me.redth.mmcutils.core.Core; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.BlockModelRenderer; import net.minecraft.client.renderer.WorldRenderer; @@ -19,8 +19,16 @@ @Mixin(BlockModelRenderer.class) public abstract class BlockModelRendererMixin { @Dynamic("optifine") - @ModifyArgs(method = "renderQuadsSmooth", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/WorldRenderer;putColorMultiplier(FFFI)V")) - public void modifyArgs(Args args, IBlockAccess worldIn, IBlockState stateIn, BlockPos blockPosIn, WorldRenderer instance, List list, RenderEnv env) { - Hooks.INSTANCE.modifyArgs(args, stateIn, blockPosIn); + @ModifyArgs( + remap = false, + method = "renderQuadsSmooth", + at = @At( + value = "INVOKE", + remap = true, + target = "Lnet/minecraft/client/renderer/WorldRenderer;putColorMultiplier(FFFI)V" + ) + ) + private void mmcUtils$modifyShadow(Args args, IBlockAccess worldIn, IBlockState stateIn, BlockPos blockPosIn, WorldRenderer instance, List list, RenderEnv env) { + Core.INSTANCE.modifyArgs(args, stateIn, blockPosIn); } } diff --git a/src/main/kotlin/me/redth/mmcutils/Hooks.kt b/src/main/kotlin/me/redth/mmcutils/Hooks.kt deleted file mode 100644 index 3176cb5..0000000 --- a/src/main/kotlin/me/redth/mmcutils/Hooks.kt +++ /dev/null @@ -1,22 +0,0 @@ -package me.redth.mmcutils - -import me.redth.mmcutils.config.ModConfig -import net.minecraft.block.BlockColored -import net.minecraft.block.state.IBlockState -import net.minecraft.util.BlockPos -import org.spongepowered.asm.mixin.injection.invoke.arg.Args - -object Hooks { - fun modifyArgs(args: Args, stateIn: IBlockState, blockPosIn: BlockPos) { - if (!MMCUtils.inBridgingGame) return - if (!ModConfig.heightLimitOverlay) return - if (blockPosIn.y != 99) return - if (stateIn.block !is BlockColored) return - val meta = stateIn.getValue(BlockColored.COLOR).metadata - if (meta != 14 && meta != 11) return - val brightness = 1f - ModConfig.heightLimitDarkness / 10f - for (i in 0..2) { - args.set(i, args.get(i) * brightness) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/me/redth/mmcutils/MMCUtils.kt b/src/main/kotlin/me/redth/mmcutils/MMCUtils.kt index 21b55ab..2985373 100644 --- a/src/main/kotlin/me/redth/mmcutils/MMCUtils.kt +++ b/src/main/kotlin/me/redth/mmcutils/MMCUtils.kt @@ -1,113 +1,21 @@ package me.redth.mmcutils -import cc.polyfrost.oneconfig.libs.universal.ChatColor +import me.redth.mmcutils.core.Core import me.redth.mmcutils.config.ModConfig -import net.minecraft.client.Minecraft -import net.minecraft.scoreboard.ScorePlayerTeam -import net.minecraftforge.client.event.ClientChatReceivedEvent -import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent -import java.util.Timer -import kotlin.concurrent.schedule @Mod(modid = MMCUtils.MODID, name = MMCUtils.NAME, version = MMCUtils.VERSION, modLanguageAdapter = "cc.polyfrost.oneconfig.utils.KotlinLanguageAdapter") object MMCUtils { const val MODID = "@ID@" const val NAME = "@NAME@" const val VERSION = "@VER@" - private val ALL_PROXY = arrayOf("AS Practice", "EU Practice", "NA Practice", "SA Practice") - private val BRIDGING_GAMES = arrayOf("Bed Fight", "Fireball Fight", "Bridges", "Battle Rush") - private val mc = Minecraft.getMinecraft() - - var checkedScoreboard = false - var inPractice = false - var inPartyChat = false - var inBridgingGame = false @Mod.EventHandler fun init(e: FMLInitializationEvent) { - MinecraftForge.EVENT_BUS.register(this) - ModConfig.initialize() - } - - @SubscribeEvent - fun onQuit(e: ClientDisconnectionFromServerEvent) { - inBridgingGame = false - inPartyChat = false - inPractice = false - checkedScoreboard = false - } - - @SubscribeEvent - fun onChat(e: ClientChatReceivedEvent) { - val cleanText = e.message.unformattedText!! - - scheduleCheckScoreboard(cleanText) - - if (!inPractice) return - - tryPartyChat(cleanText) - checkBridgingGame(cleanText) - checkGameEnd(cleanText) - } - - @SubscribeEvent - fun preventTablist(e: RenderGameOverlayEvent.Pre) { - if (!ModConfig.disablePlayerList) return - if (e.type != RenderGameOverlayEvent.ElementType.PLAYER_LIST) return - if (!inPractice) return - e.isCanceled = true - } - - private fun tryPartyChat(chat: String) { - if (inPartyChat) return - if (chat !in ALL_PROXY) return - if (!ModConfig.autoPartyChat) return - - mc.thePlayer.sendChatMessage("/p chat") - inPartyChat = true - } - - private fun checkBridgingGame(chat: String) { - if (inBridgingGame) return - if (chat !in BRIDGING_GAMES) return - - inBridgingGame = true - } - - private fun checkGameEnd(chat: String) { - if (!chat.startsWith("Match Results")) return - - if (inBridgingGame) inBridgingGame = false - - if (ModConfig.autoGG) mc.thePlayer.sendChatMessage(ModConfig.autoGGText) - } - - private fun scheduleCheckScoreboard(chat: String) { - if (checkedScoreboard) return - if (inPractice) return - if (chat != "Minemen Club") return - if (!ModConfig.autoQueue) return - - Timer().schedule(1000L) { checkScoreboard() } + MinecraftForge.EVENT_BUS.register(Core) + ModConfig } - private fun checkScoreboard() { - checkedScoreboard = true - val scoreboard = mc.theWorld.scoreboard ?: return - val objective = scoreboard.getObjectiveInDisplaySlot(1) ?: return - for (score in scoreboard.getSortedScores(objective)) { - val team = scoreboard.getPlayersTeam(score.playerName) ?: continue - val text = ChatColor.stripColorCodes(ScorePlayerTeam.formatPlayerName(team, score.playerName))?: continue - val mmcProxy = text.split(".minemen.club").firstOrNull() ?: continue - if (mmcProxy.length != 2) continue - mc.thePlayer.sendChatMessage("/joinqueue $mmcProxy-practice") - inPractice = true - break - } - } } \ No newline at end of file diff --git a/src/main/kotlin/me/redth/mmcutils/config/HeightLimitHud.kt b/src/main/kotlin/me/redth/mmcutils/config/HeightLimitHud.kt index afc89ed..910324a 100644 --- a/src/main/kotlin/me/redth/mmcutils/config/HeightLimitHud.kt +++ b/src/main/kotlin/me/redth/mmcutils/config/HeightLimitHud.kt @@ -1,14 +1,14 @@ package me.redth.mmcutils.config import cc.polyfrost.oneconfig.hud.SingleTextHud -import me.redth.mmcutils.MMCUtils -import net.minecraft.client.Minecraft +import cc.polyfrost.oneconfig.utils.dsl.mc +import me.redth.mmcutils.core.Core class HeightLimitHud : SingleTextHud("Height Limit Distance", false) { - override fun getText(example: Boolean) = if (MMCUtils.inBridgingGame) { - val distance = 100 - Minecraft.getMinecraft().thePlayer.posY.toInt() + override fun getText(example: Boolean) = if (Core.inBridgingGame) { + val distance = 100 - mc.thePlayer.posY.toInt() distance.toString() } else "3" - override fun shouldShow() = super.shouldShow() && MMCUtils.inBridgingGame + override fun shouldShow() = super.shouldShow() && Core.inBridgingGame } \ No newline at end of file diff --git a/src/main/kotlin/me/redth/mmcutils/core/Core.kt b/src/main/kotlin/me/redth/mmcutils/core/Core.kt new file mode 100644 index 0000000..e307168 --- /dev/null +++ b/src/main/kotlin/me/redth/mmcutils/core/Core.kt @@ -0,0 +1,93 @@ +package me.redth.mmcutils.core + +import cc.polyfrost.oneconfig.utils.dsl.mc +import me.redth.mmcutils.config.ModConfig +import net.minecraft.block.BlockColored +import net.minecraft.block.state.IBlockState +import net.minecraft.util.BlockPos +import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.network.FMLNetworkEvent +import org.spongepowered.asm.mixin.injection.invoke.arg.Args + +object Core { + private val ALL_PROXY = listOf("AS Practice", "EU Practice", "NA Practice", "SA Practice") + private val BRIDGING_GAMES = listOf("Bed Fight", "Fireball Fight", "Bridges", "Battle Rush") + private var checkedFirstMessage = false + private var checkedScoreboard = false + private var inPractice = false + private var inPartyChat = false + var inBridgingGame = false + + fun modifyArgs(args: Args, stateIn: IBlockState, blockPosIn: BlockPos) { + if (!inBridgingGame) return + if (!ModConfig.heightLimitOverlay) return + if (blockPosIn.y != 99) return + if (stateIn.block !is BlockColored) return + val meta = stateIn.getValue(BlockColored.COLOR).metadata + if (meta != 14 && meta != 11) return + val brightness = 1f - ModConfig.heightLimitDarkness / 10f + for (i in 0..2) { + args.set(i, args.get(i) * brightness) + } + } + + @SubscribeEvent + fun onQuit(e: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { + checkedFirstMessage = false + inBridgingGame = false + inPartyChat = false + inPractice = false + checkedScoreboard = false + } + + @SubscribeEvent + fun onChat(e: ClientChatReceivedEvent) { + val cleanText = e.message.unformattedText.trim() + if (cleanText.isEmpty()) return + + if (!checkedFirstMessage) { + checkedFirstMessage = true + inPractice = cleanText in ALL_PROXY + return + } + + if (!inPractice) return + + tryPartyChat() + checkBridgingGame(cleanText) + checkGameEnd(cleanText) + } + + @SubscribeEvent + fun preventTablist(e: RenderGameOverlayEvent.Pre) { + if (!ModConfig.disablePlayerList) return + if (e.type != RenderGameOverlayEvent.ElementType.PLAYER_LIST) return + if (!inPractice) return + e.isCanceled = true + } + + private fun tryPartyChat() { + if (!ModConfig.autoPartyChat) return + if (inPartyChat) return + + mc.thePlayer.sendChatMessage("/p chat") + inPartyChat = true + } + + private fun checkBridgingGame(chat: String) { + if (inBridgingGame) return + if (chat !in BRIDGING_GAMES) return + + inBridgingGame = true + } + + private fun checkGameEnd(chat: String) { + if (!chat.startsWith("Match Results")) return + + if (inBridgingGame) inBridgingGame = false + + if (ModConfig.autoGG) mc.thePlayer.sendChatMessage(ModConfig.autoGGText) + } +} \ No newline at end of file