Added dev capes, because you know, being special is cool :P
This commit is contained in:
parent
a99679b06b
commit
4c2a40268f
4 changed files with 188 additions and 0 deletions
4
capes.txt
Normal file
4
capes.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Adubbz:https://raw.github.com/Glitchfiend/BiomesOPlenty/master/capes/dev_cape.png
|
||||
Amnet:https://raw.github.com/Glitchfiend/BiomesOPlenty/master/capes/dev_cape.png
|
||||
Forstride:https://raw.github.com/Glitchfiend/BiomesOPlenty/master/capes/dev_cape.png
|
||||
ted80:https://raw.github.com/Glitchfiend/BiomesOPlenty/master/capes/dev_cape.png
|
BIN
capes/dev_cape.png
Normal file
BIN
capes/dev_cape.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -20,6 +20,7 @@ import biomesoplenty.configuration.configfile.BOPConfigurationIDs;
|
|||
import biomesoplenty.configuration.configfile.BOPConfigurationMisc;
|
||||
import biomesoplenty.eventhandlers.BonemealEventHandler;
|
||||
import biomesoplenty.eventhandlers.BreakSpeedEventHandler;
|
||||
import biomesoplenty.eventhandlers.CapeEventHandler;
|
||||
import biomesoplenty.eventhandlers.EntityEventHandler;
|
||||
import biomesoplenty.eventhandlers.FlipperMovementEventHandler;
|
||||
import biomesoplenty.eventhandlers.FluidEventHandler;
|
||||
|
@ -113,6 +114,10 @@ public class BiomesOPlenty
|
|||
MinecraftForge.EVENT_BUS.register(new BreakSpeedEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new MovementHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new FlipperMovementEventHandler());
|
||||
if (event.getSide() == Side.CLIENT)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(new CapeEventHandler());
|
||||
}
|
||||
|
||||
proxy.registerRenderers();
|
||||
|
||||
|
|
179
common/biomesoplenty/eventhandlers/CapeEventHandler.java
Normal file
179
common/biomesoplenty/eventhandlers/CapeEventHandler.java
Normal file
|
@ -0,0 +1,179 @@
|
|||
package biomesoplenty.eventhandlers;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class CapeEventHandler
|
||||
{
|
||||
private final String serverLocation = "https://raw.github.com/Glitchfiend/BiomesOPlenty/master/capes.txt";
|
||||
private final int timeout = 1000;
|
||||
|
||||
private static final Graphics TEST_GRAPHICS = new BufferedImage(128, 128,
|
||||
BufferedImage.TYPE_INT_RGB).getGraphics();
|
||||
private HashMap<String, String> cloaks = new HashMap<String, String>();
|
||||
private ArrayList<AbstractClientPlayer> capePlayers = new ArrayList<AbstractClientPlayer>();
|
||||
|
||||
public static CapeEventHandler instance;
|
||||
|
||||
public CapeEventHandler()
|
||||
{
|
||||
buildCloakURLDatabase();
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onPreRenderSpecials(RenderPlayerEvent.Specials.Pre event)
|
||||
{
|
||||
if (Loader.isModLoaded("shadersmod"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.entityPlayer instanceof AbstractClientPlayer)
|
||||
{
|
||||
AbstractClientPlayer abstractClientPlayer = (AbstractClientPlayer) event.entityPlayer;
|
||||
|
||||
if (!capePlayers.contains(abstractClientPlayer))
|
||||
{
|
||||
String cloakURL = cloaks.get(event.entityPlayer.username);
|
||||
|
||||
if (cloakURL == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
capePlayers.add(abstractClientPlayer);
|
||||
|
||||
ReflectionHelper.setPrivateValue(ThreadDownloadImageData.class, abstractClientPlayer.getTextureCape(), false, new String[] { "textureUploaded", "g" });
|
||||
|
||||
new Thread(new CloakThread(abstractClientPlayer, cloakURL)).start();
|
||||
event.renderCape = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void buildCloakURLDatabase()
|
||||
{
|
||||
URL url;
|
||||
try
|
||||
{
|
||||
url = new URL(serverLocation);
|
||||
URLConnection con = url.openConnection();
|
||||
con.setConnectTimeout(timeout);
|
||||
con.setReadTimeout(timeout);
|
||||
InputStream io = con.getInputStream();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(io));
|
||||
|
||||
String str;
|
||||
int linetracker = 1;
|
||||
while ((str = br.readLine()) != null)
|
||||
{
|
||||
if (!str.startsWith("--"))
|
||||
{
|
||||
if (str.contains(":"))
|
||||
{
|
||||
String nick = str.substring(0, str.indexOf(":"));
|
||||
String link = str.substring(str.indexOf(":") + 1);
|
||||
new Thread(new CloakPreload(link)).start();
|
||||
cloaks.put(nick, link);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println("[BiomesOPlenty] [skins.txt] Syntax error on line " + linetracker + ": " + str);
|
||||
}
|
||||
}
|
||||
linetracker++;
|
||||
}
|
||||
|
||||
br.close();
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private class CloakThread implements Runnable
|
||||
{
|
||||
AbstractClientPlayer abstractClientPlayer;
|
||||
String cloakURL;
|
||||
|
||||
public CloakThread(AbstractClientPlayer player, String cloak)
|
||||
{
|
||||
abstractClientPlayer = player;
|
||||
cloakURL = cloak;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Image cape = new ImageIcon(new URL(cloakURL)).getImage();
|
||||
BufferedImage bo = new BufferedImage(cape.getWidth(null),
|
||||
cape.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
bo.getGraphics().drawImage(cape, 0, 0, null);
|
||||
|
||||
ReflectionHelper.setPrivateValue(ThreadDownloadImageData.class, abstractClientPlayer.getTextureCape(), bo, new String[] { "bufferedImage", "d" });
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class CloakPreload implements Runnable
|
||||
{
|
||||
String cloakURL;
|
||||
|
||||
public CloakPreload(String link)
|
||||
{
|
||||
cloakURL = link;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
TEST_GRAPHICS
|
||||
.drawImage(new ImageIcon(new URL(cloakURL)).getImage(),
|
||||
0, 0, null);
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshCapes()
|
||||
{
|
||||
cloaks.clear();
|
||||
capePlayers.clear();
|
||||
buildCloakURLDatabase();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue