Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm trying to make a book like that of Thaumcraft and Mystcraft that you right-click the item and it opens a gui that I later will have a functionality such as controls for a machine receptacle. I am fairly new to modding minecraft and I know a decent bit of java but this is completely dumbfounding me. I have got it so far to have the item class, but I cant get a gui to appear on right-click

 

This is my item class

 

package archangel.necromancy.item;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

import archangel.necromancy.Necromancy;

import archangel.necromancy.lib.GuiIds;

import archangel.necromancy.lib.Strings;

 

public class ItemNecronomicon extends ItemNC {

 

    public ItemNecronomicon(int id) {

 

        super(id);

        this.setIconCoord(0, 0);

        this.setItemName(Strings.NECRONOMICON_NAME);

        this.setCreativeTab(Necromancy.tabsNecro);

        maxStackSize = 1;

       

    }

    public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)

    {

        player.openGui(Necromancy.instance, GuiIds.NECRONOMICON, world, 0, 0, 0);

        return itemstack;

    }

}

 

 

My ItemNC class

 

package archangel.necromancy.item;

 

import net.minecraft.item.Item;

import archangel.necromancy.lib.Reference;

import archangel.necromancy.lib.Sprites;

 

public class ItemNC extends Item {

 

    public ItemNC(int id) {

 

        super(id - Reference.SHIFTED_ID_RANGE_CORRECTION);

        maxStackSize = 1;

        setTextureFile(Sprites.SPRITE_SHEET_LOCATION + Sprites.ITEM_SPRITE_SHEET);

        setNoRepair();

    }

 

}

 

 

 

ModItems

 

package archangel.necromancy.item;

 

import net.minecraft.item.Item;

import archangel.necromancy.lib.ItemIds;

 

public class ModItems {

 

    /* Mod item instances */

    public static Item necronomicon;

    public static void init() {

 

        /* Initialize each mod item individually */

        necronomicon = new ItemNecronomicon(ItemIds.NECRONOMICON);

 

//        necronomicon.setContainerItem(necronomicon);

 

    }

}

 

 

 

I have figured that I need to make a GuiScreen class since I can't use tile entities for an item. I have been looking at the GuiScreenBook.class but I cannot make much sense out of it where I get a usable result. I have been google'ing solutions for a while now and either I am doing it wrong or I can't find anything other than GUI's for blocks. I would prefer guidance as to what to do/look for instead of handouts. I appreciate any help and advice. Thanks

change

 

 

player.openGui(Necromancy.instance, GuiIds.NECRONOMICON, world, 0, 0, 0);

 

 

to

 

 

player.openGui(Necromancy.instance, GuiIds.NECRONOMICON, world, player.posX, player.posY, player.posZ);

 

 

also make sure you arent giving the wrong instance of your mod

  • Author

That doesn't seem to work I am still not having any gui's pop up on rightclick. I'm fairly sure I am using the correct instance, but how would I tell for sure?

This is my main class file

 

package archangel.necromancy;

 

import net.minecraft.creativetab.CreativeTabs;

import net.minecraftforge.common.MinecraftForge;

import archangel.necromancy.block.ModBlocks;

import archangel.necromancy.configuration.ConfigurationHandler;

import archangel.necromancy.core.handlers.ActionRequestHandler;

import archangel.necromancy.core.handlers.EntityLivingHandler;

import archangel.necromancy.core.handlers.ItemPickupHandler;

import archangel.necromancy.core.handlers.PlayerDestroyItemHandler;

import archangel.necromancy.core.helper.LogHelper;

import archangel.necromancy.core.proxy.CommonProxy;

import archangel.necromancy.creativetab.CreativeTabNecro;

import archangel.necromancy.item.ModItems;

import archangel.necromancy.lib.Reference;

import archangel.necromancy.network.PacketHandler;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.Init;

import cpw.mods.fml.common.Mod.Instance;

import cpw.mods.fml.common.Mod.PostInit;

import cpw.mods.fml.common.Mod.PreInit;

import cpw.mods.fml.common.Mod.ServerStarting;

import cpw.mods.fml.common.SidedProxy;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.event.FMLServerStartingEvent;

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

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

import cpw.mods.fml.common.registry.LanguageRegistry;

 

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME,

        version = Reference.VERSION)

@NetworkMod(channels = { Reference.CHANNEL_NAME }, clientSideRequired = true,

        serverSideRequired = false, packetHandler = PacketHandler.class)

public class Necromancy {

 

    @Instance(Reference.MOD_ID)

    public static Necromancy instance;

 

    @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS,

            serverSide = Reference.SERVER_PROXY_CLASS)

    public static CommonProxy proxy;

 

    public static CreativeTabs tabsNecro = new CreativeTabNecro(CreativeTabs.getNextID(), Reference.MOD_ID);

 

    @ServerStarting

    public void serverStarting(FMLServerStartingEvent event) {

 

    }

 

    @PreInit

    public void preInit(FMLPreInitializationEvent event) {

 

        // Initialize the log helper

        LogHelper.init();

 

        // Initialize the configuration

        ConfigurationHandler.init(event.getSuggestedConfigurationFile());

 

        // Initialize the Render Tick Handler (Client only)

        proxy.registerRenderTickHandler();

 

        // Register the KeyBinding Handler (Client only)

        proxy.registerKeyBindingHandler();

 

        // Register the Sound Handler (Client only)

        proxy.registerSoundHandler();

 

    }

 

    @Init

    public void load(FMLInitializationEvent event) {

 

    //Fixes creative tab name

LanguageRegistry.instance().addStringLocalization("itemGroup.Necromancy", "en_US", "Necromancy");

 

        // Register the GUI Handler

        NetworkRegistry.instance().registerGuiHandler(instance, proxy);

 

        // Register the PlayerDestroyItem Handler

        MinecraftForge.EVENT_BUS.register(new PlayerDestroyItemHandler());

 

        // Register the Item Pickup Handler

        MinecraftForge.EVENT_BUS.register(new ItemPickupHandler());

 

        // Register the EntityLiving Handler

        MinecraftForge.EVENT_BUS.register(new EntityLivingHandler());

 

        MinecraftForge.EVENT_BUS.register(new ActionRequestHandler());

 

 

        // Initialize mod blocks

        ModBlocks.init();

 

        // Initialize mod items

        ModItems.init();

 

        // Initialize mod tile entities

        proxy.initTileEntities();

 

        // Initialize custom rendering and pre-load textures (Client only)

        proxy.initRenderingAndTextures();

 

    }

 

    @PostInit

    public void modsLoaded(FMLPostInitializationEvent event) {

 

 

    }

}

 

 

  • Author

Okay I figured some of this out and I now have a GUI appearing on right click, but how would I do this without mod loader?

 

ItemNecronomicon

 

package archangel.necromancy.item;

 

import net.minecraft.client.entity.EntityPlayerSP;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.item.ItemStack;

import net.minecraft.src.ModLoader;

import net.minecraft.world.World;

import archangel.necromancy.Necromancy;

import archangel.necromancy.client.gui.inventory.GuiNecronomicon;

import archangel.necromancy.lib.Strings;

 

public class ItemNecronomicon extends ItemNC {

 

    public ItemNecronomicon(int id) {

 

        super(id);

        this.setIconCoord(0, 0);

        this.setItemName(Strings.NECRONOMICON_NAME);

        this.setCreativeTab(Necromancy.tabsNecro);

        maxStackSize = 1;

       

    }

    public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)

    {

    if(player instanceof EntityPlayerMP)

    {

    /*

    * If your gui is a container add it here. The TileEntity itself also to be stored so, that it is accessable in this method

    * And don't forget to register the ContainerID in the mod_** class

    *

    * If your GUI is NOT a container you leave the if-block blank.

    */

 

  //  ModLoader.serverOpenWindow((EntityPlayerMP)player, new ContainerYours(/*your parameters for the constructor*/);

    }

    else

    {

    ModLoader.openGUI((EntityPlayerSP)player, new GuiNecronomicon(player /*your parameters for the constructor*/));

    }

return itemstack;

}

}

 

GuiNecronomicon

 

package archangel.necromancy.client.gui.inventory;

 

import net.minecraft.client.gui.GuiScreen;

import net.minecraft.entity.player.EntityPlayer;

 

import org.lwjgl.opengl.GL11;

 

import archangel.necromancy.lib.Sprites;

 

public class GuiNecronomicon extends GuiScreen {

public GuiNecronomicon(EntityPlayer player) {

 

}

 

public final int xSizeOfTexture = 176;

public final int ySizeOfTexture = 88;

 

@Override

public void drawScreen(int x, int y, float f) {

drawDefaultBackground();

 

int var4 = this.mc.renderEngine.getTexture(Sprites.GUI_SHEET_LOCATION + Sprites.NECRONOMICON_MODEL_TEXTURE);

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

this.mc.renderEngine.bindTexture(var4);

 

int posX = (this.width - xSizeOfTexture) / 2;

int posY = (this.height - ySizeOfTexture) / 2;

 

drawTexturedModalRect(posX, posY, 0, 0, xSizeOfTexture, ySizeOfTexture);

 

super.drawScreen(x, y, f);

}

 

@Override

public boolean doesGuiPauseGame() {

return false;

}

 

@Override

protected void keyTyped(char par1, int par2) {

if (par2 == 1 || par2 == this.mc.gameSettings.keyBindInventory.keyCode) {

this.mc.thePlayer.closeScreen();

}

}

}

 

  • Author

I figured out the GuiHandler and everything to get a block gui working, but I can't figure out the procedure for the handler for an item.

  • Author

I have that much so far in the item class, I'm just clueless to the structure/methods I need to use in the guihandler (client / server functions like for tile entity and container )

  • Author

Right, but now if its an item and I don't plan on it having a container, wouldn't I just need the GUI class and the handler? I'm sorry I'm new and completely lost trying to get this to work

  • Author

How would I go about doing that? I'm sorry I just don't see ANY tutorials whatsoever for making GUI's for items in forge. The best I found was modloader and I would prefer not using modloader. I'm trying to basically have it like in thaumcraft where you will open a book and it will have instructions/recipes to the things the player will be doing, as well as the book being used in a receptacle and when the book is in the receptacle you will have a new gui extending from the block that will act as a container/tile entity. I'm not sure if what I am trying to do with the book requires it to be a tile entity or a container, and what code is required to set it up in the guiscreen/proxy/item class or where to find references on how to do it. I have it working perfectly with the block acting as a container and it has its gui but this has me completely stumped.

  • Author

Awesome then, Thank you so much for the help. It will have to be server side, odds are I will have more questions but I will try to figure this out. Again thank you so much :)

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.