2014-08-25 07:58:39 -04:00
|
|
|
package WayofTime.alchemicalWizardry.client.renderer;
|
|
|
|
|
2014-12-09 19:06:47 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiChat;
|
|
|
|
import net.minecraft.client.gui.ScaledResolution;
|
2014-12-09 19:06:47 -05:00
|
|
|
import net.minecraft.client.renderer.OpenGlHelper;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureMap;
|
2014-08-25 07:58:39 -04:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-12-09 19:06:47 -05:00
|
|
|
import net.minecraft.util.IIcon;
|
2014-08-25 07:58:39 -04:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2014-12-09 19:06:47 -05:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2014-08-25 07:58:39 -04:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-09 19:06:47 -05:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-12-09 19:06:47 -05:00
|
|
|
import WayofTime.alchemicalWizardry.ModItems;
|
|
|
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler;
|
|
|
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo;
|
|
|
|
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
|
|
|
|
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
|
2014-08-25 07:58:39 -04:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
public class RenderHelper
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
public static boolean showEquippedItem = true;
|
|
|
|
public static boolean enableItemName = false;
|
|
|
|
public static boolean enabled = true;
|
|
|
|
public static boolean showInChat = true;
|
2014-12-09 19:06:47 -05:00
|
|
|
|
|
|
|
public static int zLevel = 0;
|
2014-10-13 22:33:20 +02:00
|
|
|
|
|
|
|
private static int xOffsetDefault = +50;
|
|
|
|
public static int xOffset = xOffsetDefault;
|
|
|
|
private static int yOffsetDefault = 2;
|
|
|
|
public static int yOffset = yOffsetDefault;
|
|
|
|
private static int yOffsetBottomCenterDefault = 41;
|
|
|
|
public static int yOffsetBottomCenter = yOffsetBottomCenterDefault;
|
|
|
|
private static boolean applyXOffsetToCenterDefault = true;
|
|
|
|
public static boolean applyXOffsetToCenter = applyXOffsetToCenterDefault;
|
|
|
|
private static boolean applyYOffsetToMiddleDefault = false;
|
|
|
|
public static boolean applyYOffsetToMiddle = applyYOffsetToMiddleDefault;
|
|
|
|
|
|
|
|
public static String listMode = "horizontal";
|
|
|
|
public static String alignMode = "bottomcenter";
|
|
|
|
|
|
|
|
private static ScaledResolution scaledResolution;
|
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
public static boolean onTickInGame(Minecraft mc)
|
|
|
|
{
|
|
|
|
if (enabled && (mc.inGameHasFocus || mc.currentScreen == null || (mc.currentScreen instanceof GuiChat && showInChat))
|
|
|
|
&& !mc.gameSettings.showDebugInfo)
|
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
EntityPlayer player = mc.thePlayer;
|
|
|
|
World world = mc.theWorld;
|
|
|
|
if (SpellHelper.canPlayerSeeAlchemy(player))
|
|
|
|
{
|
|
|
|
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
2014-08-25 07:58:39 -04:00
|
|
|
scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
|
|
|
displayArmorStatus(mc);
|
2014-12-09 19:06:47 -05:00
|
|
|
renderTestHUD(mc);
|
2014-08-25 07:58:39 -04:00
|
|
|
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
2014-10-13 22:33:20 +02:00
|
|
|
}
|
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
|
|
|
private static List<HUDElement> getHUDElements(Minecraft mc)
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
List<HUDElement> elements = new ArrayList();
|
|
|
|
|
|
|
|
MovingObjectPosition movingobjectposition = mc.objectMouseOver;
|
|
|
|
World world = mc.theWorld;
|
2014-08-25 07:58:39 -04:00
|
|
|
|
|
|
|
if (movingobjectposition == null)
|
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
return elements;
|
2014-08-25 07:58:39 -04:00
|
|
|
} else
|
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
|
|
|
int x = movingobjectposition.blockX;
|
|
|
|
int y = movingobjectposition.blockY;
|
|
|
|
int z = movingobjectposition.blockZ;
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
2014-10-13 22:33:20 +02:00
|
|
|
|
|
|
|
if (!(tile instanceof IReagentHandler))
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
return elements;
|
2014-08-25 07:58:39 -04:00
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
|
|
|
IReagentHandler relay = (IReagentHandler) tile;
|
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.getOrientation(movingobjectposition.sideHit));
|
2014-10-13 22:33:20 +02:00
|
|
|
|
|
|
|
if (infos != null)
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
for (ReagentContainerInfo info : infos)
|
|
|
|
{
|
|
|
|
if (info == null || info.reagent == null || info.reagent.reagent == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack itemStack = ReagentRegistry.getItemForReagent(info.reagent.reagent);
|
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
if (itemStack != null)
|
|
|
|
elements.add(new HUDElement(itemStack, 16, 16, 2, info.reagent.amount));
|
2014-10-13 22:33:20 +02:00
|
|
|
}
|
2014-08-25 07:58:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
private static int getX(int width)
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
|
|
|
if (alignMode.toLowerCase().contains("center"))
|
|
|
|
return scaledResolution.getScaledWidth() / 2 - width / 2 + (applyXOffsetToCenter ? xOffset : 0);
|
|
|
|
else if (alignMode.toLowerCase().contains("right"))
|
|
|
|
return scaledResolution.getScaledWidth() - width - xOffset;
|
|
|
|
else
|
|
|
|
return xOffset;
|
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
private static int getY(int rowCount, int height)
|
|
|
|
{
|
|
|
|
if (alignMode.toLowerCase().contains("middle"))
|
|
|
|
return (scaledResolution.getScaledHeight() / 2) - ((rowCount * height) / 2) + (applyYOffsetToMiddle ? yOffset : 0);
|
|
|
|
else if (alignMode.equalsIgnoreCase("bottomleft") || alignMode.equalsIgnoreCase("bottomright"))
|
|
|
|
return scaledResolution.getScaledHeight() - (rowCount * height) - yOffset;
|
|
|
|
else if (alignMode.equalsIgnoreCase("bottomcenter"))
|
|
|
|
return scaledResolution.getScaledHeight() - (rowCount * height) - yOffsetBottomCenter;
|
|
|
|
else
|
|
|
|
return yOffset;
|
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
|
|
|
private static int getElementsWidth(List<HUDElement> elements)
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
for (HUDElement he : elements)
|
|
|
|
r += he.width();
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
return r;
|
|
|
|
}
|
2014-12-09 19:06:47 -05:00
|
|
|
|
|
|
|
private static void renderTestHUD(Minecraft mc)
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
int l;
|
|
|
|
float f;
|
|
|
|
float f3;
|
|
|
|
float f4;
|
|
|
|
TextureManager p_77015_2_ = mc.getTextureManager();
|
|
|
|
ItemStack p_77015_3_ = new ItemStack(ModItems.activationCrystal);
|
|
|
|
|
|
|
|
Object object = p_77015_3_.getIconIndex();
|
|
|
|
|
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
|
|
|
ResourceLocation resourcelocation = p_77015_2_.getResourceLocation(p_77015_3_.getItemSpriteNumber());
|
|
|
|
p_77015_2_.bindTexture(resourcelocation);
|
|
|
|
|
|
|
|
if (object == null)
|
|
|
|
{
|
|
|
|
object = ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(resourcelocation)).getAtlasSprite("missingno");
|
|
|
|
}
|
|
|
|
|
|
|
|
l = p_77015_3_.getItem().getColorFromItemStack(p_77015_3_, 0);
|
|
|
|
f3 = (float)(l >> 16 & 255) / 255.0F;
|
|
|
|
f4 = (float)(l >> 8 & 255) / 255.0F;
|
|
|
|
f = (float)(l & 255) / 255.0F;
|
|
|
|
|
|
|
|
// if (this.renderWithColor)
|
|
|
|
// {
|
|
|
|
// GL11.glColor4f(f3, f4, f, 1.0F);
|
|
|
|
// }
|
|
|
|
|
|
|
|
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
|
|
|
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
|
|
|
|
renderIcon(x, y, (IIcon)object, 16, 16);
|
|
|
|
|
|
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
|
|
|
GL11.glDisable(GL11.GL_BLEND);
|
|
|
|
|
|
|
|
// if (renderEffect && p_77015_3_.hasEffect(0))
|
|
|
|
// {
|
|
|
|
// renderEffect(p_77015_2_, x, y);
|
|
|
|
// }
|
|
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void renderIcon(int p_94149_1_, int p_94149_2_, IIcon p_94149_3_, int p_94149_4_, int p_94149_5_)
|
|
|
|
{
|
|
|
|
Tessellator tessellator = Tessellator.instance;
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.addVertexWithUV((double)(p_94149_1_ + 0), (double)(p_94149_2_ + p_94149_5_), (double)zLevel, (double)p_94149_3_.getMinU(), (double)p_94149_3_.getMaxV());
|
|
|
|
tessellator.addVertexWithUV((double)(p_94149_1_ + p_94149_4_), (double)(p_94149_2_ + p_94149_5_), (double)zLevel, (double)p_94149_3_.getMaxU(), (double)p_94149_3_.getMaxV());
|
|
|
|
tessellator.addVertexWithUV((double)(p_94149_1_ + p_94149_4_), (double)(p_94149_2_ + 0), (double)zLevel, (double)p_94149_3_.getMaxU(), (double)p_94149_3_.getMinV());
|
|
|
|
tessellator.addVertexWithUV((double)(p_94149_1_ + 0), (double)(p_94149_2_ + 0), (double)zLevel, (double)p_94149_3_.getMinU(), (double)p_94149_3_.getMinV());
|
|
|
|
tessellator.draw();
|
|
|
|
}
|
2014-08-25 07:58:39 -04:00
|
|
|
|
|
|
|
private static void displayArmorStatus(Minecraft mc)
|
|
|
|
{
|
|
|
|
List<HUDElement> elements = getHUDElements(mc);
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
if (elements.size() > 0)
|
|
|
|
{
|
|
|
|
int yOffset = enableItemName ? 18 : 16;
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
if (listMode.equalsIgnoreCase("vertical"))
|
|
|
|
{
|
|
|
|
int yBase = getY(elements.size(), yOffset);
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
for (HUDElement e : elements)
|
|
|
|
{
|
|
|
|
e.renderToHud((alignMode.toLowerCase().contains("right") ? getX(0) : getX(e.width())), yBase);
|
|
|
|
yBase += yOffset;
|
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
} else if (listMode.equalsIgnoreCase("horizontal"))
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
|
|
|
int totalWidth = getElementsWidth(elements);
|
|
|
|
int yBase = getY(1, yOffset);
|
|
|
|
int xBase = getX(totalWidth);
|
|
|
|
int prevX = 0;
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-08-25 07:58:39 -04:00
|
|
|
for (HUDElement e : elements)
|
|
|
|
{
|
|
|
|
e.renderToHud(xBase + prevX + (alignMode.toLowerCase().contains("right") ? e.width() : 0), yBase);
|
|
|
|
prevX += (e.width());
|
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
} else if (listMode.equalsIgnoreCase("compound"))
|
2014-08-25 07:58:39 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
//TODO
|
2014-08-25 07:58:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|