Add slot locking
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user