Jump to content

Recommended Posts

Posted

You open the vanilla GUI, which checks to see if the player is using a vanilla workbench, and immediately closes the gui if they are not.

 

You need to open your custom GUI using a GuiHandler and player.openGui(...) which includes passing your mod ID.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Never mind. I put it in the workbench class.

 

    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int par6, float par7, float par8, float par9)

    {

    entityplayer.openGui(Mod.Instance, par6, world, x, y, z);

 

    }

 

I don't know what to put in "mod.instance" and in "par6" though. Can you help me with that as well? :)

Posted

Your 'Main' class should have an 'instance' field, e.g.:

@Mod(modid = ModInfo.ID, name = ModInfo.NAME, version = ModInfo.VERSION)
public class Main
{
@Mod.Instance(ModInfo.ID)
public static Main instance;

It doesn't have to be named 'Main', it could be 'YourMod' or whatever, but it is your main class that contains all of the critical mod components.

 

As for 'par6', that is the ID of the GUI screen you wish to open. For my mods, I create a constant for each GUI that I can reference, e.g. MyGuiHandler.GUI_SCREEN_ONE might be 1, and GUI_SCREEN_TWO would be 2, etc. That way your IGuiHandler has some way to determine which Gui and Container to class to return.

Posted

I've tried so much and I have done everything you said but I still can't get it to work. It's giving some errors now. Here are my files now:

 

moriumWorkbench.java:

http://pastebin.com/1zb2Dkn7

 

GuiHandler.java:

http://pastebin.com/dA0gm4se

 

ContainerModTileEntity.java:

http://pastebin.com/DZ3fY7ab

 

ContainerMoriumWorkbench.java:

http://pastebin.com/y0p6pJYW

 

GuiCrafting.java:

http://pastebin.com/yAznNezz

 

The errors that are given:

GuiHandler.java:line 17 (BlockPos)

GuiHandler.java:line 26 (line 26 completely)

 

 

If you want to know anything else, let me know! I hope somebody can help me because I've been trying for a long time and I have no idea how to finally get my custom workbench!

 

Thanks

 

Posted

The errors that are given:

GuiHandler.java:line 17 (BlockPos)

GuiHandler.java:line 26 (line 26 completely)

 

You've gone all bonkers with the file.  The first problem is that BlockPos does not exist in 1.7.10, but you're trying to use it.

This is what the class should look like.

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Thanks for helping but I really have no idea what to do to be honest.

 

This is what I changed my GuiHandler.java to:

package com.tristanvo.mod.gui;

 

import com.tristanvo.mod.blocks.moriumWorkbench;

 

import cpw.mods.fml.common.network.IGuiHandler;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

 

public class GuiHandler implements IGuiHandler {

 

@Override

    public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {

if(id == 0) {

TileEntity tileEntity = world.getTileEntity(x, y, z);

if(tileEntity instanceof moriumWorkbench){

return new ContainerModTileEntity(player.inventory, (moriumWorkbench) tileEntity);

}

}

return null;

    }

 

    @Override

    public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {

    if(id == 0) {

TileEntity tileEntity = world.getTileEntity(x, y, z);

if(tileEntity instanceof moriumWorkbench){

return new GuiCrafting(player.inventory, (moriumWorkbench) tileEntity);

}

    }

return null;

    }

}

 

And this gives an error as well right now:

entityplayer.openGui(mod.instance, GuiHandler.???, world, x, y, z);

Posted

You removed the public static field

tile_entity_gui

. You still need that, or can replace it with a 0 (but doing so violates the advice given upthead, but to follow it you'd need to check

id == tile_entity_gui

instead of

id == 0

).

 

((Also, tile_entity_gui is a terrible name))

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

@Override

    public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {

if(id == 0) {

TileEntity tileEntity = world.getTileEntity(x, y, z);

if(tileEntity instanceof ContainerModTileEntity){

return new ContainerMoriumWorkbench(player.inventory, (ContainerModTileEntity) tileEntity);

}

}

return null;

    }

 

    @Override

    public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {

    if(id == 0) {

TileEntity tileEntity = world.getTileEntity(x, y, z);

if(tileEntity instanceof ContainerModTileEntity){

return new GuiCrafting(player.inventory, (ContainerModTileEntity) tileEntity);

}

    }

return null;

    }

}

 

I don't know what to put in "ContainerModTileEntity, ContainerMoriumWorkbench, GuiCrafting" because those all give an error while I do have these classes in my mod package!

Posted

You should be passing the TileEntity itself.

The reason this isn't working is because your block doesn't HAVE a tile entity and the Container/GuiContainer are expecting an object of type

moriumWorkbench

(which, by the way, you should capitalize and prepend with "Block",

BlockMoriumWorkbench

)

 

You don't have a TileEntity to pass, so the

TileEntity tileEntity = world.getTileEntity(x, y, z);

is going to return null anyway and fail the instanceof check.  If you want to do this with just the block, you're going to have some trouble.

 

In fact, I already see some problems in your other classes.  ContainerModTileEntity has this line:

 

        for(int y = 0; y < 3; ++y)
        {
            for(int x = 0; x < 3; ++x)
            {
                this.addSlotToContainer(new Slot(inventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
            }
        }

 

That's supposed to be adding a 3x3 grid for the crafting, but the inventory you told the slot that it is a part of is the player's inventory!

 

Then there's this:

 

    public boolean canInteractWith(EntityPlayer player) {
        return ((IInventory) this.te).isUseableByPlayer(player);
    }

 

te

in this context is a

moriumWorkbench

, which as established above is a Block which does not extend IInventory! This line will throw a null pointer exception when run, as will likely your

transferStackInSlot

method; I'm not entirely sure what'll happen.

 

Long story short, you've followed a tutorial for how to add a gui interface for a TileEntity and have even named your classes with "TileEntity" even though you do not have one.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Thanks, I already fixed the problems in all the classes except for the GuiHandler.java. How do I create a tile entity inside my block class then? I really still don't get it although I'm very thankful for you help!

Posted

implement ITileEntityProvider and override its methods.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.