Skip to content

Commit bba0792

Browse files
committed
Merge to latest
1 parent 79a9192 commit bba0792

File tree

31 files changed

+252
-100
lines changed

31 files changed

+252
-100
lines changed

common/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ dependencies {
4747
implementation("com.github.Edouard127:KDiscordIPC:$discordIPCVersion")
4848
implementation("com.pngencoder:pngencoder:0.15.0")
4949

50+
// Fuel HTTP library
51+
implementation("com.github.kittinunf.fuel:fuel:$fuelVersion")
52+
implementation("com.github.kittinunf.fuel:fuel-gson:$fuelVersion")
53+
5054
// Add Kotlin
5155
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
5256

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.mojang.blaze3d.systems.RenderSystem.recordRenderCall
3333
import net.minecraft.block.Block
3434
import net.minecraft.client.MinecraftClient
3535
import net.minecraft.item.ItemStack
36+
import net.minecraft.registry.DynamicRegistryManager
3637
import net.minecraft.text.Text
3738
import net.minecraft.util.math.BlockPos
3839
import org.apache.logging.log4j.LogManager
@@ -64,7 +65,7 @@ object Lambda {
6465
.registerTypeAdapter(GameProfile::class.java, GameProfileSerializer)
6566
.registerTypeAdapter(Optional::class.java, OptionalSerializer)
6667
.registerTypeAdapter(ItemStack::class.java, ItemStackSerializer)
67-
.registerTypeAdapter(Text::class.java, Text.Serializer())
68+
.registerTypeAdapter(Text::class.java, Text.Serializer(DynamicRegistryManager.EMPTY))
6869
.create()
6970

7071
fun initialize(block: (Long) -> Unit) {

common/src/main/kotlin/com/lambda/brigadier/argument/GeometricArguments.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fun DefaultArgumentReader<RotationArgumentType>.value(): PosArgument =
5353
*/
5454
@BrigadierDsl
5555
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<RotationArgumentType>>.absolute(): Vec2f =
56-
RotationArgumentType.getRotation(context, name).toAbsoluteRotation(context.source)
56+
RotationArgumentType.getRotation(context, name).getRotation(context.source)
5757

5858
/**
5959
* Reads the set of [Direction.Axis] from the

common/src/main/kotlin/com/lambda/brigadier/argument/IdentifierArguments.kt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ package com.lambda.brigadier.argument
1919
import com.lambda.brigadier.*
2020
import net.minecraft.advancement.AdvancementEntry
2121
import net.minecraft.command.argument.IdentifierArgumentType
22+
import net.minecraft.command.argument.ItemPredicateArgumentType
23+
import net.minecraft.command.argument.ItemStackArgumentType
24+
import net.minecraft.command.argument.RegistryEntryArgumentType
25+
import net.minecraft.command.argument.RegistryKeyArgumentType
2226
import net.minecraft.loot.condition.LootCondition
2327
import net.minecraft.loot.function.LootFunction
2428
import net.minecraft.recipe.RecipeEntry
@@ -42,7 +46,7 @@ fun DefaultArgumentReader<IdentifierArgumentType>.value(): Identifier {
4246
* argument in the receiver [ArgumentReader]
4347
* as an [AdvancementEntry].
4448
*
45-
* @see IdentifierArgumentType.getAdvancementArgument
49+
* @see RegistryKeyArgumentType.getAdvancementEntry
4650
*/
4751
@BrigadierDsl
4852
fun ArgumentReader<
@@ -51,7 +55,7 @@ fun ArgumentReader<
5155
IdentifierArgumentType
5256
>
5357
>.asAdvancement(): AdvancementEntry {
54-
return IdentifierArgumentType.getAdvancementArgument(context, name)
58+
return RegistryKeyArgumentType.getAdvancementEntry(context, name)
5559
}
5660

5761
/**
@@ -61,15 +65,15 @@ fun ArgumentReader<
6165
*
6266
* @see IdentifierArgumentType.getPredicateArgument
6367
*/
64-
@BrigadierDsl
65-
fun ArgumentReader<
66-
ServerCommandSource,
67-
DefaultArgumentDescriptor<
68-
IdentifierArgumentType
69-
>
70-
>.asPredicate(): LootCondition {
71-
return IdentifierArgumentType.getPredicateArgument(context, name)
72-
}
68+
//@BrigadierDsl
69+
//fun ArgumentReader<
70+
// ServerCommandSource,
71+
// DefaultArgumentDescriptor<
72+
// IdentifierArgumentType
73+
// >
74+
// >.asPredicate(): LootCondition {
75+
// return IdentifierArgumentType.getPredicateArgument(context, name)
76+
//}
7377

7478
/**
7579
* Reads the [Identifier] value from the
@@ -78,15 +82,15 @@ fun ArgumentReader<
7882
*
7983
* @see IdentifierArgumentType.getItemModifierArgument
8084
*/
81-
@BrigadierDsl
82-
fun ArgumentReader<
83-
ServerCommandSource,
84-
DefaultArgumentDescriptor<
85-
IdentifierArgumentType
86-
>
87-
>.asItemModifier(): LootFunction {
88-
return IdentifierArgumentType.getItemModifierArgument(context, name)
89-
}
85+
//@BrigadierDsl
86+
//fun ArgumentReader<
87+
// ServerCommandSource,
88+
// DefaultArgumentDescriptor<
89+
// IdentifierArgumentType
90+
// >
91+
// >.asItemModifier(): LootFunction {
92+
// return IdentifierArgumentType.getItemModifierArgument(context, name)
93+
//}
9094

9195
/**
9296
* Reads the [Identifier] value from the
@@ -102,7 +106,7 @@ fun ArgumentReader<
102106
IdentifierArgumentType
103107
>
104108
>.asRecipe(): RecipeEntry<*> {
105-
return IdentifierArgumentType.getRecipeArgument(context, name)
109+
return RegistryKeyArgumentType.getRecipeEntry(context, name)
106110
}
107111

108112
/**
@@ -113,4 +117,4 @@ fun <S> identifier(
113117
name: String,
114118
): DefaultArgumentConstructor<S, IdentifierArgumentType> {
115119
return argument(name, IdentifierArgumentType.identifier())
116-
}
120+
}

common/src/main/kotlin/com/lambda/config/serializer/BlockPosSerializer.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,26 @@
1818
package com.lambda.config.serializer
1919

2020
import com.google.gson.*
21+
import com.mojang.serialization.JsonOps
2122
import net.minecraft.util.math.BlockPos
2223
import java.lang.reflect.Type
24+
import kotlin.jvm.optionals.getOrElse
2325

2426
object BlockPosSerializer : JsonSerializer<BlockPos>, JsonDeserializer<BlockPos> {
2527
override fun serialize(
26-
src: BlockPos?,
27-
typeOfSrc: Type?,
28-
context: JsonSerializationContext?,
28+
src: BlockPos,
29+
typeOfSrc: Type,
30+
context: JsonSerializationContext,
2931
): JsonElement =
30-
src?.let {
31-
JsonObject().apply {
32-
addProperty("x", it.x)
33-
addProperty("y", it.y)
34-
addProperty("z", it.z)
35-
}
36-
} ?: JsonNull.INSTANCE
32+
BlockPos.CODEC.encodeStart(JsonOps.INSTANCE, src)
33+
.orThrow
3734

3835
override fun deserialize(
3936
json: JsonElement?,
4037
typeOfT: Type?,
4138
context: JsonDeserializationContext?,
4239
): BlockPos =
43-
json?.asJsonObject?.let {
44-
BlockPos(it["x"].asInt, it["y"].asInt, it["z"].asInt)
45-
} ?: BlockPos.ORIGIN
40+
BlockPos.CODEC.parse(JsonOps.INSTANCE, json)
41+
.result()
42+
.getOrElse { BlockPos.ORIGIN }
4643
}

common/src/main/kotlin/com/lambda/config/serializer/BlockSerializer.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,29 @@
1818
package com.lambda.config.serializer
1919

2020
import com.google.gson.*
21+
import com.mojang.serialization.JsonOps
22+
import com.mojang.serialization.RecordBuilder
2123
import net.minecraft.block.Block
24+
import net.minecraft.block.Blocks
2225
import net.minecraft.registry.Registries
2326
import net.minecraft.util.Identifier
2427
import java.lang.reflect.Type
28+
import kotlin.jvm.optionals.getOrElse
2529

2630
object BlockSerializer : JsonSerializer<Block>, JsonDeserializer<Block> {
2731
override fun serialize(
28-
src: Block?,
29-
typeOfSrc: Type?,
30-
context: JsonSerializationContext?,
32+
src: Block,
33+
typeOfSrc: Type,
34+
context: JsonSerializationContext,
3135
): JsonElement =
32-
src?.let {
33-
JsonPrimitive(Registries.BLOCK.getId(it).toString())
34-
} ?: JsonNull.INSTANCE
36+
Registries.BLOCK.codec.encodeStart(JsonOps.INSTANCE, src)
37+
.orThrow
3538

3639
override fun deserialize(
3740
json: JsonElement?,
3841
typeOfT: Type?,
3942
context: JsonDeserializationContext?,
4043
): Block =
41-
Registries.BLOCK.get(Identifier.of(json?.asString))
44+
Registries.BLOCK.codec.parse(JsonOps.INSTANCE, json)
45+
.orThrow
4246
}

common/src/main/kotlin/com/lambda/config/serializer/ItemStackSerializer.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,34 @@ import com.google.gson.JsonDeserializationContext
2121
import com.google.gson.JsonDeserializer
2222
import com.google.gson.JsonElement
2323
import com.google.gson.JsonObject
24+
import com.google.gson.JsonParser
2425
import com.google.gson.JsonSerializationContext
2526
import com.google.gson.JsonSerializer
27+
import com.lambda.Lambda.mc
28+
import com.mojang.serialization.JsonOps
2629
import net.minecraft.item.ItemStack
2730
import net.minecraft.nbt.StringNbtReader
2831
import net.minecraft.nbt.visitor.StringNbtWriter
2932
import net.minecraft.registry.Registries
3033
import net.minecraft.util.Identifier
3134
import java.lang.reflect.Type
35+
import kotlin.jvm.optionals.getOrElse
3236

3337
object ItemStackSerializer : JsonSerializer<ItemStack>, JsonDeserializer<ItemStack> {
3438
override fun serialize(
3539
stack: ItemStack,
3640
typeOfSrc: Type,
3741
context: JsonSerializationContext
3842
): JsonElement =
39-
JsonObject().apply {
40-
addProperty("id", stack.item.registryEntry.key.get().value.toString())
41-
addProperty("count", stack.count)
42-
stack.nbt?.let { addProperty("tag", StringNbtWriter().apply(it)) }
43-
}
43+
ItemStack.CODEC.encodeStart(JsonOps.INSTANCE, stack)
44+
.orThrow
4445

4546
override fun deserialize(
4647
json: JsonElement,
4748
typeOfT: Type,
4849
context: JsonDeserializationContext
49-
): ItemStack {
50-
val id = json.asJsonObject.get("id").asString
51-
val count = json.asJsonObject.get("count").asInt
52-
val nbt = json.asJsonObject?.get("tag")?.asString
53-
54-
val item = Registries.ITEM.get(Identifier(id))
55-
56-
return ItemStack(item, count).apply { nbt?.let { setNbt(StringNbtReader.parse(it)) } }
57-
}
50+
): ItemStack =
51+
ItemStack.CODEC.parse(JsonOps.INSTANCE, json)
52+
.result()
53+
.getOrElse { ItemStack.EMPTY }
5854
}

common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Animation(initialValue: Double, val update: (Double) -> Double) {
2828
private var currValue = initialValue
2929

3030
operator fun getValue(thisRef: Any?, property: KProperty<*>) =
31-
lerp(mc.partialTicks, prevValue, currValue)
31+
lerp(mc.partialTicks.toDouble(), prevValue, currValue)
3232

3333
operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) = setValue(valueIn)
3434

common/src/main/kotlin/com/lambda/graphics/renderer/esp/impl/ESPRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ abstract class ESPRenderer(tickedMode: Boolean) {
4747

4848
fun render() {
4949
shader.use()
50-
shader["u_TickDelta"] = mc.partialTicks
50+
shader["u_TickDelta"] = mc.partialTicks.toDouble()
5151
shader["u_CameraPosition"] = mc.gameRenderer.camera.pos
5252

5353
withFaceCulling(faces::render)

common/src/main/kotlin/com/lambda/interaction/construction/StructureRegistry.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import kotlin.io.path.*
4545
* It extends [ConcurrentHashMap] to allow concurrent access to structure templates by their names.
4646
* This registry supports multiple structure formats and automatically monitors changes in the structure directory.
4747
*/
48-
@OptIn(ExperimentalPathApi::class)
4948
@Suppress("JavaIoSerializableObjectMustHaveReadResolve")
5049
object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loadable {
5150
private val pathWatcher by lazy {
@@ -148,7 +147,7 @@ object StructureRegistry : ConcurrentHashMap<String, StructureTemplate>(), Loada
148147
private fun createStructure(nbt: NbtCompound, suffix: String): StructureTemplate =
149148
StructureTemplate().apply {
150149
serializers[suffix]
151-
?.invoke(this, Registries.BLOCK.readOnlyWrapper, nbt)
150+
?.invoke(this, Registries.BLOCK, nbt)
152151
?.let { throw it } // ToDo: Maybe use propagation instead of errors as values
153152
}
154153

0 commit comments

Comments
 (0)