Posted July 1, 201411 yr 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!
July 1, 201411 yr 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; } }
July 1, 201411 yr 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.
July 1, 201411 yr 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
July 1, 201411 yr 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?
July 2, 201411 yr Author Well, good news I guess, on right click it does show true and false. If anyone has any ideas please let me know
July 2, 201411 yr 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
July 2, 201411 yr 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
July 2, 201411 yr Author Thats a valid point . 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!
July 2, 201411 yr 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.