mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-18 02:24:22 +01:00
You don't need to do this
# Conflicts: # src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo.java
This commit is contained in:
parent
74c1e6ffe1
commit
e03343b8ae
3 changed files with 32 additions and 43 deletions
|
@ -160,6 +160,16 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
||||||
return skins.getUnchecked(profile);
|
return skins.getUnchecked(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fetchAndLoadSkins(GameProfile profile, SkinManager.SkinAvailableCallback callback) {
|
||||||
|
loadProfileTextures(profile).thenAcceptAsync(m -> m.forEach((type, pp) -> {
|
||||||
|
loadTexture(type, pp, (typeIn, location, profileTexture) -> {
|
||||||
|
parseSkin(profile, typeIn, location, profileTexture);
|
||||||
|
|
||||||
|
callback.skinAvailable(typeIn, location, profileTexture);
|
||||||
|
});
|
||||||
|
}), Minecraft.getMinecraft()::addScheduledTask);
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceLocation loadTexture(Type type, MinecraftProfileTexture texture, @Nullable SkinManager.SkinAvailableCallback callback) {
|
public ResourceLocation loadTexture(Type type, MinecraftProfileTexture texture, @Nullable SkinManager.SkinAvailableCallback callback) {
|
||||||
String skinDir = type.toString().toLowerCase() + "s/";
|
String skinDir = type.toString().toLowerCase() + "s/";
|
||||||
|
|
||||||
|
@ -295,10 +305,13 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
||||||
|
|
||||||
// grab the metadata object via reflection. Object is live.
|
// grab the metadata object via reflection. Object is live.
|
||||||
Map<String, String> metadata = ProfileTextureUtil.getMetadata(texture);
|
Map<String, String> metadata = ProfileTextureUtil.getMetadata(texture);
|
||||||
|
|
||||||
boolean wasNull = metadata == null;
|
boolean wasNull = metadata == null;
|
||||||
|
|
||||||
if (wasNull) {
|
if (wasNull) {
|
||||||
metadata = new HashMap<>();
|
metadata = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ISkinParser parser : skinParsers) {
|
for (ISkinParser parser : skinParsers) {
|
||||||
try {
|
try {
|
||||||
parser.parse(profile, type, resource, metadata);
|
parser.parse(profile, type, resource, metadata);
|
||||||
|
@ -306,6 +319,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
||||||
logger.error("Exception thrown while parsing skin: ", t);
|
logger.error("Exception thrown while parsing skin: ", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasNull && !metadata.isEmpty()) {
|
if (wasNull && !metadata.isEmpty()) {
|
||||||
ProfileTextureUtil.setMetadata(texture, metadata);
|
ProfileTextureUtil.setMetadata(texture, metadata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,7 @@
|
||||||
package com.voxelmodpack.hdskins;
|
package com.voxelmodpack.hdskins;
|
||||||
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface INetworkPlayerInfo {
|
public interface INetworkPlayerInfo {
|
||||||
|
|
||||||
Optional<ResourceLocation> getResourceLocation(MinecraftProfileTexture.Type type);
|
|
||||||
|
|
||||||
Optional<MinecraftProfileTexture> getProfileTexture(MinecraftProfileTexture.Type type);
|
|
||||||
|
|
||||||
void reloadTextures();
|
void reloadTextures();
|
||||||
|
|
||||||
void setSkinType(String type);
|
void setSkinType(String type);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||||
import com.voxelmodpack.hdskins.INetworkPlayerInfo;
|
import com.voxelmodpack.hdskins.INetworkPlayerInfo;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
@ -18,8 +19,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@Mixin(NetworkPlayerInfo.class)
|
@Mixin(NetworkPlayerInfo.class)
|
||||||
public abstract class MixinNetworkPlayerInfo implements INetworkPlayerInfo {
|
public abstract class MixinNetworkPlayerInfo implements INetworkPlayerInfo {
|
||||||
|
@ -34,14 +33,8 @@ public abstract class MixinNetworkPlayerInfo implements INetworkPlayerInfo {
|
||||||
@Shadow private Map<Type, ResourceLocation> playerTextures;
|
@Shadow private Map<Type, ResourceLocation> playerTextures;
|
||||||
|
|
||||||
@SuppressWarnings("InvalidMemberReference") // mc-dev bug?
|
@SuppressWarnings("InvalidMemberReference") // mc-dev bug?
|
||||||
@Redirect(method = {
|
@Redirect(method = { "getLocationSkin", "getLocationCape", "getLocationElytra" },
|
||||||
"getLocationSkin",
|
at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;", remap = false))
|
||||||
"getLocationCape",
|
|
||||||
"getLocationElytra"
|
|
||||||
},
|
|
||||||
at = @At(value = "INVOKE",
|
|
||||||
target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;",
|
|
||||||
remap = false))
|
|
||||||
// synthetic
|
// synthetic
|
||||||
private Object getSkin(Map<Type, ResourceLocation> playerTextures, Object key) {
|
private Object getSkin(Map<Type, ResourceLocation> playerTextures, Object key) {
|
||||||
return getSkin(playerTextures, (Type) key);
|
return getSkin(playerTextures, (Type) key);
|
||||||
|
@ -49,16 +42,23 @@ public abstract class MixinNetworkPlayerInfo implements INetworkPlayerInfo {
|
||||||
|
|
||||||
// with generics
|
// with generics
|
||||||
private ResourceLocation getSkin(Map<Type, ResourceLocation> playerTextures, Type type) {
|
private ResourceLocation getSkin(Map<Type, ResourceLocation> playerTextures, Type type) {
|
||||||
return getResourceLocation(type).orElseGet(() -> playerTextures.get(type));
|
if (this.customTextures.containsKey(type)) {
|
||||||
|
return this.customTextures.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerTextures.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "getSkinType",
|
@Redirect(method = "getSkinType",
|
||||||
at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/NetworkPlayerInfo;skinType:Ljava/lang/String;"))
|
at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/NetworkPlayerInfo;skinType:Ljava/lang/String;"))
|
||||||
private String getTextureModel(NetworkPlayerInfo self) {
|
private String getTextureModel(NetworkPlayerInfo self) {
|
||||||
return getProfileTexture(Type.SKIN).map(profile -> {
|
if (customProfiles.containsKey(Type.SKIN)) {
|
||||||
String model = profile.getMetadata("model");
|
String model = customProfiles.get(Type.SKIN).getMetadata("model");
|
||||||
|
|
||||||
return model != null ? model : "default";
|
return model != null ? model : "default";
|
||||||
}).orElse(this.skinType);
|
}
|
||||||
|
|
||||||
|
return skinType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "loadPlayerTextures",
|
@Inject(method = "loadPlayerTextures",
|
||||||
|
@ -69,26 +69,10 @@ public abstract class MixinNetworkPlayerInfo implements INetworkPlayerInfo {
|
||||||
+ "Z)V",
|
+ "Z)V",
|
||||||
shift = At.Shift.BEFORE))
|
shift = At.Shift.BEFORE))
|
||||||
private void onLoadTexture(CallbackInfo ci) {
|
private void onLoadTexture(CallbackInfo ci) {
|
||||||
HDSkinManager.INSTANCE.loadProfileTextures(this.gameProfile)
|
HDSkinManager.INSTANCE.fetchAndLoadSkins(gameProfile, (type, location, profileTexture) -> {
|
||||||
.thenAcceptAsync(m -> m.forEach((type, profile) -> {
|
|
||||||
HDSkinManager.INSTANCE.loadTexture(type, profile, (typeIn, location, profileTexture) -> {
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
HDSkinManager.INSTANCE.parseSkin(gameProfile, typeIn, location, profileTexture);
|
|
||||||
});
|
|
||||||
customTextures.put(type, location);
|
customTextures.put(type, location);
|
||||||
customProfiles.put(type, profileTexture);
|
customProfiles.put(type, profileTexture);
|
||||||
});
|
});
|
||||||
}), Minecraft.getMinecraft()::addScheduledTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<ResourceLocation> getResourceLocation(Type type) {
|
|
||||||
return Optional.ofNullable(this.customTextures.get(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<MinecraftProfileTexture> getProfileTexture(Type type) {
|
|
||||||
return Optional.ofNullable(this.customProfiles.get(type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue