aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-21 12:05:06 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-21 12:05:06 -0500
commitad41c31385a66438b6647cd489e4ffb018950264 (patch)
tree0e81216ac64160d0a1f169b06cb87fb168099dbe /src/main/kotlin
parent253a9bffcf3a3f8f99bb426b7b6d8031e73c82ba (diff)
downloadDulkirMod-Fabric-ad41c31385a66438b6647cd489e4ffb018950264.tar.gz
DulkirMod-Fabric-ad41c31385a66438b6647cd489e4ffb018950264.tar.bz2
DulkirMod-Fabric-ad41c31385a66438b6647cd489e4ffb018950264.zip
Added option to hide hunger and more animation features
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/com/dulkirfabric/Registrations.kt6
-rw-r--r--src/main/kotlin/com/dulkirfabric/commands/AnimationCommand.kt90
-rw-r--r--src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt58
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/AnimationPreset.kt17
4 files changed, 140 insertions, 31 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt
index 135b6af..ffcf85f 100644
--- a/src/main/kotlin/com/dulkirfabric/Registrations.kt
+++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt
@@ -1,10 +1,7 @@
package com.dulkirfabric
import com.dulkirfabric.DulkirModFabric.EVENT_BUS
-import com.dulkirfabric.commands.ConfigCommand
-import com.dulkirfabric.commands.DynamicKeyCommand
-import com.dulkirfabric.commands.JoinDungeonCommands
-import com.dulkirfabric.commands.TestCommand
+import com.dulkirfabric.commands.*
import com.dulkirfabric.events.*
import com.dulkirfabric.events.chat.ChatReceivedEvent
import com.dulkirfabric.events.chat.ModifyCommandEvent
@@ -49,6 +46,7 @@ object Registrations {
cre.register(JoinDungeonCommands.M6Command::register)
cre.register(JoinDungeonCommands.M7Command::register)
cre.register(DynamicKeyCommand::register)
+ cre.register(AnimationCommand::register)
if (FabricLoader.getInstance().isDevelopmentEnvironment)
cre.register(TestCommand::register)
}
diff --git a/src/main/kotlin/com/dulkirfabric/commands/AnimationCommand.kt b/src/main/kotlin/com/dulkirfabric/commands/AnimationCommand.kt
new file mode 100644
index 0000000..34da0cb
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/commands/AnimationCommand.kt
@@ -0,0 +1,90 @@
+package com.dulkirfabric.commands
+
+import com.dulkirfabric.config.DulkirConfig
+import com.dulkirfabric.util.AnimationPreset
+import com.dulkirfabric.util.TextUtils
+import com.google.gson.Gson
+import com.mojang.brigadier.CommandDispatcher
+import com.mojang.brigadier.arguments.StringArgumentType
+import com.mojang.brigadier.builder.LiteralArgumentBuilder
+import com.mojang.brigadier.builder.RequiredArgumentBuilder
+import me.shedaniel.autoconfig.ConfigData
+import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
+import net.minecraft.command.CommandRegistryAccess
+import java.awt.Toolkit
+import java.awt.datatransfer.Clipboard
+import java.awt.datatransfer.DataFlavor
+import java.awt.datatransfer.StringSelection
+import java.util.*
+
+object AnimationCommand {
+ fun register(dispatcher: CommandDispatcher<FabricClientCommandSource>, registryAccess: CommandRegistryAccess) {
+ dispatcher.register(
+ LiteralArgumentBuilder.literal<FabricClientCommandSource>("animations")
+ .executes {
+ TextUtils.info("§6Usage: /animations <import/export>")
+ TextUtils.info("§6For more information about this command, run /animations help")
+ return@executes 0
+ }
+ .then(
+ LiteralArgumentBuilder.literal<FabricClientCommandSource>("import")
+ .executes {
+ applyPresetFromClipboard()
+ return@executes 1
+ }
+ )
+ .then(
+ LiteralArgumentBuilder.literal<FabricClientCommandSource>("export")
+ .executes {
+ applyPresetToClipboard()
+ return@executes 1
+ }
+ )
+ .then(
+ LiteralArgumentBuilder.literal<FabricClientCommandSource>("help")
+ .executes {
+ TextUtils.info("§6§lAnimations Info")
+ TextUtils.info("§7 - Exporting using this command will encode data about your held item (position, scale, and swing variables) to a base64 encoded string that you can share with friends.")
+ TextUtils.info("§7 - Importing using this command will apply settings based on the state of your clipboard, if possible.")
+ return@executes 2
+ }
+ )
+ )
+ }
+
+ private fun applyPresetFromClipboard() {
+ val gson = Gson()
+ val clipboard = Toolkit.getDefaultToolkit().systemClipboard
+ val base64 = clipboard.getData(DataFlavor.stringFlavor) as String
+ try {
+ val jsonString = String(Base64.getDecoder().decode(base64))
+ val import = gson.fromJson(jsonString, AnimationPreset::class.java)
+ DulkirConfig.configOptions.animationPreset.posX = import.posX
+ DulkirConfig.configOptions.animationPreset.posY = import.posY
+ DulkirConfig.configOptions.animationPreset.posZ = import.posZ
+ DulkirConfig.configOptions.animationPreset.rotX = import.rotX
+ DulkirConfig.configOptions.animationPreset.rotY = import.rotY
+ DulkirConfig.configOptions.animationPreset.rotZ = import.rotZ
+ DulkirConfig.configOptions.animationPreset.scale = import.scale
+ DulkirConfig.configOptions.animationPreset.swingDuration = import.swingDuration
+ DulkirConfig.configOptions.animationPreset.cancelReEquip = import.cancelReEquip
+ DulkirConfig.configOptions.animationPreset.rotationlessDrink = import.rotationlessDrink
+ } catch (e: Exception) {
+ TextUtils.info("§6Something went wrong when trying to import settings. Make sure you have a valid string copied to your clipboard!")
+ return
+ }
+ TextUtils.info("§6Successfully imported preset.")
+ }
+
+ private fun applyPresetToClipboard() {
+ var s = ""
+ val gson = Gson()
+ val jsonString = gson.toJson(DulkirConfig.configOptions.animationPreset)
+ s = Base64.getEncoder().encodeToString(jsonString.toByteArray())
+ // set clipboard
+ val selection = StringSelection(s)
+ val clipboard: Clipboard = Toolkit.getDefaultToolkit().systemClipboard
+ clipboard.setContents(selection, selection)
+ TextUtils.info("§6Animation config has been copied to clipboard")
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
index d8beafe..2795668 100644
--- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
+++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
@@ -17,6 +17,7 @@ import com.dulkirfabric.DulkirModFabric.mc
import com.dulkirfabric.config.ConfigHelper.mkKeyField
import com.dulkirfabric.config.ConfigHelper.mkStringField
import com.dulkirfabric.config.ConfigHelper.mkToggle
+import com.dulkirfabric.util.AnimationPreset
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlinx.serialization.decodeFromString
@@ -106,6 +107,9 @@ class DulkirConfig {
entryBuilder.mkToggle(Text.literal("Hide Armor Overlay in Skyblock"), configOptions::hideArmorOverlay)
)
general.addEntry(
+ entryBuilder.mkToggle(Text.literal("Hide Hunger Overlay in Skyblock"), configOptions::hideHungerOverlay)
+ )
+ general.addEntry(
entryBuilder.startIntSlider(Text.literal("Anti Downtime Alarm"), configOptions.alarmTimeout, 0, 1000)
.setSaveConsumer {
configOptions.alarmTimeout = it
@@ -158,56 +162,63 @@ class DulkirConfig {
//TODO: Come up with some custome float slider instead of int slider jank
animations.addEntry(
- entryBuilder.startIntSlider(Text.literal("posX"), configOptions.heldItemPosX, -150, 150)
- .setSaveConsumer { newValue -> configOptions.heldItemPosX = newValue }
+ entryBuilder.startIntSlider(Text.literal("posX"), configOptions.animationPreset.posX, -150, 150)
+ .setSaveConsumer { newValue -> configOptions.animationPreset.posX = newValue }
.setDefaultValue(0)
.build()
)
animations.addEntry(
- entryBuilder.startIntSlider(Text.literal("posY"), configOptions.heldItemPosY, -150, 150)
- .setSaveConsumer { newValue -> configOptions.heldItemPosY = newValue }
+ entryBuilder.startIntSlider(Text.literal("posY"), configOptions.animationPreset.posY, -150, 150)
+ .setSaveConsumer { newValue -> configOptions.animationPreset.posZ = newValue }
.setDefaultValue(0)
.build()
)
animations.addEntry(
- entryBuilder.startIntSlider(Text.literal("posZ"), configOptions.heldItemPosZ, -150, 50)
- .setSaveConsumer { newValue -> configOptions.heldItemPosZ = newValue }
+ entryBuilder.startIntSlider(Text.literal("posZ"), configOptions.animationPreset.posZ, -150, 50)
+ .setSaveConsumer { newValue -> configOptions.animationPreset.posZ = newValue }
.setDefaultValue(0)
.build()
)
animations.addEntry(
- entryBuilder.startIntSlider(Text.literal("rotationX"), configOptions.heldItemRotX, -180, 180)
- .setSaveConsumer { newValue -> configOptions.heldItemRotX = newValue }
+ entryBuilder.startIntSlider(Text.literal("rotationX"), configOptions.animationPreset.rotX, -180, 180)
+ .setSaveConsumer { newValue -> configOptions.animationPreset.rotX = newValue }
+ .setDefaultValue(0)
.build()
)
animations.addEntry(
- entryBuilder.startIntSlider(Text.literal("rotationY"), configOptions.heldItemRotY, -180, 180)
- .setSaveConsumer { newValue -> configOptions.heldItemRotY = newValue }
+ entryBuilder.startIntSlider(Text.literal("rotationY"), configOptions.animationPreset.rotY, -180, 180)
+ .setSaveConsumer { newValue -> configOptions.animationPreset.rotY = newValue }
+ .setDefaultValue(0)
.build()
)
animations.addEntry(
- entryBuilder.startIntSlider(Text.literal("rotationZ"), configOptions.heldItemRotZ, -180, 180)
- .setSaveConsumer { newValue -> configOptions.heldItemRotZ = newValue }
+ entryBuilder.startIntSlider(Text.literal("rotationZ"), configOptions.animationPreset.rotZ, -180, 180)
+ .setSaveConsumer { newValue -> configOptions.animationPreset.rotZ = newValue }
+ .setDefaultValue(0)
.build()
)
animations.addEntry(
- entryBuilder.startFloatField(Text.literal("Held Item Scale"), configOptions.heldItemScale)
+ entryBuilder.startFloatField(Text.literal("Held Item Scale"), configOptions.animationPreset.scale)
.setTooltip(Text.literal("Recommended range of .1 - 2"))
.setSaveConsumer { newValue ->
- configOptions.heldItemScale = newValue
+ configOptions.animationPreset.scale = newValue
}
+ .setDefaultValue(1f)
.build()
)
animations.addEntry(
- entryBuilder.startIntSlider(Text.literal("Swing Speed"), configOptions.handSwingDuration, 2, 20)
- .setSaveConsumer { newValue -> configOptions.handSwingDuration = newValue }
+ entryBuilder.startIntSlider(Text.literal("Swing Speed"), configOptions.animationPreset.swingDuration, 2, 20)
+ .setSaveConsumer { newValue -> configOptions.animationPreset.swingDuration = newValue }
+ .setDefaultValue(6)
.build()
)
animations.addEntry(
- entryBuilder.mkToggle(Text.literal("Cancel Re-equip Animation"), configOptions::cancelReEquip)
+ entryBuilder.startBooleanToggle(Text.literal("Cancel Re-Equip Animation"), configOptions.animationPreset.cancelReEquip)
+ .setSaveConsumer {newValue -> configOptions.animationPreset.cancelReEquip = newValue }
+ .setDefaultValue(false)
+ .build()
)
-
builder.transparentBackground()
screen = builder.build()
}
@@ -230,15 +241,8 @@ class DulkirConfig {
var inactiveEffigyDisplay: Boolean = false,
var disableExplosionParticles: Boolean = false,
var hideArmorOverlay: Boolean = false,
- var heldItemPosX: Int = 0,
- var heldItemPosY: Int = 0,
- var heldItemPosZ: Int = 0,
- var heldItemRotX: Int = 0,
- var heldItemRotY: Int = 0,
- var heldItemRotZ: Int = 0,
- var heldItemScale: Float = 1f,
- var handSwingDuration: Int = 6,
- var cancelReEquip: Boolean = false,
+ var hideHungerOverlay: Boolean = false,
+ var animationPreset: AnimationPreset = AnimationPreset(),
var duraCooldown: Boolean = false,
var alarmTimeout: Int = 300,
var arachneKeeperWaypoints: Boolean = false,
diff --git a/src/main/kotlin/com/dulkirfabric/util/AnimationPreset.kt b/src/main/kotlin/com/dulkirfabric/util/AnimationPreset.kt
new file mode 100644
index 0000000..67f5b00
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/util/AnimationPreset.kt
@@ -0,0 +1,17 @@
+package com.dulkirfabric.util
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class AnimationPreset(
+ var posX: Int = 0,
+ var posY: Int = 0,
+ var posZ: Int = 0,
+ var rotX: Int = 0,
+ var rotY: Int = 0,
+ var rotZ: Int = 0,
+ var scale: Float = 1f,
+ var swingDuration: Int = 6,
+ var cancelReEquip: Boolean = false,
+ var rotationlessDrink: Boolean = true,
+) \ No newline at end of file