Jump to content

[Solved][1.8]Item slots relocating in gui


blfngl

Recommended Posts

So I've got this GUI that works fine without the public void initGui() method, however when I add it all of my item slots relocate to a new location outside of the gui. I need it to add buttons though. Help?

 

The GUI in question:

 

package blfngl.fallout.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;

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

import blfngl.fallout.player.FalloutPlayer;
import blfngl.fallout.player.inventory.ContainerPipboy;
import blfngl.fallout.player.inventory.InventoryPipboy;

public class GuiPipboy extends GuiContainer
{
private float xSize_lo;
private float ySize_lo;
private static final ResourceLocation iconLocation = new ResourceLocation("fallout", "textures/gui/pipboy.png");
private final InventoryPipboy inventory;

public GuiPipboy(ContainerPipboy containerItem)
{
	super(containerItem);
	this.inventory = containerItem.inventory;
}

public void drawScreen(int par1, int par2, float par3)
{
	super.drawScreen(par1, par2, par3);
	this.xSize_lo = (float)par1;
	this.ySize_lo = (float)par2;
}

protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
	FalloutPlayer props = FalloutPlayer.get(Minecraft.getMinecraft().thePlayer);
	this.fontRendererObj.drawString("Rads: " + props.getCurrentRads(), width / 5, 6, 4210752);
}

protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.getTextureManager().bindTexture(iconLocation);
	int k = (this.width - this.xSize) / 2;
	int l = (this.height - this.ySize) / 2;
	this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
	int i1;
	drawPlayerModel(k + 51, l + 75, 30, (float)(k + 51) - this.xSize_lo, (float)(l + 75 - 50) - this.ySize_lo, this.mc.thePlayer);
}

public void initGui()
{
                  //WHEN THIS METHOD IS IN THE CODE EVERYTHING BREAKS
}

public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity)
{
	GL11.glEnable(GL11.GL_COLOR_MATERIAL);
	GL11.glPushMatrix();
	GL11.glTranslatef(x, y, 50.0F);
	GL11.glScalef(-scale, scale, scale);
	GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
	float f2 = entity.renderYawOffset;
	float f3 = entity.rotationYaw;
	float f4 = entity.rotationPitch;
	float f5 = entity.prevRotationYawHead;
	float f6 = entity.rotationYawHead;
	GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
	RenderHelper.enableStandardItemLighting();
	GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
	GL11.glRotatef(-((float) Math.atan(pitch / 40.0F)) * 20.0F, 1.0F, 0.0F, 0.0F);
	entity.renderYawOffset = (float) Math.atan(yaw / 40.0F) * 20.0F;
	entity.rotationYaw = (float) Math.atan(yaw / 40.0F) * 40.0F;
	entity.rotationPitch = -((float) Math.atan(pitch / 40.0F)) * 20.0F;
	entity.rotationYawHead = entity.rotationYaw;
	entity.prevRotationYawHead = entity.rotationYaw;
	GL11.glTranslatef(0.0F, (float) entity.getYOffset(), 0.0F);
	RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager();
	rendermanager.setPlayerViewY(180.0F);
	rendermanager.setRenderShadow(false);
	rendermanager.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
	rendermanager.setRenderShadow(true);
	entity.renderYawOffset = f2;
	entity.rotationYaw = f3;
	entity.rotationPitch = f4;
	entity.prevRotationYawHead = f5;
	entity.rotationYawHead = f6;
	GL11.glPopMatrix();
	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
}

 

Link to comment
Share on other sites

GuiContainer actually uses initGui() in its class.

 

When you are using it you need to call super.initGui() (first thing you do).

 

EDIT

Also - you shouldn't have to have any globals in YourGuiContainer - everything is alredy provided from GuiContainer.

Seriously - everything.

 

@SideOnly(Side.CLIENT)
public class MyGui extends GuiContainer
{
public MyGui(TileEntity te, EntityPlayer player)
{
	super(new MyContainer(te, player));

	this.xSize = 164; // set those in constructor - those should be literally width and lenght of your gui.png which will be the background.
	this.ySize = 233;
}
}

Then you have those:

protected int guiLeft;

protected int guiTop;

 

Those two are literally "the top border and the left border" of your gui.png (you need to set x and y Size in constructor).

What MC will do is in initGui() it will take those xSize and ySize and set guiLeft and guiTop to right values.

  • Like 1

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

  • 2 weeks later...

-snip-

Hey, sorry for the late reply, but your solution seems to move the picture, what my problem was is that the actual SLOT is moving and getting desynced with my picture. It only happens when I have the initGui() method included.

Link to comment
Share on other sites

Alredy told you:

 

2qxxi7s.jpg

 

xSize and ySize are LITERALLY the width and height of your gui in gui.png. You HAVE TO set them in constructor.

Then, GuiContainer.class in its initGui() has this code:

    public void initGui()
    {
        super.initGui();
        this.mc.thePlayer.openContainer = this.inventorySlots;
        this.guiLeft = (this.width - this.xSize) / 2;
        this.guiTop = (this.height - this.ySize) / 2;
    }

Which will nicely set the position guiLeft and guiTop which are EXACT starting position of your gui.png on screen.

 

If you are overriding initGui() , first thing you do - you need to call super.initGui().

Then you DO NOT use any of your values regarding x/y. You use only guiLeft and guiTop (and maybe others) - I told you, everything is there, internally.

 

As to slots: When adding slots insie your Container class you use x/y (as shown on picture). GuiContainer will place your slots in x/y coords, starting from guiLeft and guiTop - this it's important that you use them and not write your own coordinate handlers.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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