diff --git a/build.gradle.kts b/build.gradle.kts index 66a79ba..44029b3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -80,10 +80,15 @@ dependencies { mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") + implementation("com.google.code.gson:gson:2.11.0") + shadowImpl(kotlin("stdlib-jdk8")) // If you don't want mixins, remove these lines - compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") + shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") { + isTransitive = false + } + annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT") // If you don't want to log in with your real minecraft account, remove this line runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:1.1.2") diff --git a/src/main/java/live/ixnoah/tapactions/mixin/MixinNetHandlerPlayClient.java b/src/main/java/live/ixnoah/tapactions/mixin/MixinNetHandlerPlayClient.java index 3c8f3ad..c257ab8 100644 --- a/src/main/java/live/ixnoah/tapactions/mixin/MixinNetHandlerPlayClient.java +++ b/src/main/java/live/ixnoah/tapactions/mixin/MixinNetHandlerPlayClient.java @@ -1,8 +1,12 @@ package live.ixnoah.tapactions.mixin; +import live.ixnoah.tapactions.actions.HudActions; import live.ixnoah.tapactions.misc.TitleHandler; +import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.play.server.S45PacketTitle; +import net.minecraft.network.play.server.S47PacketPlayerListHeaderFooter; +import net.minecraft.util.ChatComponentText; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,4 +18,13 @@ public class MixinNetHandlerPlayClient { public void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) { TitleHandler.INSTANCE.handleTitle(packetIn, ci); } + + @Inject(method = "handlePlayerListHeaderFooter", at = @At("TAIL")) + public void handlePlayerListHeaderFooter(S47PacketPlayerListHeaderFooter event, CallbackInfo ci) { + if (HudActions.INSTANCE.getModifyTablist()) { + Minecraft.getMinecraft().ingameGUI.getTabList().setFooter( + new ChatComponentText("\n" + HudActions.INSTANCE.getTablistFooter() + "\n") + ); + } + } } \ No newline at end of file diff --git a/src/main/kotlin/live/ixnoah/tapactions/TapActions.kt b/src/main/kotlin/live/ixnoah/tapactions/TapActions.kt index 902e9ee..0b9236d 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/TapActions.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/TapActions.kt @@ -1,5 +1,8 @@ package live.ixnoah.tapactions +import com.google.gson.Gson +import com.google.gson.JsonArray +import com.google.gson.JsonObject import live.ixnoah.tapactions.actions.GeneralActions import live.ixnoah.tapactions.actions.HudActions import live.ixnoah.tapactions.actions.WorldActions @@ -10,11 +13,22 @@ import net.minecraftforge.client.ClientCommandHandler import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent +import java.io.InputStreamReader +import java.net.URL + @Mod(modid = "tapactions", useMetadata = true) class TapActions { companion object ModInfo { const val MOD_ID = "tapactions" + const val MOD_VER = "0.0.1" + + var outdated = false + var newerVersion = MOD_VER + } + + private fun versionParser(semver: String): Int { + return (semver.replace(Regex("\\D+"), "").toIntOrNull() ?: 0) / 10 // div by 10 to exclude patches } @Mod.EventHandler @@ -30,5 +44,25 @@ class TapActions { GeneralActions.deploy() WorldActions.deploy() HudActions.deploy() + + val thread = Thread { + try { + val url = URL("https://api.modrinth.com/v2/project/ZtvPWsL6/version?featured=true") + val apiResponse = Gson().fromJson(InputStreamReader(url.openStream()), JsonArray::class.java) + + val latestVersion = apiResponse.get(0) as JsonObject + val versionNumber = latestVersion.get("version_number").asString + + if (versionParser(versionNumber) > versionParser(MOD_VER)) { + newerVersion = versionNumber + outdated = true + } + + + } catch (e: Exception) { + throw RuntimeException(e) + } + } + thread.start() } } diff --git a/src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt b/src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt index 224987d..23a3c2c 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt @@ -4,7 +4,7 @@ import live.ixnoah.tapactions.ActionManager import net.minecraft.entity.boss.BossStatus object HudActions { - private fun actionBossbar( params : MutableMap) { + private fun actionBossbar( params : MutableMap ) { if (params["no-clear"] == null) { BossStatus.statusBarTime = Int.MAX_VALUE BossStatus.healthScale = 1f @@ -26,7 +26,17 @@ object HudActions { if (params["duration"]?.toFloatOrNull() != null) BossStatus.statusBarTime = ((params["duration"]?.toFloat() ?: 1f) * 60).toInt() } + public var modifyTablist = false + public var tablistFooter = "No valid footer found :(" + private fun actionTablist( params: MutableMap ) { + modifyTablist = true + if (params["restore"] !== null) modifyTablist = false // This will reset it ASAP + + tablistFooter = params["footer"]!!.replace(Regex("&(?=[0-9a-fk-o])"), "§").replace("\\n", "\n") + } + fun deploy() { ActionManager.registerAction("tap:bossbar", ::actionBossbar) + ActionManager.registerAction("tap:tablist", ::actionTablist, mutableListOf("footer")) } } \ No newline at end of file diff --git a/src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt b/src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt index 082e234..31a2f54 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt @@ -1,7 +1,10 @@ package live.ixnoah.tapactions.events import CommandQueue +import live.ixnoah.tapactions.actions.HudActions import live.ixnoah.tapactions.actions.WorldActions +import net.minecraft.client.Minecraft +import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent diff --git a/src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt b/src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt index f7514f2..edb0641 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt @@ -1,9 +1,15 @@ package live.ixnoah.tapactions.events import CommandQueue +import live.ixnoah.tapactions.TapActions import live.ixnoah.tapactions.actions.GeneralActions +import live.ixnoah.tapactions.actions.HudActions import net.minecraft.client.Minecraft import net.minecraft.entity.boss.BossStatus +import net.minecraft.event.ClickEvent +import net.minecraft.event.HoverEvent +import net.minecraft.util.ChatComponentText +import net.minecraft.util.ChatStyle import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -16,5 +22,19 @@ class WorldLoad { CommandQueue.clearQueue() GeneralActions.hasStatedIdentity = false + HudActions.modifyTablist = false + HudActions.tablistFooter = "No valid footer found :(" + + if (TapActions.outdated) { + Minecraft.getMinecraft().thePlayer.addChatMessage( + ChatComponentText("\n§e§l[!]§f TapActions is quite outdated, houses may break! §e§nClick to update§r! §7(${TapActions.MOD_VER} => ${TapActions.newerVersion})\n") + .setChatStyle(ChatStyle() + .setChatClickEvent(ClickEvent(ClickEvent.Action.OPEN_URL, "https://modrinth.com/mod/tapactions/versions")) + .setChatHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("§7https://modrinth.com/mod/tapactions"))) + ) + ) + + TapActions.outdated = false + } } } diff --git a/src/main/resources/assets/bars.png b/src/main/resources/assets/bars.png new file mode 100644 index 0000000..83fc4f8 Binary files /dev/null and b/src/main/resources/assets/bars.png differ