diff options
author | Linnea Gräf <nea@nea.moe> | 2024-08-09 00:49:36 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-08-09 02:20:41 +0200 |
commit | 1606188d9ad65c66e9d873497ea3271dbdadaf77 (patch) | |
tree | a33ea87c76bd672fe3902455742ba42ae8c91ee1 /src/main/kotlin/moe/nea/firmament/util | |
parent | 2a023d0a8d4e9af1dff21ea1bc997dfa0c686b14 (diff) | |
download | Firmament-1606188d9ad65c66e9d873497ea3271dbdadaf77.tar.gz Firmament-1606188d9ad65c66e9d873497ea3271dbdadaf77.tar.bz2 Firmament-1606188d9ad65c66e9d873497ea3271dbdadaf77.zip |
Add custom block textures
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
3 files changed, 39 insertions, 3 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/IdentifierSerializer.kt b/src/main/kotlin/moe/nea/firmament/util/IdentifierSerializer.kt index feea9e9..65c5b1c 100644 --- a/src/main/kotlin/moe/nea/firmament/util/IdentifierSerializer.kt +++ b/src/main/kotlin/moe/nea/firmament/util/IdentifierSerializer.kt @@ -3,6 +3,8 @@ package moe.nea.firmament.util import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -11,7 +13,7 @@ import net.minecraft.util.Identifier object IdentifierSerializer : KSerializer<Identifier> { val delegateSerializer = String.serializer() override val descriptor: SerialDescriptor - get() = SerialDescriptor("Identifier", delegateSerializer.descriptor) + get() = PrimitiveSerialDescriptor("Identifier", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): Identifier { return Identifier.of(decoder.decodeSerializableValue(delegateSerializer)) diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt index 8935766..b0d3056 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MC.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt @@ -1,11 +1,10 @@ - - package moe.nea.firmament.util import io.github.moulberry.repo.data.Coordinate import java.util.concurrent.ConcurrentLinkedQueue import net.minecraft.client.MinecraftClient import net.minecraft.client.gui.screen.ingame.HandledScreen +import net.minecraft.client.render.WorldRenderer import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket import net.minecraft.registry.BuiltinRegistries import net.minecraft.registry.RegistryKeys @@ -24,6 +23,9 @@ object MC { while (true) { inGameHud.chatHud.addMessage(messageQueue.poll() ?: break) } + while (true) { + (nextTickTodos.poll() ?: break).invoke() + } } } @@ -58,7 +60,14 @@ object MC { instance.send(block) } + private val nextTickTodos = ConcurrentLinkedQueue<() -> Unit>() + fun nextTick(function: () -> Unit) { + nextTickTodos.add(function) + } + + inline val resourceManager get() = (instance.resourceManager as ReloadableResourceManagerImpl) + inline val worldRenderer: WorldRenderer get() = instance.worldRenderer inline val networkHandler get() = player?.networkHandler inline val instance get() = MinecraftClient.getInstance() inline val keyboard get() = instance.keyboard diff --git a/src/main/kotlin/moe/nea/firmament/util/json/BlockPosSerializer.kt b/src/main/kotlin/moe/nea/firmament/util/json/BlockPosSerializer.kt new file mode 100644 index 0000000..144b0a0 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/util/json/BlockPosSerializer.kt @@ -0,0 +1,25 @@ +package moe.nea.firmament.util.json + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.serializer +import net.minecraft.util.math.BlockPos + +object BlockPosSerializer : KSerializer<BlockPos> { + val delegate = serializer<List<Int>>() + + override val descriptor: SerialDescriptor + get() = SerialDescriptor("BlockPos", delegate.descriptor) + + override fun deserialize(decoder: Decoder): BlockPos { + val list = decoder.decodeSerializableValue(delegate) + require(list.size == 3) + return BlockPos(list[0], list[1], list[2]) + } + + override fun serialize(encoder: Encoder, value: BlockPos) { + encoder.encodeSerializableValue(delegate, listOf(value.x, value.y, value.z)) + } +} |