Jump to content

Using IGuiHandler


tarun1998

Recommended Posts

Okay having some problems with the gui for a block.

 

 

 

Mod File on server.


public Object getGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if(ID == 90)
{
return new ContainerWaterCollector(player.inventory, new TileEntityWaterCollector());
}
if(ID == 91)
{
return new ContainerJM(player.inventory, new TileEntityJM());
}
return null;
}

 

Mod File on Client:


public Object getGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if(ID == 90)
{
return new GuiWaterCollector(player.inventory, new TileEntityWaterCollector());
}
if(ID == 91)
{
return new GuiJM(player.inventory, new TileEntityJM());
}
return null;
}

 

ContainerJM Server:


public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    {
        return jm.isUseableByPlayer(par1EntityPlayer);
    }

 

TileEntityJM Server:

public boolean isUseableByPlayer(EntityPlayer entityplayer)
    {
     return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityplayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
    }

 

BlockJM Server:


public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
    {
        if (world.isRemote)
        {
            return true;
        }
        else
        {
            entityplayer.openGui(mod_ThirstMod.mod, 91, world, i, j, k);
            return true;
        }
    }

 

However when I run it, game crashes with the following error:


[WARNING] Failed to handle packet: java.lang.NullPointerException
java.lang.NullPointerException
at net.minecraft.src.ThirstMod.containers.TileEntityJM.isUseableByPlayer(TileEntityJM.java:268)
at net.minecraft.src.ThirstMod.containers.ContainerJM.canInteractWith(ContainerJM.java:86)
at net.minecraft.src.EntityPlayer.onUpdate(EntityPlayer.java:239)
at net.minecraft.src.EntityPlayerMP.localOnUpdateEntity(EntityPlayerMP.java:1066)
at net.minecraft.src.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:1060)
at net.minecraft.src.NetServerHandler.handleFlying(NetServerHandler.java:241)
at net.minecraft.src.Packet10Flying.processPacket(Packet10Flying.java:41)
at net.minecraft.src.NetworkManager.processReadPackets(NetworkManager.java:353)
at net.minecraft.src.NetServerHandler.handlePackets(NetServerHandler.java:73)
at net.minecraft.src.NetworkListenThread.handleNetworkListenThread(NetworkListenThread.java:113)
at net.minecraft.server.MinecraftServer.doTick(MinecraftServer.java:566)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:445)
at net.minecraft.src.ThreadServerApplication.run(ThreadServerApplication.java:18)

 

 

 

If you need more code PM me.

This is also happening with the Water Collector

Link to comment
Share on other sites

Seems fairly straight forward, something in your code is null at the time you try to access it.

Learn to debug your own code please, we are not a IDE.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Thanks mate, all working now. Turns out worldObj was null for some reason. But I do believe this may be a bug, when you put something into the TileEntity (similar to Furnace) it does not send the information back so that in this case the drink is never made. This is the exact same code as the MLMP version except with the Forge GUI, packets etc. So I have no clue why this is not working. Do you have to register TileEntities with some sort of Forge register method or use the MinecraftForge.registerEntity method.

Link to comment
Share on other sites

You have to open the gui in whatever form that allows you to put items in.

And you need to do whatever you need to do to make sure the client sends the click events to the server.

Just like you've always had to, for any gui.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

How would you send back the so called "clicks" to the server. I'm not sure why or how because it was all working on MLMP and so far not impressed with the difficulty to port to or use FML. Anyways how would I send the "clicks" back. Packets possibly.

Link to comment
Share on other sites

As long as you are doing things properly, as Minecraft does them, None of this should be an issue.

If you're having issues when converting, its MLMP, or your fault. Not ours.

Go look into how clicks are sent to the server for normal MC stuff, figure out why its not working for your GUI.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

No everything is working on MLMP version. You probably (or CPW) did not add a functionality that MLMP does for you already relating to Tile Entities. I'll have a good look at MLMP files to fix this problem BTW is everything in the code on the first post for the GUI alright?

 

Some methods in ModLoaderMp.class Server:

getTileEntityPacket

sendTileEntityPacket

 

I'll have a look at it myself.

 

Or maybe i'll just send some itemstack packets with things inside the container... Hm...

Link to comment
Share on other sites

We specifically don't add those 1 line helper functions because they are stupid.

If you use them, move to the proper way of doing things.

But ya the bulk of the stuff in your first post looks fine.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

  • 4 weeks later...

Thanks mate, all working now. Turns out worldObj was null for some reason. But I do believe this may be a bug, when you put something into the TileEntity (similar to Furnace) it does not send the information back so that in this case the drink is never made. This is the exact same code as the MLMP version except with the Forge GUI, packets etc. So I have no clue why this is not working. Do you have to register TileEntities with some sort of Forge register method or use the MinecraftForge.registerEntity method.

 

Why was WorldObj Null?

I'm having the exact same problem.

Link to comment
Share on other sites

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.