feat: Option to not rendering slot binding lines
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
package moe.nea.firmament.features.inventory
|
package moe.nea.firmament.features.inventory
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import org.lwjgl.glfw.GLFW
|
import org.lwjgl.glfw.GLFW
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@@ -14,6 +13,7 @@ import net.minecraft.screen.GenericContainerScreenHandler
|
|||||||
import net.minecraft.screen.slot.Slot
|
import net.minecraft.screen.slot.Slot
|
||||||
import net.minecraft.screen.slot.SlotActionType
|
import net.minecraft.screen.slot.SlotActionType
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
|
import net.minecraft.util.StringIdentifiable
|
||||||
import moe.nea.firmament.annotations.Subscribe
|
import moe.nea.firmament.annotations.Subscribe
|
||||||
import moe.nea.firmament.events.HandledScreenForegroundEvent
|
import moe.nea.firmament.events.HandledScreenForegroundEvent
|
||||||
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
|
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
|
||||||
@@ -59,6 +59,17 @@ object SlotLocking : FirmamentFeature {
|
|||||||
}
|
}
|
||||||
val slotBind by keyBinding("bind") { GLFW.GLFW_KEY_L }
|
val slotBind by keyBinding("bind") { GLFW.GLFW_KEY_L }
|
||||||
val slotBindRequireShift by toggle("require-quick-move") { true }
|
val slotBindRequireShift by toggle("require-quick-move") { true }
|
||||||
|
val slotRenderLines by choice("bind-render") { SlotRenderLinesMode.ONLY_BOXES }
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class SlotRenderLinesMode : StringIdentifiable {
|
||||||
|
EVERYTHING,
|
||||||
|
ONLY_BOXES,
|
||||||
|
NOTHING;
|
||||||
|
|
||||||
|
override fun asString(): String {
|
||||||
|
return name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val config: TConfig
|
override val config: TConfig
|
||||||
@@ -95,7 +106,7 @@ object SlotLocking : FirmamentFeature {
|
|||||||
if (handler.inventory.size() < 9) return false
|
if (handler.inventory.size() < 9) return false
|
||||||
val sellItem = handler.inventory.getStack(handler.inventory.size() - 5)
|
val sellItem = handler.inventory.getStack(handler.inventory.size() - 5)
|
||||||
if (sellItem == null) return false
|
if (sellItem == null) return false
|
||||||
if (sellItem.displayNameAccordingToNbt?.unformattedString == "Sell Item") return true
|
if (sellItem.displayNameAccordingToNbt.unformattedString == "Sell Item") return true
|
||||||
val lore = sellItem.loreAccordingToNbt
|
val lore = sellItem.loreAccordingToNbt
|
||||||
return (lore.lastOrNull() ?: return false).unformattedString == "Click to buyback!"
|
return (lore.lastOrNull() ?: return false).unformattedString == "Click to buyback!"
|
||||||
}
|
}
|
||||||
@@ -104,7 +115,7 @@ object SlotLocking : FirmamentFeature {
|
|||||||
fun onSalvageProtect(event: IsSlotProtectedEvent) {
|
fun onSalvageProtect(event: IsSlotProtectedEvent) {
|
||||||
if (event.slot == null) return
|
if (event.slot == null) return
|
||||||
if (!event.slot.hasStack()) return
|
if (!event.slot.hasStack()) return
|
||||||
if (event.slot.stack.displayNameAccordingToNbt?.unformattedString != "Salvage Items") return
|
if (event.slot.stack.displayNameAccordingToNbt.unformattedString != "Salvage Items") return
|
||||||
val inv = event.slot.inventory
|
val inv = event.slot.inventory
|
||||||
var anyBlocked = false
|
var anyBlocked = false
|
||||||
for (i in 0 until event.slot.index) {
|
for (i in 0 until event.slot.index) {
|
||||||
@@ -227,23 +238,32 @@ object SlotLocking : FirmamentFeature {
|
|||||||
val accScreen = event.screen as AccessorHandledScreen
|
val accScreen = event.screen as AccessorHandledScreen
|
||||||
val sx = accScreen.x_Firmament
|
val sx = accScreen.x_Firmament
|
||||||
val sy = accScreen.y_Firmament
|
val sy = accScreen.y_Firmament
|
||||||
boundSlots.entries.forEach {
|
for (it in boundSlots.entries) {
|
||||||
val hotbarSlot = findByIndex(it.key) ?: return@forEach
|
val hotbarSlot = findByIndex(it.key) ?: continue
|
||||||
val inventorySlot = findByIndex(it.value) ?: return@forEach
|
val inventorySlot = findByIndex(it.value) ?: continue
|
||||||
|
|
||||||
val (hotX, hotY) = hotbarSlot.lineCenter()
|
val (hotX, hotY) = hotbarSlot.lineCenter()
|
||||||
val (invX, invY) = inventorySlot.lineCenter()
|
val (invX, invY) = inventorySlot.lineCenter()
|
||||||
event.context.drawLine(
|
val anyHovered = accScreen.focusedSlot_Firmament === hotbarSlot
|
||||||
invX + sx, invY + sy,
|
|| accScreen.focusedSlot_Firmament === inventorySlot
|
||||||
hotX + sx, hotY + sy,
|
if (!anyHovered && TConfig.slotRenderLines == SlotRenderLinesMode.NOTHING)
|
||||||
|
continue
|
||||||
|
val color = if (anyHovered)
|
||||||
me.shedaniel.math.Color.ofOpaque(0x00FF00)
|
me.shedaniel.math.Color.ofOpaque(0x00FF00)
|
||||||
)
|
else
|
||||||
|
me.shedaniel.math.Color.ofTransparent(0xc0a0f000.toInt())
|
||||||
|
if (TConfig.slotRenderLines == SlotRenderLinesMode.EVERYTHING || anyHovered)
|
||||||
|
event.context.drawLine(
|
||||||
|
invX + sx, invY + sy,
|
||||||
|
hotX + sx, hotY + sy,
|
||||||
|
color
|
||||||
|
)
|
||||||
event.context.drawBorder(hotbarSlot.x + sx,
|
event.context.drawBorder(hotbarSlot.x + sx,
|
||||||
hotbarSlot.y + sy,
|
hotbarSlot.y + sy,
|
||||||
16, 16, 0xFF00FF00u.toInt())
|
16, 16, color.color)
|
||||||
event.context.drawBorder(inventorySlot.x + sx,
|
event.context.drawBorder(inventorySlot.x + sx,
|
||||||
inventorySlot.y + sy,
|
inventorySlot.y + sy,
|
||||||
16, 16, 0xFF00FF00u.toInt())
|
16, 16, color.color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.lwjgl.glfw.GLFW
|
|||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.JsonElement
|
import kotlinx.serialization.json.JsonElement
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
import kotlin.enums.enumEntries
|
||||||
import kotlin.io.path.createDirectories
|
import kotlin.io.path.createDirectories
|
||||||
import kotlin.io.path.readText
|
import kotlin.io.path.readText
|
||||||
import kotlin.io.path.writeText
|
import kotlin.io.path.writeText
|
||||||
@@ -123,6 +124,17 @@ abstract class ManagedConfig(
|
|||||||
return option(propertyName, default, ChoiceHandler(universe))
|
return option(propertyName, default, ChoiceHandler(universe))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected inline fun <reified E> choice(
|
||||||
|
propertyName: String,
|
||||||
|
noinline default: () -> E
|
||||||
|
): ManagedOption<E> where E : Enum<E>, E : StringIdentifiable {
|
||||||
|
return choice(propertyName, enumEntries<E>(), default)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <E> createStringIdentifiable(x: () -> Array<out E>): Codec<E> where E : Enum<E>, E : StringIdentifiable {
|
||||||
|
return StringIdentifiable.createCodec { x() }
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: wait on https://youtrack.jetbrains.com/issue/KT-73434
|
// TODO: wait on https://youtrack.jetbrains.com/issue/KT-73434
|
||||||
// protected inline fun <reified E> choice(
|
// protected inline fun <reified E> choice(
|
||||||
// propertyName: String,
|
// propertyName: String,
|
||||||
|
|||||||
@@ -202,6 +202,11 @@
|
|||||||
"firmament.config.save-cursor-position.tolerance.description": "Select how long your cursor position last between GUIs before resetting back to the middle of the screen.",
|
"firmament.config.save-cursor-position.tolerance.description": "Select how long your cursor position last between GUIs before resetting back to the middle of the screen.",
|
||||||
"firmament.config.slot-locking": "Slot Locking",
|
"firmament.config.slot-locking": "Slot Locking",
|
||||||
"firmament.config.slot-locking.bind": "Bind Slot",
|
"firmament.config.slot-locking.bind": "Bind Slot",
|
||||||
|
"firmament.config.slot-locking.bind-render": "Show Slot Bindings",
|
||||||
|
"firmament.config.slot-locking.bind-render.choice.everything": "Always",
|
||||||
|
"firmament.config.slot-locking.bind-render.choice.nothing": "Only when hovered",
|
||||||
|
"firmament.config.slot-locking.bind-render.choice.only_boxes": "Only boxes",
|
||||||
|
"firmament.config.slot-locking.bind-render.description": "Disable rendering of the slot binding lines (or all of the slot binding rendering), unless the relevant slot is being hovered.",
|
||||||
"firmament.config.slot-locking.bind.description": "Bind a hotbar slot to another slot. This allows quick switching between the slots by shift clicking on either slot.",
|
"firmament.config.slot-locking.bind.description": "Bind a hotbar slot to another slot. This allows quick switching between the slots by shift clicking on either slot.",
|
||||||
"firmament.config.slot-locking.lock": "Lock Slot",
|
"firmament.config.slot-locking.lock": "Lock Slot",
|
||||||
"firmament.config.slot-locking.lock-uuid": "Lock UUID (Lock Item)",
|
"firmament.config.slot-locking.lock-uuid": "Lock UUID (Lock Item)",
|
||||||
|
|||||||
Reference in New Issue
Block a user