Files
TinkersConstruct/src/main/java/tconstruct/armor/ArmorProxyClient.java
T

304 lines
13 KiB
Java
Raw Normal View History

2014-06-06 19:46:05 -08:00
package tconstruct.armor;
2014-06-06 19:46:05 -08:00
import java.util.ArrayList;
2013-08-01 20:54:56 -07:00
import java.util.Random;
2013-11-29 23:16:32 -05:00
2014-06-06 19:46:05 -08:00
import com.google.common.collect.Lists;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
2014-06-06 19:46:05 -08:00
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.renderer.Tessellator;
2014-02-08 13:30:19 -05:00
import net.minecraft.client.settings.GameSettings;
2014-06-06 19:46:05 -08:00
import net.minecraft.client.settings.KeyBinding;
2014-02-05 10:28:54 -05:00
import net.minecraft.entity.SharedMonsterAttributes;
2014-01-01 08:54:06 -05:00
import net.minecraft.entity.ai.attributes.IAttributeInstance;
2014-06-06 19:46:05 -08:00
import net.minecraft.entity.player.EntityPlayer;
2014-02-05 10:28:54 -05:00
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
2014-06-06 19:46:05 -08:00
import net.minecraft.world.World;
2013-08-01 20:54:56 -07:00
import net.minecraftforge.client.GuiIngameForge;
2014-02-05 10:28:54 -05:00
import net.minecraftforge.client.event.RenderGameOverlayEvent;
2013-08-01 20:54:56 -07:00
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
2014-06-06 19:46:05 -08:00
import net.minecraftforge.common.MinecraftForge;
import tconstruct.client.TControls;
import tconstruct.client.TKeyHandler;
import tconstruct.client.TProxyClient;
import tconstruct.client.gui.AdaptiveSmelteryGui;
import tconstruct.client.gui.ArmorExtendedGui;
import tconstruct.client.gui.CraftingStationGui;
import tconstruct.client.gui.FrypanGui;
import tconstruct.client.gui.FurnaceGui;
import tconstruct.client.gui.GuiLandmine;
import tconstruct.client.gui.KnapsackGui;
import tconstruct.client.gui.PartCrafterGui;
import tconstruct.client.gui.PatternChestGui;
import tconstruct.client.gui.SmelteryGui;
import tconstruct.client.gui.StencilTableGui;
import tconstruct.client.gui.ToolForgeGui;
import tconstruct.client.gui.ToolStationGui;
import tconstruct.client.tabs.InventoryTabArmorExtended;
import tconstruct.client.tabs.InventoryTabKnapsack;
import tconstruct.client.tabs.InventoryTabVanilla;
import tconstruct.client.tabs.TabRegistry;
2014-06-30 14:57:06 -08:00
import tconstruct.common.TProxyCommon;
2014-06-06 19:46:05 -08:00
import tconstruct.mechworks.MechworksProxyCommon;
import tconstruct.mechworks.inventory.ContainerLandmine;
import tconstruct.mechworks.logic.TileEntityLandmine;
import tconstruct.smeltery.SmelteryProxyCommon;
import tconstruct.smeltery.logic.AdaptiveSmelteryLogic;
import tconstruct.smeltery.logic.SmelteryLogic;
import tconstruct.tools.ToolProxyCommon;
import tconstruct.tools.logic.CraftingStationLogic;
import tconstruct.tools.logic.FrypanLogic;
import tconstruct.tools.logic.FurnaceLogic;
import tconstruct.tools.logic.PartBuilderLogic;
import tconstruct.tools.logic.PatternChestLogic;
import tconstruct.tools.logic.StencilTableLogic;
import tconstruct.tools.logic.ToolForgeLogic;
import tconstruct.tools.logic.ToolStationLogic;
import tconstruct.util.config.PHConstruct;
public class ArmorProxyClient extends ArmorProxyCommon
{
2014-06-06 19:46:05 -08:00
public ArmorProxyClient()
{
2014-06-30 14:57:06 -08:00
registerGuiHandler();
2014-06-06 19:46:05 -08:00
MinecraftForge.EVENT_BUS.register(this);
}
2014-06-30 14:57:06 -08:00
@Override
protected void registerGuiHandler()
{
super.registerGuiHandler();
TProxyCommon.registerClientGuiHandler(inventoryGui, this);
TProxyCommon.registerClientGuiHandler(armorGuiID, this);
TProxyCommon.registerClientGuiHandler(knapsackGuiID, this);
}
2014-06-06 19:46:05 -08:00
@Override
public Object getClientGuiElement (int ID, EntityPlayer player, World world, int x, int y, int z)
{
if (ID == ArmorProxyCommon.inventoryGui)
{
2014-06-06 19:46:05 -08:00
GuiInventory inventory = new GuiInventory(player);
TabRegistry.addTabsToInventory(inventory);
return inventory;
}
2014-06-06 19:46:05 -08:00
if (ID == ArmorProxyCommon.armorGuiID)
{
TProxyClient.armorExtended.init(Minecraft.getMinecraft().thePlayer);
return new ArmorExtendedGui(player.inventory, TProxyClient.armorExtended);
}
if (ID == ArmorProxyCommon.knapsackGuiID)
{
TProxyClient.knapsack.init(Minecraft.getMinecraft().thePlayer);
return new KnapsackGui(player.inventory, TProxyClient.knapsack);
}
return null;
2013-08-11 12:23:49 -07:00
}
2014-06-06 19:46:05 -08:00
@Override
public void registerTickHandler ()
{
FMLCommonHandler.instance().bus().register(new ArmorTickHandler());
new ArmorTickHandler();
}
/* Keybindings */
public static TControls controlInstance;
2013-11-19 20:57:52 -08:00
2014-06-06 19:46:05 -08:00
@Override
public void registerKeys ()
2013-11-19 20:57:52 -08:00
{
2014-06-06 19:46:05 -08:00
controlInstance = new TControls();
uploadKeyBindingsToGame(Minecraft.getMinecraft().gameSettings, controlInstance);
TabRegistry.registerTab(new InventoryTabVanilla());
TabRegistry.registerTab(new InventoryTabArmorExtended());
TabRegistry.registerTab(new InventoryTabKnapsack());
2013-11-19 20:57:52 -08:00
}
2014-06-06 19:46:05 -08:00
public void uploadKeyBindingsToGame (GameSettings settings, TKeyHandler keyhandler)
{
2014-06-06 19:46:05 -08:00
ArrayList<KeyBinding> harvestedBindings = Lists.newArrayList();
for (KeyBinding kb : keyhandler.keyBindings)
{
2014-06-06 19:46:05 -08:00
harvestedBindings.add(kb);
}
2014-06-06 19:46:05 -08:00
KeyBinding[] modKeyBindings = harvestedBindings.toArray(new KeyBinding[harvestedBindings.size()]);
KeyBinding[] allKeys = new KeyBinding[settings.keyBindings.length + modKeyBindings.length];
System.arraycopy(settings.keyBindings, 0, allKeys, 0, settings.keyBindings.length);
System.arraycopy(modKeyBindings, 0, allKeys, settings.keyBindings.length, modKeyBindings.length);
settings.keyBindings = allKeys;
settings.loadOptions();
}
2014-06-06 19:46:05 -08:00
Minecraft mc = Minecraft.getMinecraft();
2013-07-28 19:56:01 -07:00
private static final ResourceLocation hearts = new ResourceLocation("tinker", "textures/gui/newhearts.png");
private static final ResourceLocation icons = new ResourceLocation("textures/gui/icons.png");
2014-02-16 14:23:50 -05:00
// public static int left_height = 39;
// public static int right_height = 39;
2013-08-01 20:54:56 -07:00
Random rand = new Random();
int updateCounter = 0;
2014-02-11 21:35:05 -05:00
2014-02-08 13:30:19 -05:00
GameSettings gs = Minecraft.getMinecraft().gameSettings;
/* HUD */
2014-01-01 08:54:06 -05:00
@SubscribeEvent
2013-08-01 20:54:56 -07:00
public void renderHealthbar (RenderGameOverlayEvent.Pre event)
{
2014-02-16 14:23:50 -05:00
if (!Loader.isModLoaded("tukmc_Vz"))// Loader check to avoid conflicting
// with a GUI mod (thanks Vazkii!)
{
if (event.type == ElementType.HEALTH)
2013-08-01 20:54:56 -07:00
{
updateCounter++;
2013-08-01 20:54:56 -07:00
2014-06-25 21:01:20 -04:00
ScaledResolution scaledresolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
int scaledWidth = scaledresolution.getScaledWidth();
int scaledHeight = scaledresolution.getScaledHeight();
int xBasePos = scaledWidth / 2 - 91;
int yBasePos = scaledHeight - 39;
2013-08-01 20:54:56 -07:00
boolean highlight = mc.thePlayer.hurtResistantTime / 3 % 2 == 1;
2013-08-01 20:54:56 -07:00
if (mc.thePlayer.hurtResistantTime < 10)
{
highlight = false;
}
2013-08-01 20:54:56 -07:00
2014-01-01 08:54:06 -05:00
IAttributeInstance attrMaxHealth = this.mc.thePlayer.getEntityAttribute(SharedMonsterAttributes.maxHealth);
int health = MathHelper.ceiling_float_int(mc.thePlayer.getHealth());
int healthLast = MathHelper.ceiling_float_int(mc.thePlayer.prevHealth);
float healthMax = (float) attrMaxHealth.getAttributeValue();
if (healthMax > 20)
healthMax = 20;
float absorb = this.mc.thePlayer.getAbsorptionAmount();
2013-08-01 20:54:56 -07:00
int healthRows = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F / 10.0F);
int rowHeight = Math.max(10 - (healthRows - 2), 3);
2013-08-01 20:54:56 -07:00
this.rand.setSeed((long) (updateCounter * 312871));
2013-08-01 20:54:56 -07:00
int left = scaledWidth / 2 - 91;
2014-02-04 21:21:50 -05:00
int top = scaledHeight - GuiIngameForge.left_height;
2013-08-01 20:54:56 -07:00
int regen = -1;
if (mc.thePlayer.isPotionActive(Potion.regeneration))
2013-08-01 20:54:56 -07:00
{
regen = updateCounter % 25;
2013-08-01 20:54:56 -07:00
}
final int TOP = 9 * (mc.theWorld.getWorldInfo().isHardcoreModeEnabled() ? 5 : 0);
final int BACKGROUND = (highlight ? 25 : 16);
int MARGIN = 16;
if (mc.thePlayer.isPotionActive(Potion.poison))
MARGIN += 36;
else if (mc.thePlayer.isPotionActive(Potion.wither))
MARGIN += 72;
float absorbRemaining = absorb;
for (int i = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F) - 1; i >= 0; --i)
2013-08-01 20:54:56 -07:00
{
int b0 = (highlight ? 1 : 0);
int row = MathHelper.ceiling_float_int((float) (i + 1) / 10.0F) - 1;
int x = left + i % 10 * 8;
int y = top - row * rowHeight;
if (health <= 4)
y += rand.nextInt(2);
if (i == regen)
y -= 2;
drawTexturedModalRect(x, y, BACKGROUND, TOP, 9, 9);
if (highlight)
{
if (i * 2 + 1 < healthLast)
2014-02-16 14:23:50 -05:00
drawTexturedModalRect(x, y, MARGIN + 54, TOP, 9, 9); // 6
else if (i * 2 + 1 == healthLast)
2014-02-16 14:23:50 -05:00
drawTexturedModalRect(x, y, MARGIN + 63, TOP, 9, 9); // 7
}
if (absorbRemaining > 0.0F)
{
if (absorbRemaining == absorb && absorb % 2.0F == 1.0F)
2014-02-16 14:23:50 -05:00
drawTexturedModalRect(x, y, MARGIN + 153, TOP, 9, 9); // 17
else
2014-02-16 14:23:50 -05:00
drawTexturedModalRect(x, y, MARGIN + 144, TOP, 9, 9); // 16
absorbRemaining -= 2.0F;
}
2013-08-01 20:54:56 -07:00
else
{
if (i * 2 + 1 < health)
2014-02-16 14:23:50 -05:00
drawTexturedModalRect(x, y, MARGIN + 36, TOP, 9, 9); // 4
else if (i * 2 + 1 == health)
2014-02-16 14:23:50 -05:00
drawTexturedModalRect(x, y, MARGIN + 45, TOP, 9, 9); // 5
}
2013-08-01 20:54:56 -07:00
}
PotionEffect potion = mc.thePlayer.getActivePotionEffect(Potion.wither);
if (potion != null)
return;
potion = mc.thePlayer.getActivePotionEffect(Potion.poison);
if (potion != null)
return;
2013-08-01 20:54:56 -07:00
2014-02-16 14:23:50 -05:00
// Extra hearts
this.mc.getTextureManager().bindTexture(hearts);
int hp = MathHelper.ceiling_float_int(this.mc.thePlayer.getHealth());
for (int iter = 0; iter < hp / 20; iter++)
{
int renderHearts = (hp - 20 * (iter + 1)) / 2;
if (renderHearts > 10)
renderHearts = 10;
for (int i = 0; i < renderHearts; i++)
{
this.drawTexturedModalRect(xBasePos + 8 * i, yBasePos, 0 + 18 * iter, 0, 8, 8);
}
if (hp % 2 == 1 && renderHearts < 10)
{
this.drawTexturedModalRect(xBasePos + 8 * renderHearts, yBasePos, 9 + 18 * iter, 0, 8, 8);
}
}
this.mc.getTextureManager().bindTexture(icons);
2013-08-01 20:54:56 -07:00
GuiIngameForge.left_height += 10;
if (absorb > 0)
GuiIngameForge.left_height += 10;
2013-11-29 23:16:32 -05:00
event.setCanceled(true);
2014-02-08 13:30:19 -05:00
if (event.type == ElementType.CROSSHAIRS && gs.thirdPersonView != 0)
{
event.setCanceled(true);
}
}
2013-07-31 13:08:18 -07:00
}
}
public void drawTexturedModalRect (int par1, int par2, int par3, int par4, int par5, int par6)
{
float f = 0.00390625F;
float f1 = 0.00390625F;
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV((double) (par1 + 0), (double) (par2 + par6), (double) this.zLevel, (double) ((float) (par3 + 0) * f), (double) ((float) (par4 + par6) * f1));
tessellator.addVertexWithUV((double) (par1 + par5), (double) (par2 + par6), (double) this.zLevel, (double) ((float) (par3 + par5) * f), (double) ((float) (par4 + par6) * f1));
tessellator.addVertexWithUV((double) (par1 + par5), (double) (par2 + 0), (double) this.zLevel, (double) ((float) (par3 + par5) * f), (double) ((float) (par4 + 0) * f1));
tessellator.addVertexWithUV((double) (par1 + 0), (double) (par2 + 0), (double) this.zLevel, (double) ((float) (par3 + 0) * f), (double) ((float) (par4 + 0) * f1));
tessellator.draw();
}
double zLevel = 0;
}