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

I have a problem with trying to open a custom GUI. Here is my code

 

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)

    {

        if (par1World.isRemote)

        {

       

            return true;

 

        }

        else

        {

            TileEntityInfuser tileEntityInfuser = (TileEntityInfuser)par1World.getBlockTileEntity(par2, par3, par4);

 

            if (tileEntityInfuser != null)

            {

    par5EntityPlayer.openGui(SoulCraft.instance, SoulCraft.guiIdInfuser, par1World, par2, par3, par4);

            }

 

            return true;

        }

    }

 

 

That wont work. The only way I can get it to work is to change the par1world.isRemote to "if(!par1World.isRemote)" This makes the gui open but breaks some other things. Any help would be greatly appreciated!

  • Author

here is my GUI handler class

 

 

package somarani.soulcraft.gui;

 

import somarani.soulcraft.common.SoulCraft;

import somarani.soulcraft.tileentity.TileEntityInfuser;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import cpw.mods.fml.common.network.IGuiHandler;

import cpw.mods.fml.common.network.NetworkRegistry;

 

public class GuiHandler implements IGuiHandler {

 

public GuiHandler(){

NetworkRegistry.instance().registerGuiHandler(SoulCraft.instance, this);

}

 

public Object getServerGuiElement(int ID, EntityPlayer player, World world,

int x, int y, int z) {

 

TileEntity entity = world.getBlockTileEntity(x, y, z);

 

if (entity != null)

{

switch (ID){

case SoulCraft.guiIdInfuser:

if (entity instanceof TileEntityInfuser){

return new ContainerInfuser(player.inventory, (TileEntityInfuser) entity);

}

}

}

 

return null;

}

 

 

public Object getClientGuiElement(int ID, EntityPlayer player, World world,

int x, int y, int z) {

 

TileEntity entity = world.getBlockTileEntity(x, y, z);

 

if (entity != null)

{

switch (ID){

case SoulCraft.guiIdInfuser:

if (entity instanceof TileEntityInfuser){

return new GuiInfuser(player.inventory, (TileEntityInfuser) entity);

}

 

}

}

 

return null;

}

 

}

 

Quick question die: Is it preferable to use pastebin/github over using code/spoiler tags?

We all stuff up sometimes... But I seem to be at the bottom of that pot.

  • Author

Hi here are the classes you asked for, sorry for posting incorrectly, I'm new here :)

 

Container Class - http://pastebin.com/Jjr6GbVW

 

GUI Handler Class - http://pastebin.com/x0s9Mgsk

 

Block GUI Class - http://pastebin.com/cVDvmuDJ

 

Tile Entity Class - http://pastebin.com/Zq6WQcVd

 

Also please keep in mind that all the smelting recipes, etc are still incomplete as I'm first trying to get the GUI working. If its of any help, when I change it to "if(!par1World.isRemote)" the GUI does open correctly and shows me the player inventory but doesn't allow me to move any of the items in the inventory.

 

Also what I'm attempting to do with this block is have the user place a gold ingot on top, a custom item on the bottom and it results a new item. If anyone could help with that it would be greatly appreciated.

 

Thanks for the help

  • Author

I tried outputting a message when (par1World.isRemote) and the message never showed up, but it did show up when I changed it to check if the world is remote. Could it have to do something with my Proxy classes? or my @server configuration?

  • Author

Well, good news I guess, on right click it does show true and false. If anyone has any ideas please let me know

  • Author

Just a side note, if I set it to check if the world is remote the GUI does open and display properly, but it doesn't allow me to pick up any of the inventory items, they snap back in place as soon as I pick them up

 

Here is my common proxy, it would be great if someone can take a look and see if something there is causing the problem.

 

http://pastebin.com/qmNNrVY6

  • Author

One is a gui Handler and one is a gui container. This is my first time coding a minecraft mod, is there a better way to do this? Thanks

  • Author

Thats a valid point xD. Like I said Im new to this. In my main mod class I have

 

public static CommonProxy proxy

 

and i also have

 

GuiHandler guiHandler = new GuiHandler();

 

I tried completely deleting my GUI handler class and putting everything in it inside common proxy and it still didn't work. But I feel like that may have something to do with the problem. What do you think I should do now? Thanks for all the help!

  • Author

It works! Thank you my problem turns out that i was never registering the Gui handler in my main class. Thanks to all for the help

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.