Jump to content

Recommended Posts

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

Posted

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

Posted

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

 

 

    }

}

 

 

Posted

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

}

}

}

 

Posted

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.

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

    • Yep I did upgrade just because it showed me a new version available.  I'll redownload the mod list and make sure anything works.  Thanks!
    • The latest log was taken down by pastebin for some reason. Did you try removing the mods you added? The mods you updated, was there a specific reason you updated, or just because? It's possible the updates introduced incompatibilitie, or even need a newer build of forge. If you didn't need the updates for a specific reason, you could also try downgrading those mods.
    • Please read the FAQ, and post logs as described there. https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/
    • I am using forge 1.20.1 (version 47.3.0). My pc has an RTX 4080 super and an i9 14900 KF, I am on the latest Nvidia graphics driver, latest windows 10 software, I have java 23, forge 1.12.2 works and so does all vanilla versions but for some reason no version of forge 1.20.1 works and instead the game just crashes with the error code "-1." I have no mods in my mods fodler, I have deleted my options.txt and forge.cfg files in case my settings were causing a crash and have tried removing my forge version from the installations folder and reinstalling but no matter what I still crash with the same code and my log doesn't tell me anything: 18:34:53.924 game 2025-02-06 18:34:53,914 main WARN Advanced terminal features are not available in this environment 18:34:54.023 game [18:34:54] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, mrmirchi, --version, 1.20.1-forge-47.3.0, --gameDir, C:\Users\aryam\AppData\Roaming\.minecraft, --assetsDir, C:\Users\aryam\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 2db00ea8d678420a8956109a85d90e9d, --accessToken, ????????, --clientId, ZWI3NThkNzMtNmNlZS00MGI5LTgyZTgtYmZkNzcwMTM5MGMx, --xuid, 2535436222989555, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\aryam\AppData\Roaming\.minecraft\quickPlay\java\1738838092785.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.3.0, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] 18:34:54.027 game [18:34:54] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 18:34:54.132 game [18:34:54] [main/INFO] [ne.mi.fm.lo.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow 18:34:54.191 game [18:34:54] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6 18:34:54.303 game [18:34:54] [main/INFO] [EARLYDISPLAY/]: Requested GL version 4.6 got version 4.6 18:34:54.367 monitor Process Monitor Process crashed with exit code -1     screenshot of log: https://drive.google.com/file/d/1WdkH88H865XErvmIqAKjlg7yrmj8EYy7/view?usp=sharing
    • I am currently working on a big mod, but I'm having trouble with my tabs, I want to find a way to add tabs inside tabs, like how in mrcrayfishes furniture mod, his furniture tab has multiple other sub tabs to them, so i know it is possible but i just don't know how it is possible, any help would be appreciated, thanks
  • Topics

×
×
  • Create New...

Important Information

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