Jump to content

Recommended Posts

Posted

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!

Posted

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;

}

 

}

 

Posted

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.

Posted

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

Posted

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?

Posted

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

Posted

Thats a valid point xD. 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!

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.