Skip to content

Commit 3b2904b

Browse files
committed
Improve cape loading times (hopefully), change the cape transparency mixin to use WrapOperation from mixinextras instead of a redirect, and fix wynntils capes not showing up
1 parent d935432 commit 3b2904b

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package me.cael.capes.mixins;
22

3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
35
import net.minecraft.client.render.RenderLayer;
46
import net.minecraft.client.render.entity.feature.CapeFeatureRenderer;
57
import net.minecraft.util.Identifier;
68
import org.spongepowered.asm.mixin.Mixin;
79
import org.spongepowered.asm.mixin.injection.At;
8-
import org.spongepowered.asm.mixin.injection.Redirect;
910

1011
@Mixin(CapeFeatureRenderer.class)
1112
public class MixinCapeFeatureRenderer {
1213

13-
@Redirect(method = "render*", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayer;getEntitySolid(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;"))
14-
private RenderLayer fixCapeTransparency(Identifier texture) {
14+
@WrapOperation(method = "render*", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayer;getEntitySolid(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;"))
15+
private RenderLayer fixCapeTransparency(Identifier texture, Operation<RenderLayer> original) {
1516
return RenderLayer.getArmorCutoutNoCull(texture);
1617
}
17-
}
18+
}

common/src/main/java/me/cael/capes/mixins/MixinEntityRenderDispatcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
@Mixin(EntityRenderDispatcher.class)
1414
public abstract class MixinEntityRenderDispatcher {
15+
1516
@Inject(method = "getRenderer(Lnet/minecraft/client/render/entity/state/EntityRenderState;)Lnet/minecraft/client/render/entity/EntityRenderer;", at = @At("HEAD"), cancellable = true)
16-
public <S extends EntityRenderState> void Capes$getPlaceholderRenderer(S state, CallbackInfoReturnable<EntityRenderer<?, ? super S>> cir) {
17+
public <S extends EntityRenderState> void getPlaceholderRenderer(S state, CallbackInfoReturnable<EntityRenderer<?, ? super S>> cir) {
1718
if (state instanceof PlaceholderEntityRenderState) {
1819
cir.setReturnValue((EntityRenderer<?, ? super S>) PlaceholderEntity.INSTANCE.getRenderer());
1920
}

common/src/main/java/me/cael/capes/mixins/MixinPlayerListEntry.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package me.cael.capes.mixins;
22

3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonParser;
35
import com.mojang.authlib.GameProfile;
6+
import com.mojang.authlib.properties.Property;
47
import me.cael.capes.CapeConfig;
58
import me.cael.capes.Capes;
69
import me.cael.capes.handler.PlayerHandler;
@@ -10,23 +13,30 @@
1013
import org.spongepowered.asm.mixin.Final;
1114
import org.spongepowered.asm.mixin.Mixin;
1215
import org.spongepowered.asm.mixin.Shadow;
16+
import org.spongepowered.asm.mixin.Unique;
1317
import org.spongepowered.asm.mixin.injection.At;
1418
import org.spongepowered.asm.mixin.injection.Inject;
1519
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1620

21+
import java.nio.charset.StandardCharsets;
22+
import java.util.Base64;
23+
import java.util.Optional;
1724
import java.util.function.Supplier;
1825

1926
@Mixin(PlayerListEntry.class)
20-
public class MixinPlayerListEntry {
27+
public abstract class MixinPlayerListEntry {
2128
@Shadow @Final private GameProfile profile;
2229

2330
@Inject(method = "texturesSupplier", at = @At("HEAD"))
2431
private static void loadTextures(GameProfile profile, CallbackInfoReturnable<Supplier<SkinTextures>> cir) {
25-
PlayerHandler.Companion.onLoadTexture(profile);
32+
if (capes$isValidProfile(profile)) {
33+
PlayerHandler.Companion.onLoadTexture(profile);
34+
}
2635
}
2736

2837
@Inject(method = "getSkinTextures", at = @At("TAIL"), cancellable = true)
2938
private void getCapeTexture(CallbackInfoReturnable<SkinTextures> cir) {
39+
if (!capes$isValidProfile(profile)) return;
3040
PlayerHandler handler = PlayerHandler.Companion.fromProfile(profile);
3141
if (handler.getHasCape()) {
3242
CapeConfig config = Capes.INSTANCE.getCONFIG();
@@ -41,6 +51,18 @@ private void getCapeTexture(CallbackInfoReturnable<SkinTextures> cir) {
4151
}
4252
}
4353

54+
@Unique
55+
private static boolean capes$isValidProfile(GameProfile profile) {
56+
Optional<Property> property = profile.getProperties().get("textures").stream().findFirst();
57+
if (property.isEmpty()) return false;
58+
59+
String textures = property.get().value();
60+
String json = new String(Base64.getDecoder().decode(textures), StandardCharsets.UTF_8);
61+
JsonElement element = JsonParser.parseString(json).getAsJsonObject().get("profileName");
62+
if (element == null) return false;
4463

64+
String profileName = element.getAsString();
65+
return profile.getId().version() == 4 || (profile.getId().version() == 2 && profile.getName().equals(profileName));
66+
}
4567

4668
}

common/src/main/kotlin/me/cael/capes/handler/PlayerHandler.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ import net.minecraft.util.Identifier
1717
import org.apache.commons.codec.binary.Base64
1818
import java.io.*
1919
import java.net.HttpURLConnection
20-
import java.net.URL
20+
import java.net.URI
2121
import java.util.*
2222
import java.util.concurrent.Executors
23-
import java.util.function.Supplier
2423

2524
class PlayerHandler(var profile: GameProfile) {
2625
val uuid: UUID = profile.id
@@ -37,7 +36,7 @@ class PlayerHandler(var profile: GameProfile) {
3736

3837
companion object {
3938
val instances = HashMap<UUID, PlayerHandler>()
40-
val capeExecutor = Executors.newFixedThreadPool(2)
39+
val capeExecutor = Executors.newCachedThreadPool()
4140

4241
fun fromProfile(profile: GameProfile) = instances[profile.id] ?: PlayerHandler(profile)
4342

@@ -61,8 +60,8 @@ class PlayerHandler(var profile: GameProfile) {
6160
}
6261

6362
fun connection(url: String): HttpURLConnection {
64-
val connection = URL(url).openConnection(MinecraftClient.getInstance().networkProxy) as HttpURLConnection
65-
connection.addRequestProperty("User-Agent", "Mozilla/4.0")
63+
val connection = URI(url).toURL().openConnection(MinecraftClient.getInstance().networkProxy) as HttpURLConnection
64+
connection.addRequestProperty("User-Agent", "Mozilla/5.0")
6665
connection.doInput = true
6766
connection.doOutput = false
6867
return connection
@@ -104,6 +103,7 @@ class PlayerHandler(var profile: GameProfile) {
104103
fun setWynntilsCape(connection: HttpURLConnection): Boolean {
105104
val body = JsonObject()
106105
body.addProperty("uuid", uuid.toString())
106+
body.addProperty("authToken", "")
107107
val data = body.toString().toByteArray()
108108
connection.doOutput = true
109109
connection.requestMethod = "POST"

common/src/main/kotlin/me/cael/capes/render/PlaceholderEntityRenderer.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ class PlaceholderEntityRenderer(ctx: EntityRendererFactory.Context, slim: Boolea
8484
playerEntityRenderState.leftWingRoll = -(Math.PI / 12).toFloat()
8585
playerEntityRenderState.leftWingPitch = (Math.PI / 12).toFloat()
8686

87-
88-
model.parts.forEach { it.visible = false }
8987
playerEntityRenderState.name = placeholderEntity.gameProfile.name
9088
}
9189
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ neoforge_yarn_mappings=1.21+build.4
77
enabled_platforms=fabric
88

99
archives_base_name=capes
10-
mod_version=1.5.6+1.21.7
10+
mod_version=1.5.7+1.21.7
1111
maven_group=me.capes
1212

1313
fabric_loader_version=0.16.14

0 commit comments

Comments
 (0)