2012-11-05 20:29:04 +01:00
|
|
|
package mekanism.client;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
import java.lang.reflect.Method;
|
2012-08-15 22:41:41 +02:00
|
|
|
import java.util.EnumSet;
|
2013-07-20 18:10:14 +02:00
|
|
|
import java.util.HashMap;
|
2013-06-21 17:47:01 +02:00
|
|
|
import java.util.List;
|
2013-07-20 18:10:14 +02:00
|
|
|
import java.util.Map;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-11-05 20:29:04 +01:00
|
|
|
import mekanism.common.Mekanism;
|
|
|
|
import mekanism.common.MekanismUtils;
|
2013-06-21 17:47:01 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2013-07-20 18:10:14 +02:00
|
|
|
import net.minecraft.client.entity.AbstractClientPlayer;
|
|
|
|
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureObject;
|
2013-06-21 17:47:01 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-07-20 18:10:14 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2013-06-21 17:47:01 +02:00
|
|
|
import net.minecraft.util.StringUtils;
|
2013-02-14 19:26:13 +01:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2012-08-15 22:41:41 +02:00
|
|
|
import cpw.mods.fml.common.ITickHandler;
|
|
|
|
import cpw.mods.fml.common.TickType;
|
2013-04-13 16:33:37 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-09-08 18:48:24 +02:00
|
|
|
/**
|
2012-11-05 20:29:04 +01:00
|
|
|
* Client-side tick handler for Mekanism. Used mainly for the update check upon startup.
|
2012-09-08 18:48:24 +02:00
|
|
|
* @author AidanBrady
|
|
|
|
*
|
|
|
|
*/
|
2013-04-13 16:33:37 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2012-08-15 22:41:41 +02:00
|
|
|
public class ClientTickHandler implements ITickHandler
|
|
|
|
{
|
2012-12-21 14:30:40 +01:00
|
|
|
public boolean hasNotified = false;
|
2012-11-27 01:18:50 +01:00
|
|
|
|
2013-06-21 17:47:01 +02:00
|
|
|
public Minecraft mc = FMLClientHandler.instance().getClient();
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
public static final String MIKE_CAPE = "https://dl.dropboxusercontent.com/s/ji06yflixnszcby/cape.png";
|
|
|
|
public static final String DONATE_CAPE = "https://dl.dropboxusercontent.com/u/90411166/donate.png";
|
|
|
|
public static final String AIDAN_CAPE = "https://dl.dropboxusercontent.com/u/90411166/aidan.png";
|
|
|
|
|
|
|
|
private Map<String, ThreadDownloadImageData> mikeDownload = new HashMap<String, ThreadDownloadImageData>();
|
|
|
|
private Map<String, ThreadDownloadImageData> donateDownload = new HashMap<String, ThreadDownloadImageData>();
|
|
|
|
private Map<String, ThreadDownloadImageData> aidanDownload = new HashMap<String, ThreadDownloadImageData>();
|
|
|
|
|
|
|
|
private void updateCape(EntityPlayer player, ThreadDownloadImageData newCape)
|
|
|
|
{
|
|
|
|
if(player.getHideCape())
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
Method m = EntityPlayer.class.getDeclaredMethod("setHideCape", Integer.class, Boolean.class);
|
|
|
|
m.invoke(player, 1, false);
|
|
|
|
} catch(Exception e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(MekanismUtils.getPrivateValue(player, AbstractClientPlayer.class, "field_110315_c") != newCape)
|
|
|
|
{
|
|
|
|
MekanismUtils.setPrivateValue(player, newCape, AbstractClientPlayer.class, "field_110315_c");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResourceLocation getCapeResource(EntityPlayer player)
|
|
|
|
{
|
|
|
|
if(player instanceof AbstractClientPlayer)
|
|
|
|
{
|
|
|
|
return (ResourceLocation)MekanismUtils.getPrivateValue(player, AbstractClientPlayer.class, "field_110313_e");
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ThreadDownloadImageData getCape(EntityPlayer player, String cape)
|
|
|
|
{
|
|
|
|
TextureManager texturemanager = Minecraft.getMinecraft().func_110434_K();
|
|
|
|
Object object = texturemanager.func_110581_b(getCapeResource(player));
|
|
|
|
|
|
|
|
if(object == null)
|
|
|
|
{
|
|
|
|
object = new ThreadDownloadImageData(cape, getCapeResource(player), new CapeBufferDownload());
|
|
|
|
texturemanager.func_110579_a(getCapeResource(player), (TextureObject)object);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ThreadDownloadImageData)object;
|
|
|
|
}
|
2013-06-21 17:47:01 +02:00
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
|
|
|
{
|
2013-06-21 17:47:01 +02:00
|
|
|
if(!hasNotified && mc.theWorld != null && Mekanism.latestVersionNumber != null && Mekanism.recentNews != null)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2013-06-21 17:47:01 +02:00
|
|
|
MekanismUtils.checkForUpdates(mc.thePlayer);
|
2012-12-21 14:30:40 +01:00
|
|
|
hasNotified = true;
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
2013-06-21 17:47:01 +02:00
|
|
|
|
|
|
|
if(mc.theWorld != null)
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
for(EntityPlayer entityPlayer : (List<EntityPlayer>)mc.theWorld.playerEntities)
|
2013-06-21 17:47:01 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(entityPlayer instanceof AbstractClientPlayer)
|
2013-06-24 18:24:04 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
AbstractClientPlayer player = (AbstractClientPlayer)entityPlayer;
|
|
|
|
|
|
|
|
if(player != null)
|
|
|
|
{
|
2013-06-24 18:24:04 +02:00
|
|
|
if(StringUtils.stripControlCodes(player.username).equals("mikeacttck"))
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(mikeDownload.get(player.username) == null)
|
|
|
|
{
|
|
|
|
mikeDownload.put(player.username, getCape(player, MIKE_CAPE));
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCape(player, mikeDownload.get(player.username));
|
2013-06-24 18:24:04 +02:00
|
|
|
}
|
|
|
|
else if(StringUtils.stripControlCodes(player.username).equals("aidancbrady"))
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(aidanDownload.get(player.username) == null)
|
|
|
|
{
|
|
|
|
aidanDownload.put(player.username, getCape(player, AIDAN_CAPE));
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCape(player, aidanDownload.get(player.username));
|
2013-06-24 18:24:04 +02:00
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
else if(Mekanism.donators.contains(StringUtils.stripControlCodes(player.username)) || player.username.contains("Player"))
|
2013-06-24 18:24:04 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(donateDownload.get(player.username) == null)
|
|
|
|
{
|
|
|
|
donateDownload.put(player.username, getCape(player, DONATE_CAPE));
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCape(player, donateDownload.get(player.username));
|
2013-06-24 18:24:04 +02:00
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
}
|
2013-06-24 18:24:04 +02:00
|
|
|
}
|
2013-06-21 17:47:01 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
|
|
|
{
|
2013-02-14 19:26:13 +01:00
|
|
|
if(Mekanism.audioHandler != null)
|
2012-12-30 22:34:45 +01:00
|
|
|
{
|
2013-02-14 19:26:13 +01:00
|
|
|
synchronized(Mekanism.audioHandler.sounds)
|
|
|
|
{
|
|
|
|
Mekanism.audioHandler.onTick();
|
|
|
|
}
|
2012-12-30 22:34:45 +01:00
|
|
|
}
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
2013-02-14 19:26:13 +01:00
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
public EnumSet<TickType> ticks()
|
|
|
|
{
|
2012-08-24 02:04:52 +02:00
|
|
|
return EnumSet.of(TickType.CLIENT);
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
public String getLabel()
|
|
|
|
{
|
2013-01-21 02:15:59 +01:00
|
|
|
return "MekanismClient";
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
|
|
|
}
|