Skip to content

Commit 93ab581

Browse files
committed
beanbag fucked up
1 parent 4807f3d commit 93ab581

File tree

2 files changed

+18
-32
lines changed

2 files changed

+18
-32
lines changed

src/main/java/com/lambda/mixin/render/CapeFeatureRendererMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public class CapeFeatureRendererMixin {
3434
@ModifyExpressionValue(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/client/render/entity/state/PlayerEntityRenderState;FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/SkinTextures;capeTexture()Lnet/minecraft/util/Identifier;"))
3535
Identifier renderCape(Identifier original, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, PlayerEntityRenderState player, float f, float g) {
36-
var entry = Lambda.getMc().getNetworkHandler().getPlayerListEntry(player.name);
36+
var entry = Lambda.getMc().getNetworkHandler().getPlayerListEntry(player.name); // this will cause issues if we try to render while not in game
3737
if (entry == null) return original;
3838

3939
var profile = entry.getProfile();

src/main/kotlin/com/lambda/network/CapeManager.kt

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ package com.lambda.network
1919

2020
import com.lambda.Lambda.LOG
2121
import com.lambda.Lambda.mc
22-
import com.lambda.context.SafeContext
22+
import com.lambda.config.Configurable
23+
import com.lambda.config.configurations.SecretsConfig
2324
import com.lambda.core.Loadable
2425
import com.lambda.event.events.WorldEvent
2526
import com.lambda.event.listener.SafeListener.Companion.listen
2627
import com.lambda.network.api.v1.endpoints.getCape
2728
import com.lambda.network.api.v1.endpoints.getCapes
2829
import com.lambda.network.api.v1.endpoints.setCape
30+
import com.lambda.threading.runGameScheduled
2931
import com.lambda.threading.runIO
30-
import com.lambda.threading.runSafe
3132
import com.lambda.util.FileUtils.createIfNotExists
3233
import com.lambda.util.FileUtils.downloadCompare
3334
import com.lambda.util.FileUtils.downloadIfNotPresent
@@ -44,23 +45,19 @@ import org.lwjgl.BufferUtils
4445
import java.util.*
4546
import java.util.concurrent.ConcurrentHashMap
4647
import kotlin.concurrent.fixedRateTimer
47-
import kotlin.io.path.extension
48-
import kotlin.io.path.inputStream
49-
import kotlin.io.path.nameWithoutExtension
50-
import kotlin.io.path.walk
5148
import kotlin.time.Duration.Companion.hours
5249
import kotlin.time.Duration.Companion.seconds
5350

54-
@Suppress("JavaIoSerializableObjectMustHaveReadResolve")
55-
object CapeManager : ConcurrentHashMap<UUID, String>(), Loadable {
56-
private val images = capes.walk()
57-
.filter { it.extension == "png" }
58-
.associate { it.nameWithoutExtension to NativeImageBackedTexture({ it.nameWithoutExtension }, read(it.inputStream())) }
59-
.onEach { (key, value) -> mc.textureManager.registerTexture(key.asIdentifier, value) }
51+
object CapeManager : Configurable(SecretsConfig), Loadable {
52+
override val name: String = "capes"
6053

54+
var currentCape by setting("cape", "")
55+
.onValueChangeUnsafe { _, to -> updateCape(to) }
56+
57+
val cache = ConcurrentHashMap<UUID, String>()
6158
private val fetchQueue = mutableListOf<UUID>()
6259

63-
val capeList = runBlocking {
60+
val availableCapes = runBlocking {
6461
capes.resolveFile("capes.txt")
6562
.isOlderThan(24.hours) {
6663
it.downloadIfNotPresent("${LambdaAPI.capes}.txt")
@@ -72,26 +69,15 @@ object CapeManager : ConcurrentHashMap<UUID, String>(), Loadable {
7269
}
7370
.createIfNotExists()
7471
.readText()
75-
.split("\n")
72+
.split(Regex("\\s+"))
7673
}
7774

78-
/**
79-
* Sets the current player's cape
80-
*
81-
* @param block Lambda called once the coroutine completes, it contains the throwable if any
82-
*/
8375
fun updateCape(cape: String, block: (Throwable?) -> Unit = {}) = runIO {
8476
setCape(cape).getOrThrow()
85-
86-
runSafe { fetchCape(player.uuid) }
77+
fetchCape(mc.gameProfile.id)
8778
}.invokeOnCompletion { block(it) }
8879

89-
/**
90-
* Fetches the cape of the given player id
91-
*
92-
* @param block Lambda called once the coroutine completes, it contains the throwable if any
93-
*/
94-
fun SafeContext.fetchCape(uuid: UUID, block: (Throwable?) -> Unit = {}) = runIO {
80+
fun fetchCape(uuid: UUID, block: (Throwable?) -> Unit = {}) = runIO {
9581
val cape = getCape(uuid).getOrNull() ?: return@runIO
9682

9783
val bytes = capes.resolveFile("${cape.id}.png")
@@ -105,12 +91,12 @@ object CapeManager : ConcurrentHashMap<UUID, String>(), Loadable {
10591

10692
val image = read(NativeImage.Format.RGBA, buffer)
10793

108-
mc.textureManager.registerTexture(cape.id.asIdentifier, NativeImageBackedTexture({ cape.id }, image))
94+
runGameScheduled { mc.textureManager.registerTexture(cape.id.asIdentifier, NativeImageBackedTexture({ cape.id }, image)) }
10995

110-
put(uuid, cape.id)
96+
cache[uuid] = cape.id
11197
}.invokeOnCompletion { block(it) }
11298

113-
override fun load() = "Loaded ${images.size} cached capes and ${capeList.size} remote capes"
99+
override fun load() = "Loaded ${availableCapes.size} capes"
114100

115101
init {
116102
fixedRateTimer(
@@ -122,7 +108,7 @@ object CapeManager : ConcurrentHashMap<UUID, String>(), Loadable {
122108

123109
runBlocking {
124110
getCapes(fetchQueue)
125-
.onSuccess { it.forEach { cape -> put(cape.uuid, cape.id) } }
111+
.onSuccess { it.forEach { cape -> cache[cape.uuid] = cape.id } }
126112

127113
fetchQueue.clear()
128114
}

0 commit comments

Comments
 (0)