mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-04-01 01:05:27 +02:00
Add support for model types. Still needs server support
Add back capes
This commit is contained in:
parent
429266b971
commit
aa9cd16293
5 changed files with 76 additions and 31 deletions
|
@ -68,7 +68,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.spongepowered:mixin:0.4.17-20160126.141141-3'
|
compile 'org.spongepowered:mixin:0.4.17-SNAPSHOT'
|
||||||
compile 'org.ow2.asm:asm-debug-all:5.0.3'
|
compile 'org.ow2.asm:asm-debug-all:5.0.3'
|
||||||
compile 'com.google.guava:guava:17.0'
|
compile 'com.google.guava:guava:17.0'
|
||||||
compile 'com.google.code.gson:gson:2.2.4'
|
compile 'com.google.code.gson:gson:2.2.4'
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Map;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
@ -41,26 +42,30 @@ public final class HDSkinManager {
|
||||||
private String skinUrl = "skins.voxelmodpack.com";
|
private String skinUrl = "skins.voxelmodpack.com";
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
||||||
private Map<GameProfile, ResourceLocation> skinCache = Maps.newHashMap();
|
private Map<GameProfile, Map<Type, MinecraftProfileTexture>> profileTextures = Maps.newHashMap();
|
||||||
|
private Map<GameProfile, Map<Type, ResourceLocation>> skinCache = Maps.newHashMap();
|
||||||
private List<ISkinModifier> skinModifiers = Lists.newArrayList();
|
private List<ISkinModifier> skinModifiers = Lists.newArrayList();
|
||||||
|
|
||||||
private HDSkinManager() {}
|
private HDSkinManager() {}
|
||||||
|
|
||||||
public static Optional<ResourceLocation> getSkin(GameProfile profile, boolean loadIfAbsent) {
|
public Optional<ResourceLocation> getSkinLocation(final GameProfile profile, Type type, boolean loadIfAbsent) {
|
||||||
return INSTANCE.getSkinLocation(profile, loadIfAbsent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<ResourceLocation> getSkinLocation(final GameProfile profile, boolean loadIfAbsent) {
|
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return Optional.absent();
|
return Optional.absent();
|
||||||
ResourceLocation skin = skinCache.get(profile);
|
if (!this.skinCache.containsKey(profile)) {
|
||||||
|
this.skinCache.put(profile, Maps.<Type, ResourceLocation> newHashMap());
|
||||||
|
}
|
||||||
|
ResourceLocation skin = this.skinCache.get(profile).get(type);
|
||||||
if (skin == null) {
|
if (skin == null) {
|
||||||
if (loadIfAbsent) {
|
if (loadIfAbsent) {
|
||||||
skinCache.put(profile, LOADING);
|
skinCache.get(profile).put(type, LOADING);
|
||||||
loadTexture(profile, Type.SKIN, new SkinAvailableCallback() {
|
loadTexture(profile, type, new SkinAvailableCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void skinAvailable(Type type, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
public void skinAvailable(Type type, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
||||||
skinCache.put(profile, location);
|
skinCache.get(profile).put(type, location);
|
||||||
|
if (!profileTextures.containsKey(profile)) {
|
||||||
|
profileTextures.put(profile, Maps.<Type, MinecraftProfileTexture> newHashMap());
|
||||||
|
}
|
||||||
|
profileTextures.get(profile).put(type, profileTexture);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -71,26 +76,17 @@ public final class HDSkinManager {
|
||||||
|
|
||||||
private void loadTexture(GameProfile profile, final Type type, final SkinAvailableCallback callback) {
|
private void loadTexture(GameProfile profile, final Type type, final SkinAvailableCallback callback) {
|
||||||
if (profile != null && profile.getId() != null) {
|
if (profile != null && profile.getId() != null) {
|
||||||
String uuid = UUIDTypeAdapter.fromUUID(profile.getId());
|
Map<Type, MinecraftProfileTexture> data = getProfileData(profile);
|
||||||
String url;
|
final MinecraftProfileTexture texture = data.get(type);
|
||||||
switch (type) {
|
if (texture == null) {
|
||||||
case SKIN:
|
return;
|
||||||
url = getCustomSkinURLForId(uuid, false);
|
|
||||||
break;
|
|
||||||
case CAPE:
|
|
||||||
url = getCustomCloakURLForId(uuid);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new NullPointerException("Skin type was null.");
|
|
||||||
}
|
}
|
||||||
// TODO use cache
|
|
||||||
final MinecraftProfileTexture texture = new MinecraftProfileTexture(url, null);
|
|
||||||
final ResourceLocation skin = new ResourceLocation("skins/" + texture.getHash());
|
final ResourceLocation skin = new ResourceLocation("skins/" + texture.getHash());
|
||||||
File file1 = new File(skinCacheDir, texture.getHash().substring(0, 2));
|
File file1 = new File(skinCacheDir, texture.getHash().substring(0, 2));
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
File file2 = new File(file1, texture.getHash());
|
File file2 = new File(file1, texture.getHash());
|
||||||
final IImageBuffer imagebufferdownload = new ImageBufferDownloadHD();
|
final IImageBuffer imagebufferdownload = new ImageBufferDownloadHD();
|
||||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(null, url,
|
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(null, texture.getUrl(),
|
||||||
DefaultPlayerSkin.getDefaultSkinLegacy(),
|
DefaultPlayerSkin.getDefaultSkinLegacy(),
|
||||||
new IImageBuffer() {
|
new IImageBuffer() {
|
||||||
public BufferedImage parseUserSkin(BufferedImage image) {
|
public BufferedImage parseUserSkin(BufferedImage image) {
|
||||||
|
@ -109,6 +105,24 @@ public final class HDSkinManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<Type, MinecraftProfileTexture> getProfileData(GameProfile profile) {
|
||||||
|
if (!enabled)
|
||||||
|
return ImmutableMap.of();
|
||||||
|
Map<Type, MinecraftProfileTexture> textures = this.profileTextures.get(profile);
|
||||||
|
if (textures == null) {
|
||||||
|
String uuid = UUIDTypeAdapter.fromUUID(profile.getId());
|
||||||
|
String skinUrl = getCustomSkinURLForId(uuid, false);
|
||||||
|
String capeUrl = getCustomCloakURLForId(uuid);
|
||||||
|
|
||||||
|
// TODO metadata (needs server support)
|
||||||
|
textures = ImmutableMap.of(
|
||||||
|
Type.SKIN, new MinecraftProfileTexture(skinUrl, null),
|
||||||
|
Type.CAPE, new MinecraftProfileTexture(capeUrl, null));
|
||||||
|
// this.profileTextures.put(profile, textures);
|
||||||
|
}
|
||||||
|
return textures;
|
||||||
|
}
|
||||||
|
|
||||||
private static Map<Type, MinecraftProfileTexture> getTexturesForProfile(GameProfile profile) {
|
private static Map<Type, MinecraftProfileTexture> getTexturesForProfile(GameProfile profile) {
|
||||||
LiteLoaderLogger.debug("Get textures for " + profile.getId(), new Object[0]);
|
LiteLoaderLogger.debug("Get textures for " + profile.getId(), new Object[0]);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||||
|
|
||||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||||
|
@ -18,15 +20,21 @@ public abstract class MixinPlayerInfo {
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
private GameProfile gameProfile;
|
private GameProfile gameProfile;
|
||||||
|
@Shadow
|
||||||
|
private ResourceLocation locationSkin;
|
||||||
|
@Shadow
|
||||||
|
private ResourceLocation locationCape;
|
||||||
|
@Shadow
|
||||||
|
public String skinType;
|
||||||
|
|
||||||
@Inject(method = "hasLocationSkin",
|
@Inject(method = "hasLocationSkin",
|
||||||
cancellable = true,
|
cancellable = true,
|
||||||
at = @At("RETURN") )
|
at = @At("RETURN") )
|
||||||
private void hasLocationSkin(CallbackInfoReturnable<Boolean> ci) {
|
private void hasLocationSkin(CallbackInfoReturnable<Boolean> ci) {
|
||||||
boolean has = ci.getReturnValueZ();
|
if (locationSkin == null) {
|
||||||
if (!has) {
|
|
||||||
// in case has no skin
|
// in case has no skin
|
||||||
ci.setReturnValue(HDSkinManager.getSkin(gameProfile, false).isPresent());
|
Optional<ResourceLocation> skin = HDSkinManager.INSTANCE.getSkinLocation(gameProfile, Type.SKIN, false);
|
||||||
|
ci.setReturnValue(skin.isPresent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,10 +42,33 @@ public abstract class MixinPlayerInfo {
|
||||||
cancellable = true,
|
cancellable = true,
|
||||||
at = @At("RETURN") )
|
at = @At("RETURN") )
|
||||||
private void getLocationSkin(CallbackInfoReturnable<ResourceLocation> ci) {
|
private void getLocationSkin(CallbackInfoReturnable<ResourceLocation> ci) {
|
||||||
Optional<ResourceLocation> skin = HDSkinManager.getSkin(gameProfile, true);
|
Optional<ResourceLocation> skin = HDSkinManager.INSTANCE.getSkinLocation(gameProfile, Type.SKIN, true);
|
||||||
if (skin.isPresent()) {
|
if (skin.isPresent()) {
|
||||||
// set the skin
|
// set the skin
|
||||||
ci.setReturnValue(skin.get());
|
ci.setReturnValue(skin.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "getLocationCape",
|
||||||
|
cancellable = true,
|
||||||
|
at = @At("RETURN") )
|
||||||
|
private void getLocationCape(CallbackInfoReturnable<ResourceLocation> ci) {
|
||||||
|
Optional<ResourceLocation> cape = HDSkinManager.INSTANCE.getSkinLocation(gameProfile, Type.CAPE, true);
|
||||||
|
if (cape.isPresent()) {
|
||||||
|
// set the cape
|
||||||
|
ci.setReturnValue(cape.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "getSkinType",
|
||||||
|
cancellable = true,
|
||||||
|
at = @At("RETURN") )
|
||||||
|
private void getSkinType(CallbackInfoReturnable<String> ci) {
|
||||||
|
MinecraftProfileTexture data = HDSkinManager.INSTANCE.getProfileData(gameProfile).get(Type.SKIN);
|
||||||
|
if (data != null) {
|
||||||
|
String type = data.getMetadata("model");
|
||||||
|
if (type != null)
|
||||||
|
ci.setReturnValue(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer;
|
import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer;
|
||||||
|
@ -27,7 +28,7 @@ public abstract class MixinSkullRenderer extends TileEntitySpecialRenderer {
|
||||||
private void onBindTexture(float x, float y, float z, EnumFacing facing, float rotation, int meta, GameProfile profile, int p_180543_8_,
|
private void onBindTexture(float x, float y, float z, EnumFacing facing, float rotation, int meta, GameProfile profile, int p_180543_8_,
|
||||||
CallbackInfo ci) {
|
CallbackInfo ci) {
|
||||||
if (profile != null) {
|
if (profile != null) {
|
||||||
Optional<ResourceLocation> skin = HDSkinManager.getSkin(profile, true);
|
Optional<ResourceLocation> skin = HDSkinManager.INSTANCE.getSkinLocation(profile, Type.SKIN, true);
|
||||||
if (skin.isPresent())
|
if (skin.isPresent())
|
||||||
// rebind
|
// rebind
|
||||||
bindTexture(skin.get());
|
bindTexture(skin.get());
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.brohoof.minelittlepony.gui.PonySettingPanel;
|
||||||
import com.brohoof.minelittlepony.hdskins.gui.EntityPonyModel;
|
import com.brohoof.minelittlepony.hdskins.gui.EntityPonyModel;
|
||||||
import com.brohoof.minelittlepony.hdskins.gui.GuiSkinsMineLP;
|
import com.brohoof.minelittlepony.hdskins.gui.GuiSkinsMineLP;
|
||||||
import com.brohoof.minelittlepony.hdskins.gui.RenderPonyModel;
|
import com.brohoof.minelittlepony.hdskins.gui.RenderPonyModel;
|
||||||
import com.brohoof.minelittlepony.model.PMAPI;
|
|
||||||
import com.brohoof.minelittlepony.renderer.RenderPonySkeleton;
|
import com.brohoof.minelittlepony.renderer.RenderPonySkeleton;
|
||||||
import com.brohoof.minelittlepony.renderer.RenderPonyVillager;
|
import com.brohoof.minelittlepony.renderer.RenderPonyVillager;
|
||||||
import com.brohoof.minelittlepony.renderer.RenderPonyZombie;
|
import com.brohoof.minelittlepony.renderer.RenderPonyZombie;
|
||||||
|
|
Loading…
Add table
Reference in a new issue