Jump to content

Recommended Posts

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

Posted

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?

Posted

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

Posted

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

 

Posted

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

 

Posted

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.

Posted

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

 

Posted

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.

Posted

ExpandedAesthetics.java

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

CommonProxy.java

  public void init() {
  }

 

Posted

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;

 

Posted
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

Posted

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

 

Posted

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

 

Posted (edited)

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

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