Posted July 23, 20178 yr Hey guys, I'm having trouble getting a custom gui to show up. I'm trying to create a new furnace that is a direct upgrade to the regular furnace. Internally, I have called it the Alloy Furnace. My issue is that the custom gui I've created doesn't show up when I right click the new furnace. It shows my players inventory and that's it. And then on subsequent right clicks, the gui doesn't show up anymore. Here's my code on GitHub. And relevant files for the furnace are at: src\main\java\com\DragonFerocity\expanded\handlers\GuiHandler.java src\main\java\com\DragonFerocity\expanded\inventory\ModContainerAlloyFurnace.java src\main\java\com\DragonFerocity\expanded\entities\ModTileEntityAlloyFurnace.java src\main\java\com\DragonFerocity\expanded\gui\ModGuiAlloyFurnace.java src\main\java\com\DragonFerocity\expanded\blocks\ModAlloyFurnace.java
July 23, 20178 yr Author So, I don't understand how Quote Your git repo contains way too much crap. answers my question, but thanks for the insight /s. Also, how do I get the ID of a gui (As an integer) since the EntityPlayer::openGui method requires and int ID?
July 23, 20178 yr In my GUI handler, I have an integer constant for each GUI. In the GUI Handler methods, I open the GUI corresponding to the ID (using a switch statement, for example).
July 23, 20178 yr Author I did that, and the gui still doesn't open properly. Here's my updated GuiHandler code: @SideOnly(Side.CLIENT) public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(new BlockPos(x, y, z)); System.out.println("Server GUI ----------------------------------------------------------------------------"); if (tileEntity != null) { if (ID == BlockHandler.GUI_ENUM.ALLOY_FURNACE.ordinal()) { return new ModContainerAlloyFurnace(player.inventory, (ModTileEntityAlloyFurnace)tileEntity); } } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(new BlockPos(x, y, z)); System.out.println("Client GUI ----------------------------------------------------------------------------"); if (tileEntity != null) { if (ID == BlockHandler.GUI_ENUM.ALLOY_FURNACE.ordinal()) { return new ModGuiAlloyFurnace(player.inventory, (ModTileEntityAlloyFurnace)tileEntity); } } return null; } }
July 23, 20178 yr Author Do I call open gui there? or in the blocks/ModAlloyFurnace.java::onBlockActivated function?
July 23, 20178 yr Author Still doesn't work then. I did this before as well, just forgot to mention it. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } else { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof ModTileEntityAlloyFurnace) { playerIn.openGui((Object)ExpandedAesthetics.class, BlockHandler.GUI_ENUM.ALLOY_FURNACE.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ()); playerIn.addStat(StatList.FURNACE_INTERACTION); } return true; } }
July 23, 20178 yr Author I tried playerIn.openGui((Object)ExpandedAesthetics.instance, BlockHandler.GUI_ENUM.ALLOY_FURNACE.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ()); and playerIn.openGui("ExpandedAesthetics", BlockHandler.GUI_ENUM.ALLOY_FURNACE.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ()); Neither worked, and now the gui doesn't even show up on a right click.
July 23, 20178 yr Author I put a breakpoint in the GuiHandler and it never gets hit. I have this in the init in my CommonProxy: public void init() { NetworkRegistry.INSTANCE.registerGuiHandler(BlockHandler.class, new GuiHandler()); }
July 23, 20178 yr Author So, it crashes in both the preInit and the Init functions giving this error Invalid attempt to create a GUI during mod construction. Use an EventHandler instead Sorry, but I'm not sure what it means by Use an EventHandler instead.
July 23, 20178 yr Author ExpandedAesthetics.java @EventHandler public void preInit(FMLPreInitializationEvent event) { NetworkRegistry.INSTANCE.registerGuiHandler(BlockHandler.class, new GuiHandler()); proxy.preInit(); } CommonProxy.java public void init() { }
July 23, 20178 yr Author If I keep the line of code: NetworkRegistry.INSTANCE.registerGuiHandler(ExpandedAesthetics.instance, new GuiHandler()); in the ExpandedAesthetics::preInit function, it crashes. If I replace ExpandedAesthetics.instance with "expandedaesthetics" it still crashes. Quote net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Expanded Aesthetics (expanded) Caused by: java.lang.NullPointerException Here's my instance variable: @Instance("ExpandedAesthetics") public static ExpandedAesthetics instance;
July 23, 20178 yr 33 minutes ago, DragonFerocity said: NullPointerException 33 minutes ago, DragonFerocity said: public static ExpandedAesthetics instance; What could be wrong? Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
July 23, 20178 yr Author Sorry for not knowing everything, but when the does the instance variable get set?
July 23, 20178 yr Author Even with lowercase letters it still is null. I've debugged it so I know that it is null when it reaches the preInit function. So something must be wrong here, but I don't know what it is.
July 24, 20178 yr 7 hours ago, DragonFerocity said: Still doesn't work then. I did this before as well, just forgot to mention it. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } else { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof ModTileEntityAlloyFurnace) { playerIn.openGui((Object)ExpandedAesthetics.class, BlockHandler.GUI_ENUM.ALLOY_FURNACE.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ()); playerIn.addStat(StatList.FURNACE_INTERACTION); } return true; } } Call openGui when world.isRemote is true MobDrops http://www.planetminecraft.com/mod/125-mobdrops/
July 24, 20178 yr Author ExpandedAesthetics.java package com.DragonFerocity.expanded; import com.DragonFerocity.expanded.handlers.BlockHandler; import com.DragonFerocity.expanded.handlers.GuiHandler; import com.DragonFerocity.expanded.proxy.IProxy; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; @Mod(modid = Ref.MODID, name=Ref.NAME, version = Ref.VERSION) public class ExpandedAesthetics { public static final String MODID = "expanded"; public static final String VERSION = "1.2.0"; @Instance("expandedaesthetics") public static ExpandedAesthetics instance; @SidedProxy(clientSide=Ref.CLIENT_PROXY, serverSide=Ref.SERVER_PROXY) public static IProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.preInit(); NetworkRegistry.INSTANCE.registerGuiHandler(ExpandedAesthetics.instance, new GuiHandler()); } @EventHandler public void init(FMLInitializationEvent event) { proxy.init(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(); } }
July 24, 20178 yr Author Changed it to this: Still doesn't open any gui: package com.DragonFerocity.expanded; import com.DragonFerocity.expanded.handlers.BlockHandler; import com.DragonFerocity.expanded.handlers.GuiHandler; import com.DragonFerocity.expanded.proxy.IProxy; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; @Mod(modid = Ref.MODID, name=Ref.NAME, version = Ref.VERSION) public class ExpandedAesthetics { @Instance(Ref.MODID) public static ExpandedAesthetics instance; @SidedProxy(clientSide=Ref.CLIENT_PROXY, serverSide=Ref.SERVER_PROXY) public static IProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.preInit(); NetworkRegistry.INSTANCE.registerGuiHandler(ExpandedAesthetics.instance, new GuiHandler()); } @EventHandler public void init(FMLInitializationEvent event) { proxy.init(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(); } }
July 24, 20178 yr Author Yes, it doesn't crash now if that's what you mean. However right clicking the block still doesn't show a gui.
July 24, 20178 yr Author Try again. (P.S. does that really relate to my problem? Or are you trying to run it?) I just never pushed the new version to the repo.
July 24, 20178 yr Author I'm sorry that anything I've tried seems to not work. Oh, I'm also sorry for trying to get help on a minecraft forge forum. I'm also sorry that forge isn't throwing any errors. I'm also sorry that I don't code the same way you do. I'm also sorry that my breakpoints aren't being hit. I'm also sorry that I followed a, as you put it, stupid beginning forge tutorial.... I'm also sorry that I'm not as experienced. I'm also sorry that I'm trying to get help... Oh wait I already stated that and it doesn't seem like I'm actually getting anywhere. Edit: Btw, I removed all the unnecessary files/folders from the repo. Edited July 24, 20178 yr by DragonFerocity
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.