Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Gui Button Click
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
mrkirby153

Gui Button Click

By mrkirby153, September 22, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

mrkirby153    3

mrkirby153

mrkirby153    3

  • Creeper Killer
  • mrkirby153
  • Members
  • 3
  • 186 posts
Posted September 22, 2013

Hello,

 

When I click on a button on my GUI, it runs the actionPreformed method 5 times. Why?

 

package mrkirby153.MscHouses.block.GUI;

import mrkirby153.MscHouses.block.Container.ContainerHouseGenerator;
import mrkirby153.MscHouses.block.tileEntity.TileEntityHouseGen;
import mrkirby153.MscHouses.lib.ResourceFile;
import mrkirby153.MscHouses.lib.Strings;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.StatCollector;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* 
* Msc Houses
*
* GuiBlockBase
*
* @author mrkirby153
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*/
@SideOnly(Side.CLIENT)
public class GuiHouseGenerator extends GuiContainer{

private GuiButton generate;
public GuiHouseGenerator (InventoryPlayer inventoryPlayer,
		TileEntityHouseGen tileEntity) {
	//the container is instanciated and passed to the superclass for handling
	super(new ContainerHouseGenerator(inventoryPlayer, tileEntity));
	this.ySize = 176;
	this.xSize = 176;
}

@Override
protected void drawGuiContainerForegroundLayer(int param1, int param2) {
	//draw text and stuff here
	//the parameters for drawString are: string, x, y, color
	fontRenderer.drawString(StatCollector.translateToLocal(Strings.RESOURCE_PREFIX+Strings.TILE_HOUSE_GEN), 8, 6, 4210752);
	//draws "Inventory" or your regional equivalent
	fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752);
	this.buttonList.add(generate = new GuiButton(0, this.width /2 + 20, this.height /2 - 65, 60, 20, "Generate"));
}

@Override
protected void actionPerformed(GuiButton button) {
	if(button.id==0){
		this.mc.displayGuiScreen((GuiScreen)null);
	}
}

@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2,
		int par3) {
	//draw your Gui here, only thing you need to change is the path
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.getTextureManager().bindTexture(ResourceFile.houseGen_Img);

	int x = (width - xSize) / 2;
	int y = (height - ySize) / 2;
	this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}

}

  • Quote

width=728 height=100http://i.imgur.com/gWwyMMO.jpg[/img]

Share this post


Link to post
Share on other sites

Mew    36

Mew

Mew    36

  • Dragon Slayer
  • Mew
  • Members
  • 36
  • 567 posts
Posted September 22, 2013

Well first thing first, you have done this slightly wrong.

 

You need to override the method initGui() and move your buttonList call to that method. That should clear it up :)

 

If it doesn't... Just post again xD

  • Quote

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Share this post


Link to post
Share on other sites

mrkirby153    3

mrkirby153

mrkirby153    3

  • Creeper Killer
  • mrkirby153
  • Members
  • 3
  • 186 posts
Posted September 22, 2013

Ok, that fixed it but if moved my container slots to the top left instead of center https://www.dropbox.com/s/3g782qkxl2nfxg2/2013-09-22_16.53.03.png

  • Quote

width=728 height=100http://i.imgur.com/gWwyMMO.jpg[/img]

Share this post


Link to post
Share on other sites

Mew    36

Mew

Mew    36

  • Dragon Slayer
  • Mew
  • Members
  • 36
  • 567 posts
Posted September 22, 2013

Can I see the Container class as well please? Also, try not to use xSize and ySize, they aren't actual variables for getting the size of the screen. That is the width/height variables. So use those instead. xSize/ySize are used for the TEXTURE size. ( just a hint :P )

  • Quote

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Share this post


Link to post
Share on other sites

mrkirby153    3

mrkirby153

mrkirby153    3

  • Creeper Killer
  • mrkirby153
  • Members
  • 3
  • 186 posts
Posted September 23, 2013

Sure

 

package mrkirby153.MscHouses.block.Container;

import mrkirby153.MscHouses.block.tileEntity.TileEntityHouseGen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
/**
* 
* Msc Houses
*
* ContainerBlockBase
*
* @author mrkirby153
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*/
public class ContainerHouseGenerator extends Container{
public ContainerHouseGenerator(InventoryPlayer inventoryPlayer, TileEntityHouseGen block_base) {

	// Add the Moduel slot to the base
        this.addSlotToContainer(new Slot(block_base, 0, 81, 18));
        //Add the material modifyer to the block base
        this.addSlotToContainer(new Slot(block_base, 2, 81, 40));
        // Add the fuel slot to the Block Base
        this.addSlotToContainer(new Slot(block_base, 1, 81, 63));


	// Add the player's inventory slots to the container
        for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) {
            for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex) {
                this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 94 + inventoryRowIndex * 18));
            }
        }

        // Add the player's action bar slots to the container
        for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex) {
            this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 152));
        }
}

@Override
public boolean canInteractWith(EntityPlayer player) {

	return true;
}

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {

	ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(par2);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (par2 == 2)
            {
                if (!this.mergeItemStack(itemstack1, 3, 39, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (par2 != 1 && par2 != 0)
            {
                if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (TileEntityFurnace.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 3 && par2 < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 3, 39, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.stackSize == itemstack.stackSize)
            {
                return null;
            }

            slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
        }

        return itemstack;
}

}

  • Quote

width=728 height=100http://i.imgur.com/gWwyMMO.jpg[/img]

Share this post


Link to post
Share on other sites

Mew    36

Mew

Mew    36

  • Dragon Slayer
  • Mew
  • Members
  • 36
  • 567 posts
Posted September 23, 2013

Well, I see nothing wrong with the code... So I am not sure what the problem is. It is probably something to do with your positioning of the slots...

 

Anyway, I hope this is solved fairly quickly. I hate small problems like this that take forever to be solved >.>

  • Quote

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • loordgek
      [1.16.5] Help with custom Event

      By loordgek · Posted 32 minutes ago

      yes  
    • Luis_ST
      [1.16.5] Help with custom Event

      By Luis_ST · Posted 56 minutes ago

      I've already found out that the bus is wrong   what do you mean by that? do you mean this: MinecraftForge.EVENT_BUS.post(event)  
    • loordgek
      [1.16.5] Help with custom Event

      By loordgek · Posted 1 hour ago

      https://github.com/Luis-st/Forge-1.16.5-36.0.1-mdk/blob/main/forge-1.16.5-36.0.1-mdk/src/main/java/net/luis/cave/api/event/ModEventFactory.java you never post the event
    • Draco18s
      [1.16.5] Help with custom Event

      By Draco18s · Posted 1 hour ago

      The error is caused by registering the event to the wrong bus. Change the bus, error goes away.
    • Luis_ST
      [1.16.5] Help with custom Event

      By Luis_ST · Posted 1 hour ago

      I already thought I wasn't sure   where is the error then? this is my enchanting table container (where i sue the event) https://github.com/Luis-st/Forge-1.16.5-36.0.1-mdk/blob/main/forge-1.16.5-36.0.1-mdk/src/main/java/net/luis/cave/common/inventory/container/ModEnchantingTableContainer.java
  • Topics

    • Luis_ST
      6
      [1.16.5] Help with custom Event

      By Luis_ST
      Started 4 hours ago

    • hammy3502
      1
      [1.16.4] Fluid Flowing Very Oddly

      By hammy3502
      Started 19 hours ago

    • <Gl33p_0r4nge>
      0
      [1.16.4] Screen Render

      By <Gl33p_0r4nge>
      Started 4 hours ago

    • forgnog
      0
      My Minecraft Forge Server Don't Start and I Don't Know Why

      By forgnog
      Started 4 hours ago

    • mikey3977
      4
      server won't start up

      By mikey3977
      Started December 4, 2020

  • Who's Online (See full list)

    • mactho
    • brok4d
    • diesieben07
    • forgnog
    • zombiedarwin
    • Microcellule
    • UltraFox_10
    • Zeher_Monkey
    • loordgek
    • Lucca_Lindup
    • a fellow friend
    • vemerion
    • Aviator737
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Gui Button Click
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community