Jump to content

[1.7.10] Custom Gui for custom crafting table.


TristanvO

Recommended Posts

So I have a problem where nothing happens when I right click on my custom workbench. No gui opens at all?

 

Workbench block class:

http://pastebin.com/Qe6HDm3q

 

GuiCrafting class:

http://pastebin.com/LrqgfuG9

 

ContainerWorkbench class:

http://pastebin.com/TWTfdC7n

 

I use 1.7.10, if you need any more information, just tell me!

 

Thanks

Tristan

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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? :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.