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

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

  • 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?

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).

  • 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;
    }
}

 

  • 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;
      }
  }

 

  • 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.

  • 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());
  }

 

  • 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.

  • Author

ExpandedAesthetics.java

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
      NetworkRegistry.INSTANCE.registerGuiHandler(BlockHandler.class, new GuiHandler());
      proxy.preInit();
    }

CommonProxy.java

  public void init() {
  }

 

  • 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;

 

  • 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.

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

  • 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();
    }
}

 

  • 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();
    }
}

 

  • 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 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.

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.