Skip to content

Commit

Permalink
Utilize GlStateManager in almost everything
Browse files Browse the repository at this point in the history
  • Loading branch information
IcarussOne committed Sep 1, 2024
1 parent c6db87b commit d8c5a91
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@

public class GuiCatalyzationChamber extends GuiContainer {
private static final ResourceLocation TEXTURE = new ResourceLocation(ThaumicWonders.MODID, "textures/gui/gui_catalyzation_chamber.png");

public GuiCatalyzationChamber(InventoryPlayer inventoryPlayer, TileCatalyzationChamber chamberTile) {
super(new ContainerCatalyzationChamber(inventoryPlayer, chamberTile));
this.xSize = 175;
this.ySize = 232;
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
this.mc.renderEngine.bindTexture(TEXTURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class GuiPrimordialAccelerator extends GuiContainer {
private static final ResourceLocation TEXTURE = new ResourceLocation(ThaumicWonders.MODID, "textures/gui/gui_primordial_accelerator.png");

public GuiPrimordialAccelerator(InventoryPlayer inventoryPlayer, TilePrimordialAccelerator acceleratorTile) {
super(new ContainerPrimordialAccelerator(inventoryPlayer, acceleratorTile));
this.xSize = 175;
Expand All @@ -24,7 +24,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
this.mc.renderEngine.bindTexture(TEXTURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.io.IOException;

import org.lwjgl.opengl.GL11;

import com.verdantartifice.thaumicwonders.ThaumicWonders;
import com.verdantartifice.thaumicwonders.common.network.PacketHandler;
import com.verdantartifice.thaumicwonders.common.network.packets.PacketStructureDivinerAction;
Expand All @@ -21,17 +19,17 @@ public class GuiStructureDiviner extends GuiScreen {
public GuiStructureDiviner() {
super();
}

@Override
public void initGui() {
if (this.mc == null) {
this.mc = Minecraft.getMinecraft();
}
this.buttonList.clear();

int baseX = (this.width - 16) / 2;
int baseY = (this.height - 16) / 2;

// out of order for z-ordering
this.buttonList.add(new GuiSelectorButton(2, baseX + 32, baseY, 152, 120, 16, 16, I18n.format("thaumicwonders.gui.structure_diviner.2")));
this.buttonList.add(new GuiSelectorButton(1, baseX + 23, baseY - 23, 143, 97, 16, 16, I18n.format("thaumicwonders.gui.structure_diviner.1")));
Expand All @@ -43,56 +41,56 @@ public void initGui() {
this.buttonList.add(new GuiSelectorButton(7, baseX - 23, baseY - 23, 97, 97, 16, 16, I18n.format("thaumicwonders.gui.structure_diviner.7")));
this.buttonList.add(new GuiSelectorButton(6, baseX - 32, baseY, 88, 120, 16, 16, I18n.format("thaumicwonders.gui.structure_diviner.6")));
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
// Render background
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(BG_TEXTURE);
this.drawTexturedModalRect((this.width - 256) / 2, (this.height - 256) / 2, 0, 0, 256, 256);
GlStateManager.disableBlend();
GlStateManager.popMatrix();

// Draw everything else
super.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
PacketHandler.INSTANCE.sendToServer(new PacketStructureDivinerAction(button.id));
this.mc.player.closeScreen();
}

private class GuiSelectorButton extends GuiButton {
private final ResourceLocation TEXTURE = new ResourceLocation(ThaumicWonders.MODID, "textures/gui/gui_structure_diviner.png");
private int texX;
private int texY;

public GuiSelectorButton(int buttonId, int x, int y, int texX, int texY, int widthIn, int heightIn, String buttonText) {
super(buttonId, x, y, widthIn, heightIn, buttonText);
this.texX = texX;
this.texY = texY;
}

@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
if (this.visible) {
this.hovered = ((mouseX >= this.x) && (mouseY >= this.y) && (mouseX < this.x + this.width) && (mouseY < this.y + this.height));
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
mc.renderEngine.bindTexture(this.TEXTURE);
GL11.glPushMatrix();
GlStateManager.pushMatrix();
if (this.hovered) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
} else {
GL11.glColor4f(0.8F, 0.8F, 0.8F, 1.0F);
GlStateManager.color(0.8F, 0.8F, 0.8F, 1.0F);
}
this.drawTexturedModalRect(this.x, this.y, this.texX, this.texY, 16, 16);
GL11.glPopMatrix();
GlStateManager.popMatrix();
if (this.hovered) {
this.drawString(mc.fontRenderer, this.displayString, this.x + 19, this.y + 4, 16777215);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiTimewinder extends GuiScreen {
public class GuiTimewinder extends GuiScreen {
private static final ResourceLocation BG_TEXTURE = new ResourceLocation(ThaumicWonders.MODID, "textures/gui/gui_timewinder_background.png");

public GuiTimewinder() {
super();
}

@Override
public void initGui() {
if (this.mc == null) {
this.mc = Minecraft.getMinecraft();
}
this.buttonList.clear();

int baseX = (this.width - 16) / 2;
int baseY = (this.height - 16) / 2;
this.buttonList.add(new GuiSelectorButton(0, baseX, baseY - 32, 120, 88, 16, 16, I18n.format("thaumicwonders.gui.timewinder.0")));
Expand All @@ -44,40 +44,40 @@ public void initGui() {
this.buttonList.add(new GuiSelectorButton(6, baseX - 32, baseY, 88, 120, 16, 16, I18n.format("thaumicwonders.gui.timewinder.6")));
this.buttonList.add(new GuiSelectorButton(7, baseX - 23, baseY - 23, 97, 97, 16, 16, I18n.format("thaumicwonders.gui.timewinder.7")));
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
// Render background
GlStateManager.pushMatrix();
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(BG_TEXTURE);
this.drawTexturedModalRect((this.width - 256) / 2, (this.height - 256) / 2, 0, 0, 256, 256);
GlStateManager.disableBlend();
GlStateManager.popMatrix();

// Draw everything else
super.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
PacketHandler.INSTANCE.sendToServer(new PacketTimewinderAction(button.id));
this.mc.player.closeScreen();
}

private class GuiSelectorButton extends GuiButton {
private final ResourceLocation TEXTURE = new ResourceLocation(ThaumicWonders.MODID, "textures/gui/gui_timewinder.png");
private int texX;
private int texY;

public GuiSelectorButton(int buttonId, int x, int y, int texX, int texY, int widthIn, int heightIn, String buttonText) {
super(buttonId, x, y, widthIn, heightIn, buttonText);
this.texX = texX;
this.texY = texY;
}

@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
if (this.visible) {
Expand All @@ -88,9 +88,9 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
mc.renderEngine.bindTexture(this.TEXTURE);
GL11.glPushMatrix();
if (this.hovered) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
} else {
GlStateManager.color(0.8F, 0.8F, 0.8F, 1.0F);
GlStateManager.color(0.8F, 0.8F, 0.8F, 1.0F);
}
this.drawTexturedModalRect(this.x, this.y, this.texX, this.texY, 16, 16);
GlStateManager.popMatrix();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.verdantartifice.thaumicwonders.client.renderers.entity;

import org.lwjgl.opengl.GL11;

import com.verdantartifice.thaumicwonders.ThaumicWonders;
import com.verdantartifice.thaumicwonders.common.entities.EntityVoidPortal;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
Expand All @@ -21,7 +20,7 @@
@SideOnly(Side.CLIENT)
public class RenderVoidPortal extends Render<EntityVoidPortal> {
private static final ResourceLocation TEXTURE = new ResourceLocation(ThaumicWonders.MODID, "textures/misc/void_portal.png");

public RenderVoidPortal(RenderManager renderManager) {
super(renderManager);
this.shadowSize = 0.0F;
Expand All @@ -32,15 +31,15 @@ public RenderVoidPortal(RenderManager renderManager) {
protected ResourceLocation getEntityTexture(EntityVoidPortal entity) {
return TEXTURE;
}

@Override
public void doRender(EntityVoidPortal portal, double x, double y, double z, float entityYaw, float partialTicks) {
long nt = System.nanoTime();
long time = nt / 50000000L;
float scaley = 1.4F;
int e = (int)Math.min(50.0F, portal.ticksExisted + partialTicks);
int e = (int) Math.min(50.0F, portal.ticksExisted + partialTicks);
float scale = e / 50.0F * 1.25F;

y += portal.height / 2.0F;

float stability = portal.getGeneratorStability();
Expand All @@ -52,27 +51,27 @@ public void doRender(EntityVoidPortal portal, double x, double y, double z, floa
scale -= bobXZ / 3.0F;

this.bindTexture(TEXTURE);
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1.0F, 1.0F, 1.0F, alpha);
GlStateManager.pushMatrix();

GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1.0F, 1.0F, 1.0F, alpha);

if (Minecraft.getMinecraft().getRenderViewEntity() instanceof EntityPlayer) {
GL11.glDepthMask(false);
GlStateManager.depthMask(false);
Tessellator tessellator = Tessellator.getInstance();
float arX = ActiveRenderInfo.getRotationX();
float arZ = ActiveRenderInfo.getRotationZ();
float arYZ = ActiveRenderInfo.getRotationYZ();
float arXY = ActiveRenderInfo.getRotationXY();
float arXZ = ActiveRenderInfo.getRotationXZ();

tessellator.getBuffer().begin(7, UtilsFX.VERTEXFORMAT_POS_TEX_CO_LM_NO);
Vec3d v1 = new Vec3d(-arX - arYZ, -arXZ, -arZ - arXY);
Vec3d v2 = new Vec3d(-arX + arYZ, arXZ, -arZ + arXY);
Vec3d v3 = new Vec3d(arX + arYZ, arXZ, arZ + arXY);
Vec3d v4 = new Vec3d(arX - arYZ, -arXZ, arZ - arXY);
int frame = 15 - (int)time % 16;
int frame = 15 - (int) time % 16;
float f2 = frame / 16.0F;
float f3 = f2 + 0.0625F;
float f4 = 0.0F;
Expand All @@ -85,10 +84,10 @@ public void doRender(EntityVoidPortal portal, double x, double y, double z, floa
tessellator.getBuffer().pos(x + v3.x * scale, y + v3.y * scaley, z + v3.z * scale).tex(f2, f5).color(1.0F, 1.0F, 1.0F, alpha).lightmap(j, k).normal(0.0F, 0.0F, -1.0F).endVertex();
tessellator.getBuffer().pos(x + v4.x * scale, y + v4.y * scaley, z + v4.z * scale).tex(f2, f4).color(1.0F, 1.0F, 1.0F, alpha).lightmap(j, k).normal(0.0F, 0.0F, -1.0F).endVertex();
tessellator.draw();
GL11.glDepthMask(true);
GlStateManager.depthMask(true);
}
GL11.glDisable(32826);
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
GlStateManager.glDisableClientState(32826);
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
Loading

0 comments on commit d8c5a91

Please sign in to comment.