Jump to content

[1.7.2] Gui with purchasing function


TheDav1311

Recommended Posts

I want to have a Gui with a purchasing function

 

I get the item but when i use it it delete itself

 

Code:

public class GuiTraitorMenu extends GuiScreen
{
private GuiButton teleporter = new GuiButton(0, 150 , 60, 100, 20, "Teleporter 2G");
private GuiButton fakemedipack = new GuiButton(1, 150 , 100, 100, 20, "explodierender Erste Hilfe Set 3G");

public GuiTraitorMenu ()
{ 
	super();
}

@Override
public void drawScreen(int x, int y, float f)
{
	drawDefaultBackground();

	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.renderEngine.bindTexture(new ResourceLocation("minecrafttrouble:textures/gui/TraitorMenu.png"));

	drawTexturedModalRect((this.width - 256) / 2, (this.height - 256) *2, 0, 0, 256, 256);

	super.drawScreen(x, y, f);
}

@Override
public void initGui()
{
	this.buttonList.clear();
	this.buttonList.add(teleporter);
	this.buttonList.add(fakemedipack);
	GoldCheck();
}

public void actionPerformed(GuiButton button)
{	
	InventoryPlayer iv = this.mc.thePlayer.inventory;
	switch(button.id)
	{
		case 0:	iv.addItemStackToInventory(new ItemStack(main.Teleporter));
				iv.consumeInventoryItem(main.Gold);iv.consumeInventoryItem(main.Gold);
				GoldCheck();

		case 1:	iv.addItemStackToInventory(new ItemStack(main.FakeMediPack));
				iv.consumeInventoryItem(main.Gold);iv.consumeInventoryItem(main.Gold);iv.consumeInventoryItem(main.Gold);
				GoldCheck();
		break;
		default:
	}
}

@Override
public boolean doesGuiPauseGame()
{
	return false;
}

private boolean hasItemInt(Item item, int min)
{
	InventoryPlayer iv = this.mc.thePlayer.inventory;
	int own = 0;
	for(int i = 0; i < iv.getSizeInventory(); i++)
	{
		if(iv.getStackInSlot(i) != null && iv.getStackInSlot(i).getItem() == item)
		{
			own = own + iv.getStackInSlot(i).stackSize;
		}
	}
	if(own >= min)
	{
		return true;
	}
	else
	{
		return false;
	}
}

private void GoldCheck()
{
	if(hasItemInt(main.Muenze, 2))
	{
		teleporter.enabled = true;
	}
	else
	{
		teleporter.enabled = false;
	}	
	if(hasItemInt(main.Muenze, 3))
	{
		fakemedipack.enabled = true;
	}
	else
	{
		fakemedipack.enabled = false;
	}
}
}

 

Second Problem:

if I max my Minecraft the Gui is normal

but if it not about the whole screen it buggs the buttons are at the wrong position and i not see the whole Gui

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.



×
×
  • Create New...

Important Information

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