aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-05-18 03:20:22 +0200
committernea <nea@nea.moe>2023-05-18 03:20:22 +0200
commit1dd603ab1cc42a602f1d82595dd15789ef63d2a3 (patch)
tree1658e1d32849d69102ff1e1b4c856da8428ab82b /src/main/kotlin/moe/nea/firmament/features
parent3ebe3e80b929b03ad0bcb0c76cec6b3285fe08bd (diff)
downloadFirmament-1dd603ab1cc42a602f1d82595dd15789ef63d2a3.tar.gz
Firmament-1dd603ab1cc42a602f1d82595dd15789ef63d2a3.tar.bz2
Firmament-1dd603ab1cc42a602f1d82595dd15789ef63d2a3.zip
Add slot locking
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt6
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/FirmamentFeature.kt (renamed from src/main/kotlin/moe/nea/firmament/features/NEUFeature.kt)2
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt68
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt4
5 files changed, 77 insertions, 7 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
index 68205f4..580d745 100644
--- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
@@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import moe.nea.firmament.Firmament
import moe.nea.firmament.features.fishing.FishingWarning
+import moe.nea.firmament.features.inventory.SlotLocking
import moe.nea.firmament.features.world.FairySouls
import moe.nea.firmament.util.data.DataHolder
@@ -13,7 +14,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
val enabledFeatures: MutableMap<String, Boolean> = mutableMapOf()
)
- private val features = mutableMapOf<String, NEUFeature>()
+ private val features = mutableMapOf<String, FirmamentFeature>()
private var hasAutoloaded = false
@@ -26,11 +27,12 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
if (hasAutoloaded) return
loadFeature(FairySouls)
loadFeature(FishingWarning)
+ loadFeature(SlotLocking)
hasAutoloaded = true
}
}
- fun loadFeature(feature: NEUFeature) {
+ fun loadFeature(feature: FirmamentFeature) {
synchronized(features) {
if (feature.identifier in features) {
Firmament.logger.error("Double registering feature ${feature.identifier}. Ignoring second instance $feature")
diff --git a/src/main/kotlin/moe/nea/firmament/features/NEUFeature.kt b/src/main/kotlin/moe/nea/firmament/features/FirmamentFeature.kt
index f231003..c9cb8f0 100644
--- a/src/main/kotlin/moe/nea/firmament/features/NEUFeature.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/FirmamentFeature.kt
@@ -2,7 +2,7 @@ package moe.nea.firmament.features
import moe.nea.firmament.util.config.ManagedConfig
-interface NEUFeature {
+interface FirmamentFeature {
val name: String
val identifier: String
val defaultEnabled: Boolean
diff --git a/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt b/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt
index cdeb24c..ab8ebf4 100644
--- a/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt
@@ -13,13 +13,13 @@ import net.minecraft.util.math.Vec3d
import moe.nea.firmament.events.ParticleSpawnEvent
import moe.nea.firmament.events.WorldReadyEvent
import moe.nea.firmament.events.WorldRenderLastEvent
-import moe.nea.firmament.features.NEUFeature
+import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.TimeMark
import moe.nea.firmament.util.config.ManagedConfig
import moe.nea.firmament.util.render.RenderBlockContext.Companion.renderBlocks
-object FishingWarning : NEUFeature {
+object FishingWarning : FirmamentFeature {
override val name: String
get() = "Fishing Warning"
override val identifier: String
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
new file mode 100644
index 0000000..9f75541
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
@@ -0,0 +1,68 @@
+package moe.nea.firmament.features.inventory
+
+import kotlinx.serialization.Serializable
+import kotlinx.serialization.serializer
+import net.minecraft.client.gui.DrawableHelper
+import net.minecraft.entity.player.PlayerInventory
+import moe.nea.firmament.events.HandledScreenKeyPressedEvent
+import moe.nea.firmament.events.IsSlotProtectedEvent
+import moe.nea.firmament.events.SlotRenderEvents
+import moe.nea.firmament.features.FirmamentFeature
+import moe.nea.firmament.keybindings.FirmamentKeyBindings
+import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
+import moe.nea.firmament.util.CommonSoundEffects
+import moe.nea.firmament.util.MC
+import moe.nea.firmament.util.data.ProfileSpecificDataHolder
+
+object SlotLocking : FirmamentFeature {
+ override val name: String
+ get() = "Slot Locking"
+ override val identifier: String
+ get() = "slot-locking"
+
+ @Serializable
+ data class Data(
+ val lockedSlots: MutableSet<Int> = mutableSetOf(),
+ )
+
+ object DConfig : ProfileSpecificDataHolder<Data>(serializer(), "locked-slots", ::Data)
+
+ val keyBinding by FirmamentKeyBindings::SLOT_LOCKING
+ val lockedSlots get() = DConfig.data?.lockedSlots
+ override fun onLoad() {
+ HandledScreenKeyPressedEvent.subscribe {
+ if (!it.matches(keyBinding)) return@subscribe
+ val inventory = MC.handledScreen ?: return@subscribe
+ inventory as AccessorHandledScreen
+
+ val slot = inventory.focusedSlot_NEU ?: return@subscribe
+ val lockedSlots = lockedSlots ?: return@subscribe
+ if (slot.inventory is PlayerInventory) {
+ if (slot.index in lockedSlots) {
+ lockedSlots.remove(slot.index)
+ } else {
+ lockedSlots.add(slot.index)
+ }
+ DConfig.markDirty()
+ CommonSoundEffects.playSuccess()
+ }
+ }
+ IsSlotProtectedEvent.subscribe {
+ if (it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())) {
+ it.protect()
+ }
+ }
+ SlotRenderEvents.Before.subscribe {
+ if (it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())) {
+ DrawableHelper.fill(
+ it.matrices,
+ it.slot.x,
+ it.slot.y,
+ it.slot.x + 16,
+ it.slot.y + 16,
+ 0xFFFF0000.toInt()
+ )
+ }
+ }
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt b/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt
index f752963..ffde0b9 100644
--- a/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt
@@ -6,7 +6,7 @@ import kotlinx.serialization.serializer
import moe.nea.firmament.events.ServerChatLineReceivedEvent
import moe.nea.firmament.events.SkyblockServerUpdateEvent
import moe.nea.firmament.events.WorldRenderLastEvent
-import moe.nea.firmament.features.NEUFeature
+import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SBData
@@ -17,7 +17,7 @@ import moe.nea.firmament.util.render.RenderBlockContext.Companion.renderBlocks
import moe.nea.firmament.util.unformattedString
-object FairySouls : NEUFeature {
+object FairySouls : FirmamentFeature {
@Serializable