Skip to content

Commit

Permalink
Implement identity return command, visibility action and more.
Browse files Browse the repository at this point in the history
  • Loading branch information
ixnoahlive committed Jun 7, 2024
1 parent b7fd371 commit 9a4d327
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/main/kotlin/live/ixnoah/tapactions/TapActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package live.ixnoah.tapactions

import live.ixnoah.tapactions.actions.GeneralActions
import live.ixnoah.tapactions.actions.HudActions
import live.ixnoah.tapactions.commands.CreateCommand
import live.ixnoah.tapactions.commands.CreateActionCommand
import live.ixnoah.tapactions.events.ClientTick
import live.ixnoah.tapactions.events.WorldLoad
import net.minecraft.client.Minecraft
import net.minecraftforge.client.ClientCommandHandler
Expand All @@ -26,13 +27,14 @@ class TapActions {
throw java.lang.RuntimeException(e)
}
// Commands
ClientCommandHandler.instance.registerCommand(CreateCommand())
ClientCommandHandler.instance.registerCommand(CreateActionCommand())

// Events
MinecraftForge.EVENT_BUS.register(WorldLoad())
MinecraftForge.EVENT_BUS.register(ClientTick())

// Deploy actions
GeneralActions().deploy()
HudActions().deploy()
GeneralActions.deploy()
HudActions.deploy()
}
}
28 changes: 23 additions & 5 deletions src/main/kotlin/live/ixnoah/tapactions/actions/GeneralActions.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
package live.ixnoah.tapactions.actions

import CommandQueue
import live.ixnoah.tapactions.ActionManager
import live.ixnoah.tapactions.wrappers.Scoreboard

class GeneralActions {
object GeneralActions {
private val nameRegex = Regex("^[0-9A-z '\"!@#\$%^*?]{0,20}\$")
var hasStatedIdentity = false

/** This can be used to show the identity of a house, like name, links & description! :D */
/** This can be used to show the identity of a house, like name, links & description! */
private val actionIdentity = { params : MutableMap<String, String> ->
val paramName = params["name"] ?: "Housing"
if (!hasStatedIdentity) {
hasStatedIdentity = true
val paramName = params["name"] ?: "Housing"

if (nameRegex.containsMatchIn(paramName)) {
Scoreboard.setTitle("§e§l" + paramName.uppercase())
if (nameRegex.containsMatchIn(paramName)) {
Scoreboard.setTitle("§e§l" + paramName.uppercase())
}

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

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

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

fun deploy() {
ActionManager.registerAction("tap:identity", actionIdentity)
ActionManager.registerAction("tap:visibility", actionVisibility)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package live.ixnoah.tapactions.actions
import live.ixnoah.tapactions.ActionManager
import net.minecraft.entity.boss.BossStatus

class HudActions {
object HudActions {
private val actionBossbar = { params : MutableMap<String, String> ->
if (params["no-clear"] == null) {
BossStatus.statusBarTime = Int.MAX_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ object CommandQueue {
if (queue.size == 0) return

val command = queue.first()
queue.drop(1)
queue = queue.drop(1).toMutableList()

Minecraft.getMinecraft().thePlayer.sendChatMessage("/" + command)
Minecraft.getMinecraft().thePlayer.sendChatMessage("/$command")
}

fun onTick(tick: Int) {
if (tick == 1) runNextCommand()
}

fun clearQueue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import net.minecraft.command.CommandException
import net.minecraft.command.ICommandSender
import net.minecraft.util.ChatComponentText

class CreateCommand: CommandBase() {
class CreateActionCommand: CommandBase() {
private val splitter = " | "

override fun getCommandName(): String {
return "createaction"
return "tap:createaction"
}

override fun getCommandAliases(): MutableList<String> {
return mutableListOf("createaction", "ca")
}

override fun getCommandUsage(sender: ICommandSender?): String {
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package live.ixnoah.tapactions.events

import CommandQueue
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent

class ClientTick {
private var tick = 0;

@SubscribeEvent
fun onEvent(event: ClientTickEvent) {
if (tick > 20) tick = 0
tick += 1

CommandQueue.onTick(tick)
}
}
5 changes: 3 additions & 2 deletions src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package live.ixnoah.tapactions.events

import live.ixnoah.tapactions.commands.CommandQueue

import CommandQueue
import live.ixnoah.tapactions.actions.GeneralActions
import net.minecraft.client.Minecraft
import net.minecraft.entity.boss.BossStatus
import net.minecraftforge.event.entity.EntityJoinWorldEvent
Expand All @@ -14,5 +14,6 @@ class WorldLoad {

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

0 comments on commit 9a4d327

Please sign in to comment.