Skip to content

Commit b59cd8b

Browse files
committed
Split client and server configs into separate classes
1 parent 9547170 commit b59cd8b

File tree

17 files changed

+164
-80
lines changed

17 files changed

+164
-80
lines changed

Common/src/main/java/gay/object/hexdebug/mixin/MixinShiftScrollListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package gay.object.hexdebug.mixin;
22

33
import at.petrak.hexcasting.client.ShiftScrollListener;
4-
import gay.object.hexdebug.config.HexDebugConfig;
4+
import gay.object.hexdebug.config.HexDebugClientConfig;
55
import gay.object.hexdebug.items.DebuggerItem;
66
import gay.object.hexdebug.registry.HexDebugItems;
77
import net.minecraft.client.Minecraft;
@@ -43,7 +43,7 @@ public abstract class MixinShiftScrollListener {
4343
&& (player.isShiftKeyDown() || !needsSneaking)
4444
&& !player.isSpectator()
4545
// additional logic
46-
&& HexDebugConfig.INSTANCE.getClient().getSmartDebuggerSneakScroll()
46+
&& HexDebugClientConfig.getConfig().getSmartDebuggerSneakScroll()
4747
&& !DebuggerItem.isDebugging()
4848
&& player.getMainHandItem().getItem() == HexDebugItems.DEBUGGER.getValue()
4949
&& hexdebug$invokeIsScrollableItem(player.getOffhandItem().getItem())

Common/src/main/kotlin/gay/object/hexdebug/HexDebug.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package gay.`object`.hexdebug
22

33
import gay.`object`.hexdebug.adapter.DebugAdapterManager
4-
import gay.`object`.hexdebug.config.HexDebugConfig
4+
import gay.`object`.hexdebug.config.HexDebugServerConfig
55
import gay.`object`.hexdebug.networking.HexDebugNetworking
66
import gay.`object`.hexdebug.registry.*
77
import net.minecraft.resources.ResourceLocation
@@ -16,7 +16,7 @@ object HexDebug {
1616

1717
fun init() {
1818
LOGGER.info("HexDebug <3 HexBug")
19-
HexDebugConfig.init()
19+
HexDebugServerConfig.init()
2020
initRegistries(
2121
HexDebugBlocks,
2222
HexDebugBlockEntities,
@@ -32,6 +32,11 @@ object HexDebug {
3232
DebugAdapterManager.init()
3333
}
3434

35+
fun initServer() {
36+
LOGGER.info("Infesting your server with HexBugs...")
37+
HexDebugServerConfig.initServer()
38+
}
39+
3540
@JvmStatic
3641
fun id(path: String) = ResourceLocation(MODID, path)
3742
}

Common/src/main/kotlin/gay/object/hexdebug/HexDebugClient.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import at.petrak.hexcasting.api.client.ScryingLensOverlayRegistry
55
import at.petrak.hexcasting.api.utils.asTextComponent
66
import at.petrak.hexcasting.api.utils.gray
77
import at.petrak.hexcasting.api.utils.plusAssign
8+
import gay.`object`.hexdebug.HexDebug.LOGGER
89
import gay.`object`.hexdebug.adapter.proxy.DebugProxyClient
910
import gay.`object`.hexdebug.blocks.focusholder.FocusHolderBlock
10-
import gay.`object`.hexdebug.config.HexDebugConfig
11-
import gay.`object`.hexdebug.config.HexDebugConfig.GlobalConfig
11+
import gay.`object`.hexdebug.config.HexDebugClientConfig
12+
import gay.`object`.hexdebug.config.HexDebugServerConfig
1213
import gay.`object`.hexdebug.registry.HexDebugBlocks
1314
import gay.`object`.hexdebug.utils.styledHoverName
1415
import gay.`object`.hexdebug.utils.toComponent
@@ -29,13 +30,15 @@ object HexDebugClient {
2930
private const val MAX_IOTA_DISPLAY_LINES = 4
3031

3132
fun init() {
32-
HexDebugConfig.initClient()
33+
LOGGER.info("Hiding cognitohazards in your client...")
34+
HexDebugServerConfig.initClient()
35+
HexDebugClientConfig.init()
3336
DebugProxyClient.init()
3437
addScryingLensOverlays()
3538
}
3639

3740
fun getConfigScreen(parent: Screen): Screen {
38-
return AutoConfig.getConfigScreen(GlobalConfig::class.java, parent).get()
41+
return AutoConfig.getConfigScreen(HexDebugClientConfig.GlobalConfig::class.java, parent).get()
3942
}
4043

4144
private fun addScryingLensOverlays() {

Common/src/main/kotlin/gay/object/hexdebug/adapter/proxy/DebugProxyClient.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package gay.`object`.hexdebug.adapter.proxy
22

33
import dev.architectury.event.events.client.ClientPlayerEvent
44
import gay.`object`.hexdebug.HexDebug
5-
import gay.`object`.hexdebug.config.HexDebugConfig
5+
import gay.`object`.hexdebug.config.HexDebugClientConfig
66
import gay.`object`.hexdebug.items.DebuggerItem
77
import gay.`object`.hexdebug.networking.msg.MsgDebugAdapterProxy
88
import io.ktor.network.selector.*
@@ -41,8 +41,8 @@ data class DebugProxyClient(val input: InputStream, val output: OutputStream) {
4141
var instance: DebugProxyClient? = null
4242
private set
4343

44-
private val enabled get() = HexDebugConfig.client.openDebugPort
45-
private val port get() = HexDebugConfig.client.debugPort
44+
private val enabled get() = HexDebugClientConfig.config.openDebugPort
45+
private val port get() = HexDebugClientConfig.config.debugPort
4646

4747
private val executorService = Executors.newCachedThreadPool()
4848

@@ -51,7 +51,7 @@ data class DebugProxyClient(val input: InputStream, val output: OutputStream) {
5151
private var serverJob: Job? = null
5252

5353
fun init() {
54-
HexDebugConfig.holder.registerSaveListener { _, _ ->
54+
HexDebugClientConfig.holder.registerSaveListener { _, _ ->
5555
reload()
5656
InteractionResult.PASS
5757
}

Common/src/main/kotlin/gay/object/hexdebug/blocks/splicing/SplicingTableBlockEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import gay.`object`.hexdebug.blocks.base.ContainerDataLongDelegate
2323
import gay.`object`.hexdebug.blocks.base.ContainerDataSelectionDelegate
2424
import gay.`object`.hexdebug.casting.eval.FakeCastEnv
2525
import gay.`object`.hexdebug.casting.eval.SplicingTableCastEnv
26-
import gay.`object`.hexdebug.config.HexDebugConfig
26+
import gay.`object`.hexdebug.config.HexDebugServerConfig
2727
import gay.`object`.hexdebug.gui.splicing.SplicingTableMenu
2828
import gay.`object`.hexdebug.registry.HexDebugBlockEntities
2929
import gay.`object`.hexdebug.splicing.*
@@ -437,7 +437,7 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
437437
override fun writeable() = listHolder?.writeable() ?: false
438438

439439
companion object {
440-
private val config get() = HexDebugConfig.server
440+
private val config get() = HexDebugServerConfig.config
441441

442442
private val mediaCost get() = config.splicingTableMediaCost
443443
private val maxMedia get() = config.splicingTableMaxMedia.coerceIn(1, null)

Common/src/main/kotlin/gay/object/hexdebug/casting/eval/SplicingTableCastEnv.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment
88
import at.petrak.hexcasting.api.utils.extractMedia
99
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
1010
import gay.`object`.hexdebug.blocks.splicing.SplicingTableBlockEntity
11-
import gay.`object`.hexdebug.config.HexDebugConfig
11+
import gay.`object`.hexdebug.config.HexDebugServerConfig
1212
import net.minecraft.core.BlockPos
1313
import net.minecraft.core.Direction
1414
import net.minecraft.server.level.ServerPlayer
@@ -80,7 +80,7 @@ class SplicingTableCastEnv(
8080
return true
8181
}
8282

83-
return isVecInRadius(vec, blockPos.center, HexDebugConfig.server.splicingTableAmbit)
83+
return isVecInRadius(vec, blockPos.center, HexDebugServerConfig.config.splicingTableAmbit)
8484
}
8585

8686
override fun getCastingHand(): InteractionHand = castingHand
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package gay.`object`.hexdebug.config
2+
3+
import gay.`object`.hexdebug.HexDebug
4+
import me.shedaniel.autoconfig.AutoConfig
5+
import me.shedaniel.autoconfig.ConfigData
6+
import me.shedaniel.autoconfig.ConfigHolder
7+
import me.shedaniel.autoconfig.annotation.Config
8+
import me.shedaniel.autoconfig.annotation.ConfigEntry.Category
9+
import me.shedaniel.autoconfig.annotation.ConfigEntry.Gui.Tooltip
10+
import me.shedaniel.autoconfig.annotation.ConfigEntry.Gui.TransitiveObject
11+
import me.shedaniel.autoconfig.serializer.PartitioningSerializer
12+
import me.shedaniel.autoconfig.serializer.PartitioningSerializer.GlobalData
13+
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer
14+
import net.minecraft.world.InteractionResult
15+
16+
object HexDebugClientConfig {
17+
@JvmStatic
18+
lateinit var holder: ConfigHolder<GlobalConfig>
19+
20+
@JvmStatic
21+
val config get() = holder.config.client
22+
23+
fun init() {
24+
holder = AutoConfig.register(
25+
GlobalConfig::class.java,
26+
PartitioningSerializer.wrap(::Toml4jConfigSerializer),
27+
)
28+
29+
// when we change the server config in the client gui, also send it to the server config class
30+
holder.registerSaveListener { _, config ->
31+
HexDebugServerConfig.holder.config = HexDebugServerConfig.GlobalConfig(config.server)
32+
InteractionResult.PASS
33+
}
34+
}
35+
36+
@Config(name = HexDebug.MODID)
37+
class GlobalConfig : GlobalData() {
38+
@Category("client")
39+
@TransitiveObject
40+
val client = ClientConfig()
41+
42+
@Category("server")
43+
@TransitiveObject
44+
val server = HexDebugServerConfig.ServerConfig()
45+
}
46+
47+
@Config(name = "client")
48+
class ClientConfig : ConfigData {
49+
@Tooltip
50+
val openDebugPort: Boolean = true
51+
52+
@Tooltip
53+
val debugPort: Int = 4444
54+
55+
@Tooltip
56+
val smartDebuggerSneakScroll: Boolean = true
57+
58+
@Tooltip
59+
val debuggerDisplayMode: DebuggerDisplayMode = DebuggerDisplayMode.ENABLED
60+
61+
@Tooltip
62+
val showDebugClientLineNumber: Boolean = false
63+
64+
@Tooltip
65+
val invertSplicingTableScrollDirection: Boolean = false
66+
}
67+
}
68+
69+
enum class DebuggerDisplayMode {
70+
DISABLED,
71+
NOT_CONNECTED,
72+
ENABLED,
73+
}

Common/src/main/kotlin/gay/object/hexdebug/config/HexDebugConfig.kt renamed to Common/src/main/kotlin/gay/object/hexdebug/config/HexDebugServerConfig.kt

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ import me.shedaniel.autoconfig.serializer.PartitioningSerializer
1616
import me.shedaniel.autoconfig.serializer.PartitioningSerializer.GlobalData
1717
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer
1818
import net.minecraft.network.FriendlyByteBuf
19+
import net.minecraft.world.InteractionResult
1920

2021
// we can't use a companion object because GlobalData sees the field and throws an error :/
2122

22-
object HexDebugConfig {
23+
object HexDebugServerConfig {
2324
@JvmStatic
2425
lateinit var holder: ConfigHolder<GlobalConfig>
2526

2627
@JvmStatic
27-
val client get() = holder.config.client
28-
29-
@JvmStatic
30-
val server get() = syncedServerConfig ?: holder.config.server
28+
val config get() = syncedServerConfig ?: holder.config.server
3129

3230
// only used on the client, probably
3331
private var syncedServerConfig: ServerConfig? = null
@@ -38,9 +36,8 @@ object HexDebugConfig {
3836
PartitioningSerializer.wrap(::Toml4jConfigSerializer),
3937
)
4038

41-
PlayerEvent.PLAYER_JOIN.register { player ->
42-
MsgSyncConfigS2C(holder.config.server).sendToPlayer(player)
43-
}
39+
// never save the server config here; that happens in the client config gui
40+
holder.registerSaveListener { _, _ -> InteractionResult.FAIL }
4441
}
4542

4643
fun initClient() {
@@ -49,41 +46,23 @@ object HexDebugConfig {
4946
}
5047
}
5148

49+
fun initServer() {
50+
// don't sync the config in singleplayer, to allow changing server configs without reloading the world
51+
PlayerEvent.PLAYER_JOIN.register { player ->
52+
MsgSyncConfigS2C(holder.config.server).sendToPlayer(player)
53+
}
54+
}
55+
5256
fun onSyncConfig(serverConfig: ServerConfig) {
5357
syncedServerConfig = serverConfig
5458
}
5559

5660
@Config(name = HexDebug.MODID)
57-
class GlobalConfig : GlobalData() {
58-
@Category("client")
59-
@TransitiveObject
60-
val client = ClientConfig()
61-
61+
class GlobalConfig(
6262
@Category("server")
6363
@TransitiveObject
64-
val server = ServerConfig()
65-
}
66-
67-
@Config(name = "client")
68-
class ClientConfig : ConfigData {
69-
@Tooltip
70-
val openDebugPort: Boolean = true
71-
72-
@Tooltip
73-
val debugPort: Int = 4444
74-
75-
@Tooltip
76-
val smartDebuggerSneakScroll: Boolean = true
77-
78-
@Tooltip
79-
val debuggerDisplayMode: DebuggerDisplayMode = DebuggerDisplayMode.ENABLED
80-
81-
@Tooltip
82-
val showDebugClientLineNumber: Boolean = false
83-
84-
@Tooltip
85-
val invertSplicingTableScrollDirection: Boolean = false
86-
}
64+
val server: ServerConfig = ServerConfig(),
65+
) : GlobalData()
8766

8867
@Config(name = "server")
8968
class ServerConfig : ConfigData {
@@ -115,20 +94,12 @@ object HexDebugConfig {
11594
buf.writeDouble(splicingTableAmbit)
11695
}
11796

118-
companion object {
119-
fun decode(buf: FriendlyByteBuf) = ServerConfig().apply {
120-
maxUndoStackSize = buf.readInt()
121-
splicingTableMediaCost = buf.readLong()
122-
splicingTableMaxMedia = buf.readLong()
123-
splicingTableCastingCooldown = buf.readInt()
124-
splicingTableAmbit = buf.readDouble()
125-
}
97+
fun decode(buf: FriendlyByteBuf) {
98+
maxUndoStackSize = buf.readInt()
99+
splicingTableMediaCost = buf.readLong()
100+
splicingTableMaxMedia = buf.readLong()
101+
splicingTableCastingCooldown = buf.readInt()
102+
splicingTableAmbit = buf.readDouble()
126103
}
127104
}
128105
}
129-
130-
enum class DebuggerDisplayMode {
131-
DISABLED,
132-
NOT_CONNECTED,
133-
ENABLED,
134-
}

Common/src/main/kotlin/gay/object/hexdebug/gui/splicing/SplicingTableScreen.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import at.petrak.hexcasting.api.utils.asTranslatedComponent
44
import at.petrak.hexcasting.client.gui.GuiSpellcasting
55
import com.mojang.blaze3d.systems.RenderSystem
66
import gay.`object`.hexdebug.HexDebug
7-
import gay.`object`.hexdebug.config.HexDebugConfig
7+
import gay.`object`.hexdebug.config.HexDebugClientConfig
8+
import gay.`object`.hexdebug.config.HexDebugServerConfig
89
import gay.`object`.hexdebug.gui.splicing.widgets.*
910
import gay.`object`.hexdebug.splicing.IOTA_BUTTONS
1011
import gay.`object`.hexdebug.splicing.Selection
@@ -46,7 +47,7 @@ class SplicingTableScreen(
4647
private val hasMediaItem get() = menu.mediaSlot.hasItem()
4748
val hasStaffItem get() = menu.staffSlot.hasItem()
4849

49-
private val hasMediaForAction get() = menu.media >= HexDebugConfig.server.splicingTableMediaCost
50+
private val hasMediaForAction get() = menu.media >= HexDebugServerConfig.config.splicingTableMediaCost
5051

5152
private var prevSelection: Selection? = selection
5253
private var prevViewStartIndex = viewStartIndex
@@ -533,11 +534,19 @@ class SplicingTableScreen(
533534
)
534535
}
535536

537+
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
538+
if (super.keyPressed(keyCode, scanCode, modifiers)) return true
539+
540+
541+
542+
return false
543+
}
544+
536545
// TODO: limit scroll to certain regions? (let's see if anyone complains first)
537546
override fun mouseScrolled(mouseX: Double, mouseY: Double, delta: Double): Boolean {
538547
if (super.mouseScrolled(mouseX, mouseY, delta)) return true
539548

540-
val adjustedDelta = if (HexDebugConfig.client.invertSplicingTableScrollDirection) {
549+
val adjustedDelta = if (HexDebugClientConfig.config.invertSplicingTableScrollDirection) {
541550
delta * -1
542551
} else {
543552
delta
@@ -736,7 +745,7 @@ class SplicingTableScreen(
736745
const val MAX_DIGIT_LEN = 4
737746
val MAX_DIGIT = 10f.pow(MAX_DIGIT_LEN).toInt() - 1
738747

739-
private val maxCastingCooldown get() = HexDebugConfig.server.splicingTableCastingCooldown
748+
private val maxCastingCooldown get() = HexDebugServerConfig.config.splicingTableCastingCooldown
740749

741750
fun getInstance() = Minecraft.getInstance().screen as? SplicingTableScreen
742751

Common/src/main/kotlin/gay/object/hexdebug/gui/splicing/widgets/MediaBar.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.utils.asTextComponent
55
import at.petrak.hexcasting.api.utils.asTranslatedComponent
66
import at.petrak.hexcasting.api.utils.mediaBarColor
77
import at.petrak.hexcasting.api.utils.styledWith
8-
import gay.`object`.hexdebug.config.HexDebugConfig
8+
import gay.`object`.hexdebug.config.HexDebugServerConfig
99
import gay.`object`.hexdebug.gui.splicing.SplicingTableMenu
1010
import gay.`object`.hexdebug.gui.splicing.SplicingTableScreen
1111
import net.minecraft.client.gui.GuiGraphics
@@ -29,7 +29,7 @@ class MediaBar(
2929
height: Int,
3030
) : AbstractWidget(x, y, width, height, Component.empty()) {
3131
private val media by menu::media
32-
private val maxMedia get() = HexDebugConfig.server.splicingTableMaxMedia
32+
private val maxMedia get() = HexDebugServerConfig.config.splicingTableMaxMedia
3333
private val fullness get() = if (maxMedia > 0) media.toDouble() / maxMedia else 0.0
3434

3535
override fun renderWidget(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, partialTick: Float) {

0 commit comments

Comments
 (0)