0.9th version code moves to repo

Support 1.7.2
This commit is contained in:
xfl03 committed 2014-04-15 17:51:54 +08:00
1 parent 8fd21a6675
commit 4e9ead2ad4
3 files changed
+258

No files matched your search

@@ -0,0 +1,145 @@
package idv.jlchntoz;
import net.minecraft.client.Minecraft;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 9th Revision 2014.4.15
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014
*/
public class CustomSkinLoader {
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$");
private final static Logger logger = Logger
.getLogger(CustomSkinLoader.class.getName());
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
public InputStream getPlayerSkinStream(String path) {
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//If is old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load
// again.
for (String l : isCloak ? cloakURLs : skinURLs) {
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
InputStream S = getStream(loc, true);
if (S == null)
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin")
+ " found in " + loc);
else
return S;
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful (?) to get skin.
BufferedInputStream IS = new BufferedInputStream(
C.getInputStream());
if (!CheckPNG) // If no need to check PNG header, just skip it.
return IS;
IS.mark(0);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N'
&& ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
return IS;
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
disconnect();
}
return null;
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
File mcdir = Minecraft.getMinecraft().mcDataDir;
skinURLs = readAllLines(mcdir, "skinurls.txt");
cloakURLs = readAllLines(mcdir, "capeurls.txt");
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
private static String[] readAllLines(File mcdir, String path) {
try {
File F = new File(mcdir, path);
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (!F.exists()) {
logger.log(Level.INFO, "Config file not found, create new one.");
F.createNewFile();
return new String[0];
} else if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
return str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
}
@@ -0,0 +1,112 @@
package net.minecraft.client.renderer;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import idv.jlchntoz.CustomSkinLoader;
public class ThreadDownloadImageData extends SimpleTexture
{
private static final Logger logger = LogManager.getLogger();
private static final AtomicInteger field_147643_d = new AtomicInteger(0);
private final String imageUrl;
private final IImageBuffer imageBuffer;
private BufferedImage bufferedImage;
private Thread imageThread;
private boolean textureUploaded;
private static final String __OBFID = "CL_00001049";
public ThreadDownloadImageData(String par1Str, ResourceLocation par2ResourceLocation, IImageBuffer par3IImageBuffer)
{
super(par2ResourceLocation);
this.imageUrl = par1Str;
this.imageBuffer = par3IImageBuffer;
}
private void func_147640_e()
{
if (!this.textureUploaded)
{
if (this.bufferedImage != null)
{
if (this.textureLocation != null)
{
this.func_147631_c();
}
TextureUtil.uploadTextureImage(super.getGlTextureId(), this.bufferedImage);
this.textureUploaded = true;
}
}
}
public int getGlTextureId()
{
this.func_147640_e();
return super.getGlTextureId();
}
public void func_147641_a(BufferedImage p_147641_1_)
{
this.bufferedImage = p_147641_1_;
}
public void loadTexture(IResourceManager par1ResourceManager) throws IOException
{
if (this.bufferedImage == null && this.textureLocation != null)
{
super.loadTexture(par1ResourceManager);
}
if (this.imageThread == null)
{
this.imageThread = new Thread("Texture Downloader #" + field_147643_d.incrementAndGet())
{
private static final String __OBFID = "CL_00001050";
public void run()
{
CustomSkinLoader Loader = new CustomSkinLoader();
try
{
BufferedImage var2 = ImageIO.read(Loader.getPlayerSkinStream(ThreadDownloadImageData.this.imageUrl));
if (ThreadDownloadImageData.this.imageBuffer != null)
{
var2 = ThreadDownloadImageData.this.imageBuffer.parseUserSkin(var2);
}
ThreadDownloadImageData.this.func_147641_a(var2);
}
catch (Exception var6)
{
ThreadDownloadImageData.logger.error("Couldn\'t download http texture", var6);
return;
}
}
};
this.imageThread.setDaemon(true);
this.imageThread.setName("Skin downloader: " + this.imageUrl);
this.imageThread.start();
}
}
public boolean isTextureUploaded()
{
this.func_147640_e();
return this.textureUploaded;
}
}
+1
View File
@@ -1,2 +1,3 @@
MCCustomSkinLoader
==================