Skip to content

Commit 93c6df6

Browse files
committed
Bind codec to prevent keybinds from crashing after the trueMods rename
1 parent c9c606c commit 93c6df6

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/main/kotlin/com/lambda/Lambda.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.lambda
1919

2020
import com.google.gson.Gson
2121
import com.google.gson.GsonBuilder
22+
import com.lambda.config.serializer.BindCodec
2223
import com.lambda.config.serializer.BlockCodec
2324
import com.lambda.config.serializer.BlockPosCodec
2425
import com.lambda.config.serializer.ColorSerializer
@@ -29,6 +30,7 @@ import com.lambda.config.serializer.KeyCodeCodec
2930
import com.lambda.config.serializer.OptionalCodec
3031
import com.lambda.config.serializer.TextCodec
3132
import com.lambda.config.serializer.UUIDCodec
33+
import com.lambda.config.settings.complex.Bind
3234
import com.lambda.core.Loader
3335
import com.lambda.event.events.ClientEvent
3436
import com.lambda.event.listener.UnsafeListener.Companion.listenOnceUnsafe
@@ -87,6 +89,7 @@ object Lambda : ClientModInitializer {
8789
.registerTypeAdapter(ArrowItem::class.java, ItemCodec)
8890
.registerTypeAdapter(PotionItem::class.java, ItemCodec)
8991
.registerTypeAdapter(RangedWeaponItem::class.java, ItemCodec)
92+
.registerTypeAdapter(Bind::class.java, BindCodec)
9093
.create()
9194

9295
override fun onInitializeClient() {} // nop
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2026 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.config.serializer
19+
20+
import com.google.gson.JsonDeserializationContext
21+
import com.google.gson.JsonElement
22+
import com.google.gson.JsonObject
23+
import com.google.gson.JsonSerializationContext
24+
import com.lambda.config.Codec
25+
import com.lambda.config.settings.complex.Bind
26+
import java.lang.reflect.Type
27+
28+
object BindCodec : Codec<Bind> {
29+
override fun serialize(src: Bind, typeOfSrc: Type, context: JsonSerializationContext): JsonElement =
30+
JsonObject().apply {
31+
addProperty("key", src.key)
32+
addProperty("modifiers", src.modifiers)
33+
addProperty("mouse", src.mouse)
34+
}
35+
36+
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext) =
37+
json.asJsonObject.let { obj ->
38+
Bind(obj.get("key").asInt, obj.get("modifiers").asInt, obj.get("mouse").asInt)
39+
}
40+
}

0 commit comments

Comments
 (0)