Try to fix SpectatorMenu

Forge only
This commit is contained in:
Alexander Xia committed 2018-02-10 20:21:26 +08:00
1 parent 9698d4098a
commit eee978fc83
4 files changed
+96 -1

No files matched your search

@@ -0,0 +1,60 @@
package customskinloader.fake;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
public class FakeClientPlayer {
//For Legacy Skin
public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username)
{
TextureManager textman = Minecraft.getMinecraft().getTextureManager();
ITextureObject ito = textman.getTexture(resourceLocationIn);
if (ito == null)
{
//if Legacy Skin for username not loaded yet
SkinManager skinman = Minecraft.getMinecraft().getSkinManager();
UUID offlineUUID=EntityPlayer.getOfflineUUID(username);
GameProfile offlineProfile=new GameProfile(offlineUUID,username);
skinman.loadProfileTextures(offlineProfile, new LegacyBuffer(resourceLocationIn), false);
}
return (ThreadDownloadImageData)ito;
}
public static ResourceLocation getLocationSkin(String username)
{
return new ResourceLocation("skins/" + username);
}
private static class LegacyBuffer implements SkinAvailableCallback{
ResourceLocation resourceLocationIn;
public LegacyBuffer(ResourceLocation resourceLocationIn) {
this.resourceLocationIn=resourceLocationIn;
}
@Override
public void skinAvailable(Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) {
if(typeIn!=Type.SKIN)
return;
TextureManager textman = Minecraft.getMinecraft().getTextureManager();
ITextureObject ito = textman.getTexture(location);
textman.loadTexture(resourceLocationIn, ito);
}
}
}
@@ -104,5 +104,4 @@ public class FakeSkinManager{
FakeSkinManager.makeCallback(callback,type, location, texture);
}
}
}
@@ -87,6 +87,7 @@ public class ProfileCache {
}
private void saveLocalProfile(String username,UserProfile profile){
String json=CustomSkinLoader.GSON.toJson(profile);
File localProfile=new File(PROFILE_CACHE_DIR,username+".json");
if(localProfile.exists())
localProfile.delete();
try {
@@ -0,0 +1,35 @@
package customskinloader.forge;
import java.util.ListIterator;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import customskinloader.forge.TransformerManager.IMethodTransformer;
import customskinloader.forge.TransformerManager.TransformTarget;
public class SpectatorMenuTransformer {
@TransformTarget(className="net.minecraft.client.gui.spectator.PlayerMenuObject",
methodNames={"<init>"},
desc="(Lcom/mojang/authlib/GameProfile;)V")
public static class PlayerMenuObjectTransformer implements IMethodTransformer{
@Override
public void transform(ClassNode cn, MethodNode mn) {
InsnList il=mn.instructions;
ListIterator<AbstractInsnNode> li=il.iterator();
while(li.hasNext()) {
AbstractInsnNode nn=li.next();
if(nn.getOpcode()!=Opcodes.INVOKESTATIC)
continue;
MethodInsnNode min=(MethodInsnNode)nn;
min.owner="customskinloader/fake/FakeClientPlayer";
}
}
}
}