Skip to content

Commit

Permalink
Major code quality + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ixnoahlive committed Jun 8, 2024
1 parent b6159fb commit 2ac4c33
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id("gg.essential.loom") version "0.10.0.+"
id("dev.architectury.architectury-pack200") version "0.1.3"
id("com.github.johnrengelman.shadow") version "8.1.1"
kotlin("jvm") version "1.8.21"
kotlin("jvm") version "2.0.0"
}

//Constants:
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/live/ixnoah/tapactions/ActionManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object ActionManager {
val definedParams = params?.keys
val missingParams = mutableListOf<String>()

if (definedParams !== null && action.paramsRequired?.isNotEmpty() == true) {
if (definedParams != null && action.paramsRequired?.isNotEmpty() == true) {
action.paramsRequired.forEach { paramName ->
if (!definedParams.contains(paramName)) missingParams.add(paramName)
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/kotlin/live/ixnoah/tapactions/actions/GeneralActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object GeneralActions {
var hasStatedIdentity = false

/** This can be used to show the identity of a house, like name, links & description! */
private val actionIdentity = { params : MutableMap<String, String> ->
private fun actionIdentity( params : MutableMap<String, String>) {
if (!hasStatedIdentity) {
hasStatedIdentity = true
val paramName = params["name"] ?: "Housing"
Expand All @@ -24,21 +24,21 @@ object GeneralActions {
Scoreboard.setTitle("§e§l" + paramName.uppercase())
}

if (params["run"] !== null) {
if (params["run"] != null) {
CommandQueue.pushCommand("house:${params["run"]}")
}
}
}

private val actionVisibility = { params : MutableMap<String, String> ->
private fun actionVisibility ( params : MutableMap<String, String> ) {
val paramVis : Int? = params["max"]?.toIntOrNull()

if (paramVis !== null) {
if (paramVis != null) {
CommandQueue.pushCommand("visibility $paramVis")
}
}

private val actionVisitHouse = { params: MutableMap<String, String> ->
private fun actionVisitHouse( params: MutableMap<String, String> ) {
Minecraft.getMinecraft().thePlayer.addChatMessage(
ChatComponentText("§eThis house wants you to visit §b${params["house"]}§e! Click to visit!")
// This is fucking awful but Minecraft devs has forced my hand
Expand All @@ -50,8 +50,8 @@ object GeneralActions {
}

fun deploy() {
ActionManager.registerAction("tap:identity", actionIdentity)
ActionManager.registerAction("tap:visibility", actionVisibility, mutableListOf("max"))
ActionManager.registerAction("tap:visit", actionVisitHouse, mutableListOf("player", "house"))
ActionManager.registerAction("tap:identity", ::actionIdentity)
ActionManager.registerAction("tap:visibility", ::actionVisibility, mutableListOf("max"))
ActionManager.registerAction("tap:visit", ::actionVisitHouse, mutableListOf("player", "house"))
}
}
18 changes: 10 additions & 8 deletions src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ import live.ixnoah.tapactions.ActionManager
import net.minecraft.entity.boss.BossStatus

object HudActions {
private val 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
BossStatus.bossName = ""
}

var max_health = 100
var maxHealth = 100

if (params["name"] !== null) BossStatus.bossName = params["name"]
if (params["max_health"]?.toIntOrNull() !== null) max_health = params["max_health"]?.toInt() ?: 100
if (params["name"] != null) BossStatus.bossName = params["name"]
if (params["max_health"]?.toIntOrNull() != null) maxHealth = params["max_health"]?.toInt() ?: 100

var healthScale = ( params["health"]?.toInt() ?: 100 ).toFloat() / max_health.toFloat()
var healthScale = ( params["health"]?.toInt() ?: 100 ).toFloat() / maxHealth.toFloat()
if (healthScale > 1 || healthScale < 0) healthScale = 1f

BossStatus.healthScale = healthScale
if (params["no-clear"] == null
|| params["health"] != null
|| params["max_health"] != null) BossStatus.healthScale = healthScale

if (params["duration"]?.toFloatOrNull() !== null) BossStatus.statusBarTime = ((params["duration"]?.toFloat() ?: 1f) * 60).toInt()
if (params["duration"]?.toFloatOrNull() != null) BossStatus.statusBarTime = ((params["duration"]?.toFloat() ?: 1f) * 60).toInt()
}

fun deploy() {
ActionManager.registerAction("tap:bossbar", actionBossbar)
ActionManager.registerAction("tap:bossbar", ::actionBossbar)
}
}
39 changes: 20 additions & 19 deletions src/main/kotlin/live/ixnoah/tapactions/actions/WorldActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ import net.minecraft.client.Minecraft
import net.minecraft.util.EnumParticleTypes

object WorldActions {
private val actionParticle = { params: MutableMap<String, String> ->
val particleType = params["particle"]?.let { EnumParticleTypes.valueOf(it) }
var particlesRendered = 0
private fun actionParticle(params: MutableMap<String, String>) {
if (particlesRendered > 100) return
if (EnumParticleTypes.entries.none { it.name == params["type"] }) return

if (particleType !== null) {
Minecraft.getMinecraft().theWorld.spawnParticle(
val particleType = EnumParticleTypes.valueOf(params["type"]!!)

val xyz = params["pos"]?.split(" ")?.map { item -> item.toDoubleOrNull() }
val pos = mutableMapOf(
"x" to (xyz?.get(0) ?: 0.00),
"y" to (xyz?.get(1) ?: 0.00),
"z" to (xyz?.get(2) ?: 0.00),
)

Minecraft.getMinecraft().theWorld.spawnParticle(
particleType,
params["x"]?.toDoubleOrNull() ?: 0.00,
params["y"]?.toDoubleOrNull() ?: 0.00,
params["z"]?.toDoubleOrNull() ?: 0.00,
params["ox"]?.toDoubleOrNull() ?: 0.00,
params["oy"]?.toDoubleOrNull() ?: 0.00,
params["oz"]?.toDoubleOrNull() ?: 0.00,
)
}
pos["x"]!!, pos["y"]!!, pos["z"]!!,
0.00, 0.00, 0.00
)

particlesRendered++
}

fun deploy() {
ActionManager.registerAction(
"tap:particle",
actionParticle,
mutableListOf(
"particle",
"x", "y", "z",
))
ActionManager.registerAction("tap:particle", ::actionParticle, mutableListOf("type", "pos" ))
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package live.ixnoah.tapactions.events

import CommandQueue
import live.ixnoah.tapactions.actions.WorldActions
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent

Expand All @@ -13,5 +14,6 @@ class ClientTick {
tick += 1

CommandQueue.onTick(tick)
WorldActions.particlesRendered = 0
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class WorldLoad {
@SubscribeEvent
fun onEvent(event: EntityJoinWorldEvent) {
if (event.entity !== Minecraft.getMinecraft().thePlayer) return
if (event.entity != Minecraft.getMinecraft().thePlayer) return

BossStatus.statusBarTime = 0 // clears the bossbar
CommandQueue.clearQueue()
GeneralActions.hasStatedIdentity = false

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo

object TitleHandler {
fun handleTitle(packetIn: S45PacketTitle, ci: CallbackInfo) {
if (packetIn.type.toString() !== "TITLE") return
if (packetIn.type.toString() != "TITLE") return
var messageContent = packetIn.message.unformattedText
if (!messageContent.startsWith("")) return

Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/assets/test/test.txt

This file was deleted.

0 comments on commit 2ac4c33

Please sign in to comment.