Skip to content

Commit

Permalink
Almost all features for Beta 2!
Browse files Browse the repository at this point in the history
  • Loading branch information
ixnoahlive committed Jun 15, 2024
1 parent f755b68 commit 45947a7
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 2 deletions.
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")
);
}
}
}
34 changes: 34 additions & 0 deletions src/main/kotlin/live/ixnoah/tapactions/TapActions.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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()
}
}
12 changes: 11 additions & 1 deletion src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import live.ixnoah.tapactions.ActionManager
import net.minecraft.entity.boss.BossStatus

object HudActions {
private fun actionBossbar( params : MutableMap<String, String>) {
private fun actionBossbar( params : MutableMap<String, String> ) {
if (params["no-clear"] == null) {
BossStatus.statusBarTime = Int.MAX_VALUE
BossStatus.healthScale = 1f
Expand All @@ -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<String, String> ) {
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"))
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
}
}
}
Binary file added src/main/resources/assets/bars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 45947a7

Please sign in to comment.