Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So this Gui is a bit more advanced.

It has a representation of the clicked mob.

 

There is one problem.

When it gets night, the gui is very dark.

When it it day, the gui is light, normal.

*see below

 

code for the gui file

**see below

 

pic1.png

pic2.png

 

package comp101.client.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import comp101.client.SendPackage;
import comp101.common.Core;
import comp101.common.container.ContainerHireable;
import comp101.common.entity.EntityHireable;

public class GuiHireable extends GuiContainer{

private static final ResourceLocation tex = new ResourceLocation(Core.getModID(), "textures/gui/hireable.png");

EntityHireable hireable;

boolean toggleRightVisible = false;
boolean toggleLeftVisible = false;

public GuiHireable(EntityPlayer player, EntityHireable entity)
{
	super(new ContainerHireable(player, entity));
	hireable = entity;
	this.ySize = 176;
	this.xSize = 196;
}

public void initGui()
{
	int k = (this.width - this.xSize) / 2;
	int l = (this.height - this.ySize) / 2;

	this.buttonList.clear();

	this.buttonList.add(new InvisibleButton(0, k + 98, l + 71, 26, 18, ""));

	this.buttonList.add(new InvisibleButton(1, k + (xSize - 5), l + 13, 15, 60, ""));
	this.buttonList.add(new InvisibleButton(2, k - 5, l + 13, 15, 60, ""));

	this.buttonList.add(new InvisibleButton(3, k + -20, l + 23, 16, 18, ""));

	this.buttonList.add(new InvisibleButton(4, k + -20, l + 23 + 20, 16, 18, ""));

	super.initGui();
}

@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_)
{
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.getTextureManager().bindTexture(tex);
	int k = (this.width - this.xSize) / 2;
	int l = (this.height - this.ySize) / 2;
	this.drawTexturedModalRect(k + 26, l + 18, 196, 0, 52, 70);

	func_74223_a(this.mc, guiLeft + 51, guiTop + 82, 30, (float)(width + 51) - this.width, (float)(guiTop + 75 - 50) - this.height);

	this.mc.getTextureManager().bindTexture(tex);
	this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);

	this.setRightSide(this.toggleRightVisible ? 100 : 5, this.toggleRightVisible ? (this.hireable.getBonusHealth() > 0 || this.hireable.getBonusDamage() > 0 ? (this.hireable.getBonusHealth() > 0 && this.hireable.getBonusDamage() > 0 ? 74 : 63) : 56) : 50);

	if(this.hireable.HasUpgradeItem(Core.BackPack) || this.hireable.HasUpgradeItem(Core.IronBackPack) || this.hireable.HasUpgradeItem(Core.DiamondBackPack) || this.hireable.HasUpgradeItem(Core.LittleOven)){
		this.setLeftSide(27, 30);
	}
	if((this.hireable.HasUpgradeItem(Core.BackPack) || this.hireable.HasUpgradeItem(Core.IronBackPack) || this.hireable.HasUpgradeItem(Core.DiamondBackPack)) && this.hireable.HasUpgradeItem(Core.LittleOven)){
		this.setLeftSide(27, 51);
	}

	if(this.hireable.HasUpgradeCount(1)){
		if(this.hireable.HasUpgradeItem(Core.BackPack) || this.hireable.HasUpgradeItem(Core.IronBackPack) || this.hireable.HasUpgradeItem(Core.DiamondBackPack)){
			this.drawTexturedModalRect(k - 20, l + 23, 154, 176, 16, 18);
		}

		if(this.hireable.HasUpgradeItem(Core.LittleOven) && (this.hireable.HasUpgradeItem(Core.BackPack) || this.hireable.HasUpgradeItem(Core.IronBackPack) || this.hireable.HasUpgradeItem(Core.DiamondBackPack))){				
			this.drawTexturedModalRect(k - 20, l + 23 + 20, 170, 176, 16, 18);
		}
		if(this.hireable.HasUpgradeItem(Core.LittleOven) && !(this.hireable.HasUpgradeItem(Core.BackPack) || this.hireable.HasUpgradeItem(Core.IronBackPack) || this.hireable.HasUpgradeItem(Core.DiamondBackPack))){				
			this.drawTexturedModalRect(k - 20, l + 23, 170, 176, 16, 18);
		}
	}

	for(int i = 0; i < hireable.getBonusUpgradeSlot(); i++){
		this.drawTexturedModalRect(k + 125 + (i * 18), l + 71, 17, 93, 18, 18);
	}

//text
	GL11.glDisable(GL11.GL_LIGHTING);

	String s = this.hireable.hasCustomNameTag() ? this.hireable.getCustomNameTag() : I18n.format("entity." + Core.getModID() + "." + hireable.getName() + ".name", new Object[0]);
	this.fontRendererObj.drawString(s + "'s " + I18n.format("entity.gui.stat", new Object[0]), (this.width / 2) - this.fontRendererObj.getStringWidth(s + " " + I18n.format("entity.gui.stat", new Object[0])) / 2, l + 6, 4210752);

	if(this.toggleRightVisible){
		this.fontRendererObj.drawString(I18n.format("entity.gui.level", new Object[0]) + " = " + hireable.getLevel(), k + 198, l + 14 + 9, 4210752);
		this.fontRendererObj.drawString(I18n.format("entity.gui.health", new Object[0]) + " = " + hireable.getHealth(), k + 198, l + 14 + (9 * 2), 4210752);
		this.fontRendererObj.drawString(I18n.format("entity.gui.maxhealth", new Object[0]) + " = " + hireable.getMaxHealth(), k + 198, l + 14 + (9 * 3), 4210752);
		this.fontRendererObj.drawString(I18n.format("entity.gui.xp", new Object[0]) + " = " + hireable.getXP() + " / " + hireable.getXPtonextLevel(), k + 198, l + 14 + (9 * 4), 4210752);
		this.fontRendererObj.drawString(I18n.format("entity.gui.damage", new Object[0]) + " = " + hireable.getAttackDamage(), k + 198, l + 14 + (9 * 5), 4210752);

		if(this.hireable.getBonusHealth() > 0){
			this.fontRendererObj.drawString(I18n.format("entity.gui.bonushealth", new Object[0]) + " +" + (hireable.getBonusHealth() * 2), k + 198, l + 14 + (9 * 6), 4210752);
		}
		if(this.hireable.getBonusDamage() > 0){
			this.fontRendererObj.drawString(I18n.format("entity.gui.bonusdamage", new Object[0]) + " +" + hireable.getBonusDamage(), k + 198, l + 14 + (9 * (this.hireable.getBonusHealth() > 0 ? 7 : 6)), 4210752);
		}
	}
}

public void actionPerformed(GuiButton button)
{
	if(button.id == 0){
		this.mc.displayGuiScreen(new GuiPowerUp(hireable));
	}
	if(button.id == 1 || button.id == 2){
		if(this.toggleRightVisible == false){
			this.toggleRightVisible = true;
		}else{
			this.toggleRightVisible = false;
		}
		if(this.toggleLeftVisible == false){
			this.toggleLeftVisible = true;
		}else{
			this.toggleLeftVisible = false;
		}
	}

	if(button.id == 3){
		Core.network.sendToServer(new SendPackage(5, hireable.getEntityId(), 1));
	}
	if(button.id == 4){
		Core.network.sendToServer(new SendPackage(5, hireable.getEntityId(), 2));
	}
}

private void setRightSide(int sizex, int sizey)
{
	int k = (this.width - this.xSize) / 2;
	int l = (this.height - this.ySize) / 2;

	if(sizey > 80){
		this.drawTexturedModalRect(k + xSize, l + 17, 154 - sizex, 176, sizex, 4);

		this.drawTexturedModalRect(k + xSize, l + 17 + 4, 154 - sizex, 180, sizex, 60);
		this.drawTexturedModalRect(k + xSize, l + 17 + 64, 154 - sizex, 180, sizex, sizey - 68);

		this.drawTexturedModalRect(k + xSize, l + 17 + (sizey - 4), 154 - sizex, 252, sizex, 4);
	}else{
		this.drawTexturedModalRect(k + xSize, l + 17, 154 - sizex, 176, sizex, sizey - 4);
		this.drawTexturedModalRect(k + xSize, l + 17 + (sizey - 4), 154 - sizex, 252, sizex, 4);
	}
}

private void setLeftSide(int sizex, int sizey)
{
	int k = (this.width - this.xSize) / 2;
	int l = (this.height - this.ySize) / 2;

	if(sizey > 80){
		this.drawTexturedModalRect(k - sizex, l + 17, 0, 176, sizex, 4);

		this.drawTexturedModalRect(k - sizex, l + 17 + 4, 0, 180, sizex, 60);
		this.drawTexturedModalRect(k - sizex, l + 17 + 64, 0, 180, sizex, sizey - 68);

		this.drawTexturedModalRect(k - sizex, l + 17 + (sizey - 4), 0, 252, sizex, 4);
	}else{
		this.drawTexturedModalRect(k - sizex, l + 17, 0, 176, sizex, sizey - 4);
		this.drawTexturedModalRect(k - sizex, l + 17 + (sizey - 4), 0, 252, sizex, 4);
	}
}

public void func_74223_a(Minecraft par0Minecraft, int par1, int par2, int par3, float par4, float par5)
{
	GL11.glEnable(GL11.GL_COLOR_MATERIAL);
	GL11.glPushMatrix();
	GL11.glTranslatef((float)par1, (float)par2, 50.0F);
	GL11.glScalef((float)(-par3), (float)par3, (float)par3);
	GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);

	GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
	RenderHelper.enableStandardItemLighting();
	GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);

	GL11.glRotatef(10, 1.0F, 0.0F, 0.0F);


	//GL11.glRotatef((((float)(System.currentTimeMillis()%10000)) / 10000)*360, 0, 1, 0);

	float percent = (((float)(System.currentTimeMillis()%5000)) / 5000);
	if(percent < 0.75){
		GL11.glRotatef(percent*180F/.75F-90F, 0, 1, 0);
	}else{
		GL11.glRotatef(percent*180F/.25F-90F, 0, 1, 0);
	}

	GL11.glRotatef(0,0,1,0);
	RenderManager.instance.playerViewY = 180.0F;
	//hireable.renderShadow = false;
	RenderManager.instance.renderEntityWithPosYaw(new EntityHireable(Minecraft.getMinecraft().theWorld).setTextureInt(hireable.getTextureInt()).copyInventory(hireable), 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
	//RenderManager.instance.renderEntityWithPosYaw(par0Minecraft.thePlayer, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);

	//GL11.glRotatef((((float)(System.currentTimeMillis()%10000)) / 10000)*360, 0, -1, 0);

	GL11.glPopMatrix();
	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	RenderHelper.enableGUIStandardItemLighting();
	GL11.glDisable(GL11.GL_COLOR_MATERIAL);

	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}

public void updateScreen()
{
	if(this.hireable.HasUpgradeItem(Core.BackPack) || this.hireable.HasUpgradeItem(Core.IronBackPack) || this.hireable.HasUpgradeItem(Core.DiamondBackPack)){
		((GuiButton)this.buttonList.get(3)).enabled = true;
	}else{
		((GuiButton)this.buttonList.get(3)).enabled = false;
	}

	if(this.hireable.HasUpgradeItem(Core.LittleOven)){
		((GuiButton)this.buttonList.get(4)).enabled = true;
	}else{
		((GuiButton)this.buttonList.get(4)).enabled = false;
	}
	super.updateScreen();
}

public boolean doesGuiPauseGame()
{
	return false;
}
}

Coding, Testing, Smiling, Publishing!

I'm not very good at GUIs but why are you disabling GL_Lighting at the end? aren't you supposed to disable it at the beginning of rendering?

The proud(ish) developer of Ancients

  • Author

Tried several setting.

 

disable it before rendering.

disable it before, enable it after

enable it before.

enable it before, disable it after

 

It did not help.

Coding, Testing, Smiling, Publishing!

The only thing I can think of that would do that is either the "night" colouring or the lighting. I've only done very basic opengl so that's really all I can say

The proud(ish) developer of Ancients

The lighting is already be taken care of for you by GuiContainer, so I wouldn't mess with it unless you know exactly what you are doing. Try removing that line.

 

For rendering the model on the screen, you can actually use GuiInventory.func_147046_a (aka drawEntityOnScreen) - it can render any EntityLivingBase. It's possible you made some mistakes or changes copying this code that are affecting the lighting.

 

The only other thing I can think of is that there is something in your InvisibleButton class that is causing the lighting issue. Post that class if the above two changes don't fix it for you.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.