Gui rendering cleanup

This commit is contained in:
mezz committed 2017-01-24 20:53:27 -08:00
1 parent 17f036522e
commit 31a305ffc2
173 files changed
+1317 -1349

No files matched your search

@@ -1,11 +1,8 @@
package binnie.craftgui.minecraft;
import binnie.core.BinnieCore;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.core.Tooltip;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IBorder;
import binnie.craftgui.core.geometry.CraftGUIUtil;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.events.EventKey;
import binnie.craftgui.events.EventMouse;
@@ -14,18 +11,11 @@ import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
@@ -53,7 +43,7 @@ public class GuiCraftGUI extends GuiContainer {
public GuiCraftGUI(final Window window) {
super(window.getContainer());
this.mousePos = new IPoint(0.0f, 0.0f);
this.mousePos = IPoint.ZERO;
this.window = window;
this.resize(window.getSize());
}
@@ -87,7 +77,7 @@ public class GuiCraftGUI extends GuiContainer {
GL11.glDisable(2929);
this.zLevel = 10.0f;
//GuiScreen.itemRender.zLevel = this.zLevel;
this.window.render();
this.window.render(this.width, this.height);
GL11.glPushMatrix();
@@ -96,7 +86,7 @@ public class GuiCraftGUI extends GuiContainer {
final InventoryPlayer playerInventory = this.mc.thePlayer.inventory;
this.draggedItem = playerInventory.getItemStack();
if (this.draggedItem != null) {
this.renderItem(new IPoint(mouseX - 8, mouseY - 8), this.draggedItem, 200, false);
CraftGUIUtil.renderItem(new IPoint(mouseX - 8, mouseY - 8), this.draggedItem, false);
}
RenderHelper.enableGUIStandardItemLighting();
GL11.glDisable(32826);
@@ -188,7 +178,7 @@ public class GuiCraftGUI extends GuiContainer {
GL11.glPushMatrix();
GL11.glTranslatef(i1, j1 - 1.5f, 0.0f);
GL11.glScalef(0.6f, 0.6f, 1.0f);
this.renderItem(new IPoint(0.0f, 0.0f), stack, false);
CraftGUIUtil.renderItem(IPoint.ZERO, stack, false);
GL11.glPopMatrix();
} catch (NBTException e) {
e.printStackTrace();
@@ -271,191 +261,6 @@ public class GuiCraftGUI extends GuiContainer {
this.window.onClose();
}
public void renderTexturedRect(final float x, final float y, final float u, final float v, final float w, final float h) {
this.drawTexturedModalRect((int) x, (int) y, (int) u, (int) v, (int) w, (int) h);
}
public void renderTexture(final IPoint position, final IArea textureArea) {
this.drawTexturedModalRect((int) position.x(), (int) position.y(), (int) textureArea.pos().x(), (int) textureArea.pos().y(), (int) textureArea.size().x(), (int) textureArea.size().y());
}
private void renderTexturedRect(final IArea area, final IPoint uv) {
this.renderTexturedRect(area.pos().x(), area.pos().y(), uv.x(), uv.y(), area.size().x(), area.size().y());
}
public void renderTexturePadded(final IArea area, final IArea texture, final IBorder padding) {
int borderLeft = (int) padding.l();
int borderRight = (int) padding.r();
int borderTop = (int) padding.t();
int borderBottom = (int) padding.b();
final int posX = (int) area.pos().x();
final int posY = (int) area.pos().y();
final int width = (int) area.size().x();
final int height = (int) area.size().y();
final int textWidth = (int) texture.w();
final int textHeight = (int) texture.h();
final int u = (int) texture.x();
final int v = (int) texture.y();
if (borderTop + borderBottom > height) {
borderTop = height / 2;
borderBottom = height / 2;
}
if (borderLeft + borderRight > width) {
borderLeft = width / 2;
borderRight = width / 2;
}
final IPoint origin = area.pos();
this.drawTexturedModalRect(posX, posY, u, v, borderLeft, borderTop);
this.drawTexturedModalRect(posX + width - borderRight, posY, u + textWidth - borderRight, v, borderRight, borderTop);
this.drawTexturedModalRect(posX, posY + height - borderBottom, u, v + textHeight - borderBottom, borderLeft, borderBottom);
this.drawTexturedModalRect(posX + width - borderRight, posY + height - borderBottom, u + textWidth - borderRight, v + textHeight - borderBottom, borderRight, borderBottom);
int texturingWidth;
for (int currentXPos = borderLeft; currentXPos < width - borderRight; currentXPos += texturingWidth) {
final int distanceXRemaining = width - borderRight - currentXPos;
texturingWidth = textWidth - borderLeft - borderRight;
if (texturingWidth > distanceXRemaining) {
texturingWidth = distanceXRemaining;
}
if (texturingWidth <= 0) {
break;
}
this.drawTexturedModalRect(posX + currentXPos, posY, u + borderLeft, v, texturingWidth, borderTop);
this.drawTexturedModalRect(posX + currentXPos, posY + height - borderBottom, u + borderLeft, v + textHeight - borderBottom, texturingWidth, borderBottom);
int texturingHeight;
for (int currentYPos = borderTop; currentYPos < height - borderBottom; currentYPos += texturingHeight) {
final int distanceYRemaining = height - borderBottom - currentYPos;
texturingHeight = textHeight - borderTop - borderBottom;
if (texturingHeight > distanceYRemaining) {
texturingHeight = distanceYRemaining;
}
if (texturingHeight <= 0) {
break;
}
this.drawTexturedModalRect(posX + currentXPos, posY + currentYPos, u + borderLeft, v + borderTop, texturingWidth, texturingHeight);
}
}
int texturingHeight2;
for (int currentYPos2 = borderTop; currentYPos2 < height - borderBottom; currentYPos2 += texturingHeight2) {
final int distanceYRemaining2 = height - borderBottom - currentYPos2;
texturingHeight2 = textHeight - borderTop - borderBottom;
if (texturingHeight2 > distanceYRemaining2) {
texturingHeight2 = distanceYRemaining2;
}
if (texturingHeight2 <= 0) {
break;
}
this.drawTexturedModalRect(posX, posY + currentYPos2, u, v + borderTop, borderLeft, texturingHeight2);
this.drawTexturedModalRect(posX + width - borderRight, posY + currentYPos2, u + textWidth - borderRight, v + borderTop, borderRight, texturingHeight2);
}
}
public void drawGradientArea(final float p_73733_1_, final float p_73733_2_, final float p_73733_3_, final float p_73733_4_, final int p_73733_5_, final int p_73733_6_) {
final float f = (p_73733_5_ >> 24 & 0xFF) / 255.0f;
final float f2 = (p_73733_5_ >> 16 & 0xFF) / 255.0f;
final float f3 = (p_73733_5_ >> 8 & 0xFF) / 255.0f;
final float f4 = (p_73733_5_ & 0xFF) / 255.0f;
final float f5 = (p_73733_6_ >> 24 & 0xFF) / 255.0f;
final float f6 = (p_73733_6_ >> 16 & 0xFF) / 255.0f;
final float f7 = (p_73733_6_ >> 8 & 0xFF) / 255.0f;
final float f8 = (p_73733_6_ & 0xFF) / 255.0f;
GL11.glDisable(3553);
GL11.glEnable(3042);
GL11.glDisable(3008);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glShadeModel(7425);
final Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vb = tessellator.getBuffer();
vb.begin(7, DefaultVertexFormats.POSITION_COLOR);
vb.pos(p_73733_3_, p_73733_2_, this.zLevel).color(f2, f3, f4, f).endVertex();
vb.pos(p_73733_1_, p_73733_2_, this.zLevel).color(f2, f3, f4, f).endVertex();
vb.pos(p_73733_1_, p_73733_4_, this.zLevel).color(f6, f7, f8, f5).endVertex();
vb.pos(p_73733_3_, p_73733_4_, this.zLevel).color(f6, f7, f8, f5).endVertex();
tessellator.draw();
GL11.glShadeModel(7424);
GL11.glDisable(3042);
GL11.glEnable(3008);
GL11.glEnable(3553);
}
public void renderItem(final IPoint pos, final ItemStack item, final boolean rotating) {
this.renderItem(pos, item, (int) this.zLevel + 3, rotating);
}
private void renderItem(final IPoint pos, final ItemStack item, final int zLevel, final boolean rotating) {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
GL11.glPushMatrix();
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(32826);
GL11.glEnable(2929);
FontRenderer font = item.getItem().getFontRenderer(item);
if (font == null) {
font = this.getFontRenderer();
}
if (item != null) {
BinnieCore.proxy.getMinecraftInstance();
final float phase = Minecraft.getSystemTime() / 20.0f;
GL11.glPushMatrix();
if (rotating) {
GL11.glTranslatef(8.0f, 8.0f, 0.0f);
GL11.glRotatef(phase, 0.0f, -0.866f, 0.5f);
GL11.glTranslatef(-8.0f, -8.0f, -67.1f);
}
Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(item, (int) pos.x(), (int) pos.y());
GL11.glPopMatrix();
Minecraft.getMinecraft().getRenderItem().renderItemOverlayIntoGUI(font, item, (int) pos.x(), (int) pos.y(), null);
}
GL11.glClear(256);
GL11.glEnable(3042);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
RenderHelper.disableStandardItemLighting();
CraftGUI.render.colour(-1);
GL11.glEnable(32826);
GL11.glPopMatrix();
}
public void renderFluid(FluidStack fluid, IPoint pos) {
final int hex = fluid.getFluid().getColor(fluid);
final int r = (hex & 0xFF0000) >> 16;
final int g = (hex & 0xFF00) >> 8;
final int b = hex & 0xFF;
TextureAtlasSprite icon = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluid.getFluid().getStill().toString());
GL11.glColor4f(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
GL11.glEnable(3042);
GL11.glBlendFunc(770, 771);
renderSprite(pos, icon, TextureMap.LOCATION_BLOCKS_TEXTURE);
GL11.glDisable(3042);
}
public void renderSprite(final IPoint pos, final TextureAtlasSprite icon, final ResourceLocation map) {
if (icon == null) {
return;
}
GL11.glPushMatrix();
GL11.glEnable(32826);
BinnieCore.proxy.bindTexture(map);
drawTexture((int) pos.x(), (int) pos.y(), icon, 0, 0, zLevel);
GL11.glEnable(32826);
GL11.glPopMatrix();
}
private static void drawTexture(double xCoord, double yCoord, TextureAtlasSprite textureSprite, int maskTop, int maskRight, double zLevel) {
double uMin = textureSprite.getMinU();
double uMax = textureSprite.getMaxU();
double vMin = textureSprite.getMinV();
double vMax = textureSprite.getMaxV();
uMax = uMax - maskRight / 16.0 * (uMax - uMin);
vMax = vMax - maskTop / 16.0 * (vMax - vMin);
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexBuffer = tessellator.getBuffer();
vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexBuffer.pos(xCoord, yCoord + 16, zLevel).tex(uMin, vMax).endVertex();
vertexBuffer.pos(xCoord + 16 - maskRight, yCoord + 16, zLevel).tex(uMax, vMax).endVertex();
vertexBuffer.pos(xCoord + 16 - maskRight, yCoord + maskTop, zLevel).tex(uMax, vMin).endVertex();
vertexBuffer.pos(xCoord, yCoord + maskTop, zLevel).tex(uMin, vMin).endVertex();
tessellator.draw();
}
public boolean isHelpMode() {
return Keyboard.isKeyDown(15);
}
@@ -472,56 +277,4 @@ public class GuiCraftGUI extends GuiContainer {
this.window.setPosition(new IPoint(this.guiLeft, this.guiTop));
}
public void limitArea(final IArea area) {
float x = area.pos().x();
float y = area.pos().y();
float w = area.size().x();
float h = area.size().y();
y = this.height - (y + h);
final float k = this.xSize;
final float scaleX = this.width / (float) this.mc.displayWidth;
final float scaleY = this.height / (float) this.mc.displayHeight;
x += 0.0f;
y += 0.0f;
w += 0.0f;
h += 0.0f;
GL11.glScissor((int) (x / scaleX), (int) (y / scaleY), (int) (w / scaleX), (int) (h / scaleY));
}
public int getZLevel() {
return (int) this.zLevel;
}
public void drawRect(float p_73734_0_, float p_73734_1_, float p_73734_2_, float p_73734_3_, final int p_73734_4_) {
if (p_73734_0_ < p_73734_2_) {
final float j1 = p_73734_0_;
p_73734_0_ = p_73734_2_;
p_73734_2_ = j1;
}
if (p_73734_1_ < p_73734_3_) {
final float j1 = p_73734_1_;
p_73734_1_ = p_73734_3_;
p_73734_3_ = j1;
}
final float f3 = (p_73734_4_ >> 24 & 0xFF) / 255.0f;
final float f4 = (p_73734_4_ >> 16 & 0xFF) / 255.0f;
final float f5 = (p_73734_4_ >> 8 & 0xFF) / 255.0f;
final float f6 = (p_73734_4_ & 0xFF) / 255.0f;
final Tessellator tessellator = Tessellator.getInstance();
GL11.glEnable(3042);
GL11.glDisable(3553);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glColor4f(f4, f5, f6, f3);
VertexBuffer vertexBuffer = tessellator.getBuffer();
vertexBuffer.begin(7, DefaultVertexFormats.POSITION);
vertexBuffer.pos(p_73734_0_, p_73734_3_, 0.0).endVertex();
vertexBuffer.pos(p_73734_2_, p_73734_3_, 0.0).endVertex();
vertexBuffer.pos(p_73734_2_, p_73734_1_, 0.0).endVertex();
vertexBuffer.pos(p_73734_0_, p_73734_1_, 0.0).endVertex();
tessellator.draw();
GL11.glEnable(3553);
GL11.glDisable(3042);
}
}