Jump to content

GUI issue


zedblade

Recommended Posts

Hello,

 

I'm developing a mod with 2 objects (1 Item, 1 block) and 2 very similar GUI.

 

Now when i right-click on my block with my item in hand i open a GUI to save the position of the block into a tagCompound of my Item, and instead when i right-click with my item at any part i open another GUI totally similar to the previous GUI.

 

The GUIs have 1 Title, 1 textfield and 2 buttons (OK and Cancel), this is the code:

 

 

 

package portalgates;

 

import net.minecraft.src.EntityClientPlayerMP;

import net.minecraft.src.EntityPlayer;

import net.minecraft.src.GuiButton;

import net.minecraft.src.GuiScreen;

import net.minecraft.src.GuiTextField;

import net.minecraft.src.Packet250CustomPayload;

import org.lwjgl.input.Keyboard;

import net.minecraft.src.ItemStack;

import net.minecraft.src.MovingObjectPosition;

import net.minecraft.src.NBTTagCompound;

import net.minecraft.src.World;

 

public class PortalPlateGui extends GuiScreen

{

    private String TITLE = "Portal Gate's Name";

    EntityPlayer entityPlayer;

    private GuiTextField txt_PortalName;

    private GuiButton btn_ok;

    private GuiButton btn_cancel;

 

    public PortalPlateGui(EntityPlayer var1)

    {

        this.entityPlayer = var1;

    }

 

    /**

    * Called from the main game loop to update the screen.

    */

    public void updateScreen()

    {

        this.txt_PortalName.updateCursorCounter();

    }

   

    /**

    * Adds the buttons (and other controls) to the screen in question.

    */

    public void initGui()

    {

        Keyboard.enableRepeatEvents(false);

        this.controlList.clear();

        int var1 = this.width / 2 + 100 - 80;

        int var2 = this.height / 2 + 50 - 24;

        this.btn_ok = new GuiButton(0, var1, var2, 60, 20, "OK");

        this.btn_ok.enabled = false;

        var1 = this.width / 2 - 100 + 20;

        var2 = this.height / 2 + 50 - 24;

        this.btn_cancel = new GuiButton(1, var1, var2, 60, 20, "Cancel");

        this.controlList.add(this.btn_ok);

        this.controlList.add(this.btn_cancel);

        var1 = this.width / 2 - 100;

        var2 = this.height / 2 - 50 + 47;

        this.txt_PortalName = new GuiTextField(this.fontRenderer, var1, var2, 200, 20);

        this.txt_PortalName.setFocused(true);

        this.txt_PortalName.setMaxStringLength(32);

    }

 

    /**

    * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).

    */

    protected void actionPerformed(GuiButton var1)

    {

        if (var1.enabled)

        {

            switch (var1.id)

            {

                case 0:

                    String var2 = this.txt_PortalName.getText().trim();

                    this.sendNewNameToServer(var2);

 

                case 1:

                    this.mc.displayGuiScreen((GuiScreen)null);

                    this.mc.setIngameFocus();

 

                default:

            }

        }

    }

 

    /**

    * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).

    */

    protected void keyTyped(char var1, int var2)

    {

        this.txt_PortalName.textboxKeyTyped(var1, var2);

        ((GuiButton)this.controlList.get(0)).enabled = this.txt_PortalName.getText().trim().length() > 0;

 

        if (var1 == 10)

        {

            this.actionPerformed((GuiButton)this.controlList.get(0));

        }

 

        if (Integer.valueOf(var1).intValue() == 27)

        {

            this.actionPerformed((GuiButton)this.controlList.get(1));

        }

    }

 

    /**

    * Called when the mouse is clicked.

    */

    protected void mouseClicked(int var1, int var2, int var3)

    {

        super.mouseClicked(var1, var2, var3);

        this.txt_PortalName.mouseClicked(var1, var2, var3);

    }

 

    /**

    * Draws the screen and all the components in it.

    */

    public void drawScreen(int var1, int var2, float var3)

    {

//    System.out.println(var1);

//    System.out.println(var2);

//    System.out.println(var3);

   

        this.drawDefaultBackground();

        this.drawGuiBackground();

        int var4 = this.width / 2 - this.fontRenderer.getStringWidth(this.TITLE) / 2;

        int var5 = this.height / 2 - 50 + 20;

        this.fontRenderer.drawStringWithShadow(this.TITLE, var4, var5, 0xff4040);

        var4 = this.width / 2 - 100;

        var5 = this.height / 2 - 50 + 35;

        //this.fontRenderer.drawString("New name:", var4, var5, 4210752);

        this.txt_PortalName.drawTextBox();

        super.drawScreen(var1, var2, var3);

    }

 

    protected void drawGuiBackground()

    {

        int var1 = this.mc.renderEngine.getTexture("/gui/guiportal.png");

        this.mc.renderEngine.bindTexture(var1);

        int var2 = (this.width - 100) / 2;

        int var3 = (this.height - 50) / 2;

        this.drawTexturedModalRect(var2 - 100 + 30, var3 - 50 + 30 + 5, 0, 0, 240, 100);

    }

 

    protected void sendNewNameToServer(String var1)

    {

        String var3 = (new String(var1)).trim();       

    }

}

 

 

 

In a new world i use all my objects without problems but when i esc and re-load my world MC goes to crash, randomly but most of the times, when i try to open a GUI with my Item in hand:

 

 

 

2012-12-23 01:05:09 [iNFO] [ForgeModLoader] Forge Mod Loader version 4.5.2.459 for Minecraft 1.4.5 loading

2012-12-23 01:05:10 [iNFO] [sTDOUT] 27 achievements

2012-12-23 01:05:11 [iNFO] [sTDOUT] 208 recipes

2012-12-23 01:05:11 [iNFO] [sTDOUT] Setting user: Player391, -

2012-12-23 01:05:11 [iNFO] [sTDERR] Client asked for parameter: server

2012-12-23 01:05:11 [iNFO] [sTDOUT] LWJGL Version: 2.4.2

2012-12-23 01:05:12 [iNFO] [ForgeModLoader] Attempting early MinecraftForge initialization

2012-12-23 01:05:12 [iNFO] [sTDOUT] MinecraftForge v6.4.1.411 Initialized

2012-12-23 01:05:12 [iNFO] [ForgeModLoader] MinecraftForge v6.4.1.411 Initialized

2012-12-23 01:05:12 [iNFO] [sTDOUT] Replaced 84 ore recipies

2012-12-23 01:05:12 [iNFO] [ForgeModLoader] Completed early MinecraftForge initialization

2012-12-23 01:05:12 [iNFO] [ForgeModLoader] Searching C:\Users\7ed\Desktop\MPC\jars\mods for mods

2012-12-23 01:05:13 [iNFO] [ForgeModLoader] Forge Mod Loader has identified 7 mods to load

2012-12-23 01:05:13 [iNFO] [ForgeModLoader] Configured a dormant chunk cache size of 0

2012-12-23 01:05:13 [iNFO] [sTDOUT] Custom Stack Limit: FILE PATH = C:\Users\7ed\Desktop\MPC\jars\config\stacking.properties

2012-12-23 01:05:13 [iNFO] [sTDOUT] Custom Stack Limit: READING CONFIG FILE

2012-12-23 01:05:14 [iNFO] [sTDOUT] Starting up SoundSystem...

2012-12-23 01:05:14 [iNFO] [sTDOUT] Initializing LWJGL OpenAL

2012-12-23 01:05:14 [iNFO] [sTDOUT]    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

2012-12-23 01:05:14 [iNFO] [sTDOUT] OpenAL initialized.

2012-12-23 01:05:15 [iNFO] [ForgeModLoader] Forge Mod Loader has successfully loaded 7 mods

2012-12-23 01:05:18 [iNFO] [ForgeModLoader] Loading dimension 0 (New World) (net.minecraft.src.IntegratedServer@80cbba)

2012-12-23 01:05:18 [iNFO] [ForgeModLoader] Loading dimension 1 (New World) (net.minecraft.src.IntegratedServer@80cbba)

2012-12-23 01:05:18 [iNFO] [ForgeModLoader] Loading dimension -1 (New World) (net.minecraft.src.IntegratedServer@80cbba)

2012-12-23 01:05:24 [iNFO] [ForgeModLoader] Unloading dimension 0

2012-12-23 01:05:24 [iNFO] [ForgeModLoader] Unloading dimension -1

2012-12-23 01:05:24 [iNFO] [ForgeModLoader] Unloading dimension 1

2012-12-23 01:05:24 [iNFO] [sTDERR] net.minecraft.src.ReportedException: Rendering screen

2012-12-23 01:05:24 [iNFO] [sTDERR] at net.minecraft.src.EntityRenderer.updateCameraAndRender(EntityRenderer.java:986)

2012-12-23 01:05:24 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:888)

2012-12-23 01:05:24 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:783)

2012-12-23 01:05:24 [iNFO] [sTDERR] at java.lang.Thread.run(Unknown Source)

2012-12-23 01:05:24 [iNFO] [sTDERR] Caused by: java.lang.NullPointerException

2012-12-23 01:05:24 [iNFO] [sTDERR] at net.minecraft.src.GuiScreen.drawWorldBackground(GuiScreen.java:254)

2012-12-23 01:05:24 [iNFO] [sTDERR] at net.minecraft.src.GuiScreen.drawDefaultBackground(GuiScreen.java:249)

2012-12-23 01:05:24 [iNFO] [sTDERR] at portalgates.PortalGateGui.drawScreen(PortalGateGui.java:153)

2012-12-23 01:05:24 [iNFO] [sTDERR] at net.minecraft.src.EntityRenderer.updateCameraAndRender(EntityRenderer.java:977)

2012-12-23 01:05:24 [iNFO] [sTDERR] ... 3 more

2012-12-23 01:05:34 [iNFO] [sTDOUT] Stopping!

2012-12-23 01:05:34 [iNFO] [sTDOUT] SoundSystem shutting down...

2012-12-23 01:05:34 [iNFO] [sTDOUT]    Author: Paul Lamb, www.paulscode.com

2012-12-23 01:05:36 [iNFO] [sTDERR] Someone is closing me!

 

 

 

Sorry for my English but Please Help!

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.