aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-02-06 21:01:55 +0100
committernea <nea@nea.moe>2023-02-06 21:01:55 +0100
commit5a113b83d0429a712d70b3b6ef22224493d69b32 (patch)
tree5da696b6b9d8b0820690bfa70403c206a8255b47 /src/main/kotlin
parent0b5c9a711f92aa0967b4ceedf7bd9205fcfb496c (diff)
downloadNotEnoughUpdates-5a113b83d0429a712d70b3b6ef22224493d69b32.tar.gz
NotEnoughUpdates-5a113b83d0429a712d70b3b6ef22224493d69b32.tar.bz2
NotEnoughUpdates-5a113b83d0429a712d70b3b6ef22224493d69b32.zip
Dungeon commands
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt10
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt144
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt16
3 files changed, 166 insertions, 4 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
index 351c0fa9..7647ca2c 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
@@ -88,13 +88,17 @@ class DevTestCommand {
SPECIAL_KICK,
"Ok, this is actually the last message, use the command again and you'll crash I promise"
)
+
+ fun isDeveloper(commandSender: ICommandSender): Boolean {
+ return DEV_TESTERS.contains((commandSender as? EntityPlayer)?.uniqueID?.toString())
+ || Launch.blackboard.get("fml.deobfuscatedEnvironment") as Boolean
+
+ }
}
var devFailIndex = 0
-
fun canPlayerExecute(commandSender: ICommandSender): Boolean {
- return DEV_TESTERS.contains((commandSender as? EntityPlayer)?.uniqueID?.toString())
- || Launch.blackboard.get("fml.deobfuscatedEnvironment") as Boolean
+ return isDeveloper(commandSender)
}
@SubscribeEvent
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt
new file mode 100644
index 00000000..514f7be0
--- /dev/null
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2023 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.commands.misc
+
+import com.google.gson.JsonObject
+import com.mojang.brigadier.arguments.StringArgumentType.string
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates
+import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
+import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor
+import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
+import io.github.moulberry.notenoughupdates.util.brigadier.*
+import net.minecraft.block.material.MapColor
+import net.minecraft.client.Minecraft
+import net.minecraft.item.ItemMap
+import net.minecraft.util.EnumChatFormatting.GREEN
+import net.minecraft.util.EnumChatFormatting.RED
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.awt.Color
+
+@NEUAutoSubscribe
+class DungeonCommands {
+ @SubscribeEvent
+ fun onCommands(event: RegisterBrigadierCommandEvent) {
+ event.command("dh") {
+ thenExecute {
+ Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp dungeon_hub")
+ }
+ }.withHelp("Warps to the dungeon hub")
+ event.command("dn") {
+ thenExecute {
+ Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp dungeon_hub")
+ reply("Warping to...")
+ reply("Deez nuts lmao")
+ }
+ }.withHelp("Warps to the dungeon nuts")
+ event.command("join") {
+ thenArgument("floor", string()) { floor ->
+ suggests((1..7).flatMap { listOf("f$it", "m$it") })
+ thenExecute {
+ val floor = this[floor]
+ val prefix = if (floor.startsWith("m")) "master_catacombs" else "catacombs"
+ val level = floor.lastOrNull()?.digitToIntOrNull()
+ val cmd = "/joindungeon $prefix ${floor.lastOrNull()}"
+ reply("Running command: $cmd")
+ Minecraft.getMinecraft().thePlayer.sendChatMessage(cmd)
+ }
+ }.withHelp("Join a dungeon floor with a party of 5")
+ }
+ event.command("neumap") {
+ thenLiteral("reset") {
+ thenExecute {
+ NotEnoughUpdates.INSTANCE.colourMap = null
+ reply("Reset color map")
+ }
+ requiresDev()
+ }.withHelp("Reset the colour map")
+ thenLiteral("save") {
+ thenArgument("filename", string()) { fileName ->
+ requiresDev()
+ thenExecute {
+ val stack = Minecraft.getMinecraft().thePlayer.heldItem
+ if (stack == null || stack.item !is ItemMap) {
+ reply("Please hold a map item")
+ return@thenExecute
+ }
+ val map = stack.item as ItemMap
+ val mapData = map.getMapData(stack, Minecraft.getMinecraft().theWorld)
+ if (mapData == null) {
+ reply("Could not grab map data (empty map)")
+ return@thenExecute
+ }
+ val json = JsonObject()
+ for (i in 0 until (128 * 128)) {
+ val x = i % 128
+ val y = i / 128
+ val j = mapData.colors[i].toInt() and 255
+ val c = if (j / 4 == 0) {
+ Color((i + i / 128 and 1) * 8 + 16 shl 24, true)
+ } else {
+ Color(MapColor.mapColorArray[j / 4].getMapColor(j and 3), true)
+ }
+ json.addProperty("$x:$y", c.rgb)
+ }
+ try {
+ NotEnoughUpdates.INSTANCE.manager.configLocation.resolve("maps").mkdirs()
+ NotEnoughUpdates.INSTANCE.manager.writeJson(
+ json,
+ NotEnoughUpdates.INSTANCE.manager.configLocation.resolve("maps/${this[fileName]}.json")
+ )
+ reply("${GREEN}Saved to file.")
+ } catch (e: Exception) {
+ e.printStackTrace()
+ reply("${RED}Failed to save.")
+ }
+ }
+ }
+ }.withHelp("Save a colour map from an item")
+ thenLiteral("load") {
+ thenArgument("filename", string()) { fileName ->
+ requiresDev()
+ thenExecute {
+ val json = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(
+ NotEnoughUpdates.INSTANCE.manager.configLocation.resolve(
+ "maps/${this[fileName]}.json"
+ )
+ )
+ NotEnoughUpdates.INSTANCE.colourMap = (0 until 128).map { x ->
+ (0 until 128).map { y ->
+ val key = "$x:$y"
+ json[key]?.asInt?.let { Color(it, true) } ?: Color(0, 0, 0, 0)
+ }.toTypedArray()
+ }.toTypedArray()
+ for (x in 0..127) {
+ for (y in 0..127) {
+ NotEnoughUpdates.INSTANCE.colourMap[x][y] = Color(0, 0, 0, 0)
+ }
+ }
+ reply("Loaded colour map from file")
+ }
+ }
+ }.withHelp("Load a colour map from a file")
+ thenExecute {
+ NotEnoughUpdates.INSTANCE.openGui = GuiDungeonMapEditor(null)
+ }
+ }.withHelp("Open the dungeon map editor")
+ }
+}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
index f6a326dc..1b840a07 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
@@ -27,11 +27,11 @@ import com.mojang.brigadier.context.CommandContext
import com.mojang.brigadier.tree.ArgumentCommandNode
import com.mojang.brigadier.tree.CommandNode
import com.mojang.brigadier.tree.LiteralCommandNode
+import io.github.moulberry.notenoughupdates.commands.dev.DevTestCommand
import io.github.moulberry.notenoughupdates.util.iterate
import net.minecraft.command.ICommandSender
import net.minecraft.util.ChatComponentText
import net.minecraft.util.IChatComponent
-import java.lang.RuntimeException
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.lang.reflect.TypeVariable
@@ -152,6 +152,11 @@ fun <T : ArgumentBuilder<DefaultSource, T>> T.thenExecute(block: CommandContext<
1
}
+fun <T : ArgumentBuilder<DefaultSource, T>> T.requiresDev(): T {
+ requires { DevTestCommand.isDeveloper(it) }
+ return this
+}
+
fun NEUBrigadierHook.withHelp(helpText: String): NEUBrigadierHook {
commandNode.withHelp(helpText)
return this
@@ -162,4 +167,13 @@ fun <T : CommandNode<DefaultSource>> T.withHelp(helpText: String): T {
return this
}
+fun <A : Any, T : RequiredArgumentBuilder<DefaultSource, A>> T.suggests(list: List<String>) {
+ suggests { context, builder ->
+ list.filter { it.startsWith(builder.remaining, ignoreCase = true) }
+ .forEach { builder.suggest(it) }
+ builder.buildFuture()
+ }
+}
+
+