Jump to content

How do I make a Gui open when an item is right clicked? - SOLVED


iLegendx98

Recommended Posts

Ok, so I have a pickaxe that I want to open an Inventory for when it is right clicked. Now I am fairly new to making GUI/containers and need help as any tutorials are outdated. I have successfully made a machine that functions as a furnace does except with custom recipes. I imagine a tool inventory would be similar, except I don't think a tool is considered a tile entity. This makes it things complicated when it comes to the GUI Handler.

 

GuiHandler.java (Note: The Endite Reactor is my machine that is already working)

 

 

package gui;

 

import gui_container.ContainerEnditeReactor;

import main.RunicScrolls;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import tileentity.TileEntityEnditeReactor;

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

 

public class GuiHandler implements IGuiHandler {

 

@Override

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

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

if(entity != null) {

switch(ID) {

case RunicScrolls.guiIDEnditeReactor:

if(entity instanceof TileEntityEnditeReactor) {

return new ContainerEnditeReactor(player.inventory, (TileEntityEnditeReactor) entity);

}

return null;

}

}

 

//ADDED

if (ID == RunicScrolls.guiIDAdaptedPick) {

return null;

}

//ADDED

 

return null;

}

 

@Override

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

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

if(entity != null) {

switch(ID) {

case RunicScrolls.guiIDEnditeReactor:

if(entity instanceof TileEntityEnditeReactor) {

return new GuiEnditeReactor(player.inventory, (TileEntityEnditeReactor) entity);

}

return null;

}

}

//ADDED//

if (ID == RunicScrolls.guiIDAdaptedPick) {

return new GuiAdaptedPick(player.inventory);

}

//ADDED//

 

return null;

}

}

 

 

 

ToolAdaptedPick.java (This is the tool)

 

 

package tools;

 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage.ModIdData;

import cpw.mods.fml.common.network.internal.FMLNetworkHandler;

import main.RunicScrolls;

import net.minecraft.block.Block;

import net.minecraft.enchantment.Enchantment;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemPickaxe;

import net.minecraft.item.ItemStack;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.World;

import net.minecraftforge.common.ForgeHooks;

import net.minecraftforge.event.world.BlockEvent.BreakEvent;

 

public class ToolAdaptedPick extends ItemPickaxe {

 

public ToolAdaptedPick(int id, Item.ToolMaterial mat) {

super(mat);

}

 

@Override //ADDED//

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {

player.openGui(RunicScrolls.instance, RunicScrolls.guiIDAdaptedPick, world, (int) player.posX, (int) player.posY, (int) player.posZ);

return stack;

} //ADDED//

 

}

 

 

 

EDIT:

 

GuiAdaptedPick.java (This is the Gui Class)

 

 

package gui;

 

import java.io.IOException;

 

import org.lwjgl.opengl.GL11;

 

import gui_container.ContainerAdaptedPick;

import gui_container.ContainerEnditeReactor;

import tileentity.TileEntityEnditeReactor;

import main.RunicScrolls;

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.client.resources.I18n;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.util.ResourceLocation;

 

public class GuiAdaptedPick extends GuiContainer{

 

public static final ResourceLocation bground = new ResourceLocation(RunicScrolls.modid + ":" + "textures/gui/GuiAdaptedPick.png");

private static Object inventoryPlayer;

private Object adaptedPick;

 

public GuiAdaptedPick(InventoryPlayer inventoryPlayer) {

super(new ContainerAdaptedPick(inventoryPlayer, null));

 

this.xSize = 176;

this.ySize = 166;

}

 

public void drawGuiContainerForegroundLayer(int par1, int par2) {

String name = "Modify Adapted Pickaxe";

this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);

this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);

}

 

@Override

protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {

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

Minecraft.getMinecraft().getTextureManager().bindTexture(bground);

drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

}

 

}

 

 

 

ContainerAdaptedPick.java (This is still a WIP)

 

 

package gui_container;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.ICrafting;

import net.minecraft.inventory.IInventory;

import net.minecraft.inventory.Slot;

import net.minecraft.inventory.SlotFurnace;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.FurnaceRecipes;

import net.minecraft.tileentity.TileEntityFurnace;

import recipes.RecipesEnditeReactor;

import tileentity.TileEntityEnditeReactor;

import tools.ToolAdaptedPick;

 

public class ContainerAdaptedPick extends Container {

 

private IInventory AdaptedPick;

 

 

 

public ContainerAdaptedPick(InventoryPlayer inventory, IInventory upgInv) {

this.AdaptedPick = upgInv;

this.addSlotToContainer(new Slot(upgInv, 0, 80, 17));

this.addSlotToContainer(new Slot(upgInv, 1, 80, 53));

this.addSlotToContainer(new SlotFurnace(inventory.player, upgInv, 2, 134, 35));

 

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 9; j++) {

this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j*18, 84 + i*18));

}

}

for(int i = 0; i < 9; i++) {

this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));

}

}

 

 

 

@Override

public boolean canInteractWith(EntityPlayer p_75145_1_) {

// TODO Auto-generated method stub

return true;

}

 

 

}

 

 

 

So to clarify, I am not getting errors with code or anything, I'm just lost on how to start with the tool as it isn't a tile entity. Some guidance would be much appreciated as well as maybe some example code. I already know the basics of java so don't bother just telling me "You need to learn java!!!" That is not helpful.

 

NOTE: This is for minecraft version 1.7.10. If you want anymore of my code, just tell me and I will put it in.

Link to comment
Share on other sites

 

in your item class add

 

@Override

public ItemStack onItemRightClick(ItemStack i, World w, EntityPlayer pl) {

  pl.openGui(  fill in your own parameters here  );

  return i;

}

 

during initialization register your gui

 

NetworkRegistry.INSTANCE.registerGuiHandler(yourMod.instance,new GUIHandler());

 

 

here is what is in my gui handler

 

public class GUIHandler implements IGuiHandler {

 

@Override

public Object getServerGuiElement(int id, EntityPlayer pl, World wld, int x, int y, int z) {

MagicEnchant.debug("getServerGuiElement");

if ( id == GuiEnchantTable.GUI_ID ){

return null;

}

return null;

}

 

@Override

public Object getClientGuiElement(int id, EntityPlayer pl, World wld, int x, int y, int z) {

MagicEnchant.debug("getClientGuiElement");

if ( id == GuiEnchantTable.GUI_ID ){

return new GuiEnchantTable(pl,x,y,z);

}

return null;

}

}

 

 

 

 

Link to comment
Share on other sites

I applied the changes you said and it did something. It recognizes that I right click on the tool but then crashes! I have no red underlines in the code to signify an error, but I assume the code I made is wrong. I have pasted in my gui and container classes in the main thread. The gui class is probably wrong as I just copied my gui class for my machines (block) but editing a few methods and names.

 

Here is the crash report :

 

 

---- Minecraft Crash Report ----

// Why did you do that?

 

Time: 8/12/14 11:18 AM

Description: Rendering screen

 

java.lang.NullPointerException: Rendering screen

at net.minecraft.inventory.Slot.getStack(Slot.java:88)

at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:223)

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:118)

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1145)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1066)

at net.minecraft.client.Minecraft.run(Minecraft.java:961)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at net.minecraft.inventory.Slot.getStack(Slot.java:88)

at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:223)

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:118)

 

-- Screen render details --

Details:

Screen name: gui.GuiAdaptedPick

Mouse location: Scaled: (213, 119). Absolute: (427, 240)

Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['ForgeDevName'/4, l='MpServer', x=1083.56, y=57.62, z=677.47]]

Chunk stats: MultiplayerChunkCache: 170, 170

Level seed: 0

Level generator: ID 01 - flat, ver 0. Features enabled: false

Level generator options:

Level spawn location: World: (1072,4,688), Chunk: (at 0,0,0 in 67,43; contains blocks 1072,0,688 to 1087,255,703), Region: (2,1; contains chunks 64,32 to 95,63, blocks 1024,0,512 to 1535,255,1023)

Level time: 284725 game time, 68288 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 5 total; [EntityItemFrame['entity.ItemFrame.name'/0, l='MpServer', x=1050.06, y=56.50, z=688.50], EntityItemFrame['entity.ItemFrame.name'/1, l='MpServer', x=1050.06, y=57.50, z=689.50], EntityItemFrame['entity.ItemFrame.name'/2, l='MpServer', x=1050.06, y=58.50, z=688.50], EntityChicken['Chicken'/3, l='MpServer', x=1152.59, y=56.00, z=679.34], EntityClientPlayerMP['ForgeDevName'/4, l='MpServer', x=1083.56, y=57.62, z=677.47]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:417)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2567)

at net.minecraft.client.Minecraft.run(Minecraft.java:983)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 7 (amd64) version 6.1

Java Version: 1.8.0_05, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 769699752 bytes (734 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP v9.05 FML v7.10.18.1180 Minecraft Forge 10.13.0.1180 4 mods loaded, 4 mods active

mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{7.10.18.1180} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{10.13.0.1180} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

ilegendsrunicscrolls{v2.2 Stable} [iLegends Runic Scrolls] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Launched Version: 1.7

LWJGL: 2.9.1

OpenGL: GeForce GTX 550 Ti/PCIe/SSE2 GL version 4.3.0, NVIDIA Corporation

GL Caps: Using GL 1.3 multitexturing.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Anisotropic filtering is supported and maximum anisotropy is 16.

Shaders are available because OpenGL 2.1 is supported.

 

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: ~~ERROR~~ NullPointerException: null

Profiler Position: N/A (disabled)

Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

Anisotropic Filtering: Off (1)

 

 

 

I am usually good at reading crash reports but I am lost on this one.

 

My main class is way to large to paste in but I already had my Gui handler registered like you said.

 

public void init(FMLInitializationEvent e) {

NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());

 

//300 lines of recipes

}

 

Link to comment
Share on other sites

When I made my back pack, I added this to my gui handler for opening a gui that was equiped.

public class TEGuiHandler implements IGuiHandler{

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) 
{
	TileEntity tile_entity = world.getTileEntity(x, y, z);
	ItemStack equipped;


	 equipped = getEquippedItem(player);
      if (equipped == null) {
        return null;
      }
      if ((equipped.getItem() instanceof BackPack)) {
         return new ContainerBackPack(player, player.inventory, new ItemInventory(player.getHeldItem()));
      }


	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) 
{
	TileEntity tile_entity = world.getTileEntity(x, y, z);
	ItemStack equipped;

		//Entity BackPack
	 equipped = getEquippedItem(player);
      if (equipped == null) {
        return null;
      }
      if ((equipped.getItem() instanceof BackPack)) {
    	  return new GuiBackPack((ContainerBackPack) new ContainerBackPack(player, player.inventory, new ItemInventory(player.getHeldItem())));
      }

	return null;
}

  public ItemStack getEquippedItem(EntityPlayer player)
  {
    return player.getCurrentEquippedItem();
  }


}

Link to comment
Share on other sites

Would you be able to show me the code for your GUI and container class please? I think that there is an issue in the GUI class and I am lost with the container class. This would also be great if anyone else that has made something like this could show me their code too. I am completely lost.

Link to comment
Share on other sites

I your gui handeler, your added code needs to be a case statement inside your switch statement.  This video might help:

 

Here is my gui handeler:

 

 

package Technomage3.both.Interfaces;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import Technomage3.both.TechnologicalMagic;
import Technomage3.both.Blocks.secureBlocks.ItemBlockPlacer;
import Technomage3.both.Blocks.tileentities.TileEntityAncientSpellTable;
import Technomage3.both.Blocks.tileentities.TileEntityMageForge;
import Technomage3.both.Blocks.tileentities.TileEntityMagicPathway;
import Technomage3.both.Blocks.tileentities.TileEntityPowerCharger;
import Technomage3.both.Interfaces.containers.ContainerAncientSpellTable;
import Technomage3.both.Interfaces.containers.ContainerBlockPlacer;
import Technomage3.both.Interfaces.containers.ContainerItemNetworkAccess;
import Technomage3.both.Interfaces.containers.ContainerItemPusher;
import Technomage3.both.Interfaces.containers.ContainerItemTransferNetworkBase;
import Technomage3.both.Interfaces.containers.ContainerKeystone;
import Technomage3.both.Interfaces.containers.ContainerMageForge;
import Technomage3.both.Interfaces.containers.ContainerMagicPathwayBlocked;
import Technomage3.both.Interfaces.containers.ContainerMagicPathwayOpen;
import Technomage3.both.Interfaces.containers.ContainerModularArmor;
import Technomage3.both.Interfaces.containers.ContainerPowerCharger;
import Technomage3.both.Interfaces.containers.ContainerSpellcastingWand;
import Technomage3.both.Interfaces.guis.GUIAncientSpellTable;
import Technomage3.both.Interfaces.guis.GUIKeystone;
import Technomage3.both.Interfaces.guis.GUIMageForge;
import Technomage3.both.Interfaces.guis.GUIMagicPathway;
import Technomage3.both.Interfaces.guis.GUIModularArmor;
import Technomage3.both.Interfaces.guis.GuiItemNetworkAccess;
import Technomage3.both.Interfaces.guis.GuiItemPusher;
import Technomage3.both.Interfaces.guis.GuiItemTransferNetworkBase;
import Technomage3.both.Interfaces.guis.TN3GUIContainer;
import Technomage3.both.ItemTransfer.tileentities.TileEntityItemNetworkAccess;
import Technomage3.both.ItemTransfer.tileentities.TileEntityItemPusher;
import Technomage3.both.ItemTransfer.tileentities.TileEntityItemTransferNetworkBase;
import Technomage3.both.Items.ItemKeystone.KeyCode;
import Technomage3.both.Items.TMItems;
import Technomage3.both.Items.armor.ItemModularArmor;
import Technomage3.both.Spell.SpellcastingWand;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;

public class TMGUIHandeler implements IGuiHandler {

public TMGUIHandeler() {

	NetworkRegistry.instance().registerGuiHandler(TechnologicalMagic.instance, this);

}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {

	TileEntity tile = world.getBlockTileEntity(x, y, z);

	switch(ID) {

	case TMGuis.mageForgeGui:  // tile entity mage forge

		if(tile != null && tile instanceof TileEntityMageForge)
			return new ContainerMageForge(player.inventory, (TileEntityMageForge) tile);
		break;

	case TMGuis.modularArmorGui: // modular armor

		ItemStack stack = player.getHeldItem();

		if(stack.getItem() instanceof ItemModularArmor)
			return new ContainerModularArmor(player.inventory, (ItemModularArmor) stack.getItem());

	case TMGuis.powerChargerGui:

		if(tile != null && tile instanceof TileEntityPowerCharger)
			return new ContainerPowerCharger(player.inventory, (TileEntityPowerCharger) tile);


	case TMGuis.spellcastingWandGui:
		ItemStack stack2 = player.getHeldItem();

		if(stack2.getItem() instanceof SpellcastingWand)
			return new ContainerSpellcastingWand(player.inventory, (SpellcastingWand) stack2.getItem());

	case TMGuis.ancientSpellTableGui:
		if(tile != null && tile instanceof TileEntityAncientSpellTable)
			return new ContainerAncientSpellTable(player.inventory, (TileEntityAncientSpellTable) tile);

	case TMGuis.magicPathwayGuiNoKey:
		System.out.println(KeyCode.getHeldCode(player));
		if(tile != null && tile instanceof TileEntityMagicPathway)
			return new ContainerMagicPathwayBlocked(player.inventory, (TileEntityMagicPathway) tile);

	case TMGuis.keystoneGui:
		ItemStack stack1 = player.getHeldItem();

		if(stack1.itemID == TMItems.keyStone.itemID)
			return new ContainerKeystone(stack1, player.inventory);

	case TMGuis.magicPathwayGuiKey:
		System.out.println(KeyCode.getHeldCode(player));
		if(tile != null && tile instanceof TileEntityMagicPathway)
			return new ContainerMagicPathwayOpen(player.inventory, (TileEntityMagicPathway) tile);

	case TMGuis.itemTransferNetworkBaseGui:
		if(tile != null && tile instanceof TileEntityItemTransferNetworkBase)
			return new ContainerItemTransferNetworkBase((TileEntityItemTransferNetworkBase) tile, player);

	case TMGuis.itemTransferNetworkPusherGui:
		if(tile != null && tile instanceof TileEntityItemPusher)
			return new ContainerItemPusher((TileEntityItemPusher) tile, player);

	case TMGuis.itemTransferNetworkAccessGui:
		if(tile != null && tile instanceof TileEntityItemNetworkAccess)
			return new ContainerItemNetworkAccess((TileEntityItemNetworkAccess) tile, player);



	case TMGuis.blockPlacer:
		ItemStack stack3 = player.getHeldItem();

		if(stack3.itemID == TMItems.blockPlacer.itemID)
			return new ContainerBlockPlacer(player.inventory, (ItemBlockPlacer) stack3.getItem());





	}

	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {

	TileEntity tile = world.getBlockTileEntity(x, y, z);

	switch(ID) {

	case TMGuis.mageForgeGui:

		if(tile != null && tile instanceof TileEntityMageForge)
			return new GUIMageForge(player.inventory, (TileEntityMageForge) tile);
		break;

	case TMGuis.modularArmorGui: // modular armor

		ItemStack stack = player.getHeldItem();

		if(stack.getItem() instanceof ItemModularArmor)
			return new GUIModularArmor(player.inventory, stack);

	case TMGuis.powerChargerGui:

		if(tile != null && tile instanceof TileEntityPowerCharger)
			return new TN3GUIContainer(player.inventory, 
					new ContainerPowerCharger(player.inventory, (TileEntityPowerCharger) tile),
					"powerCharger",
					176, 130
					);

	case TMGuis.spellcastingWandGui:
		ItemStack stack2 = player.getHeldItem();

		if(stack2.getItem() instanceof SpellcastingWand)
			return new TN3GUIContainer(player.inventory, 
			new ContainerSpellcastingWand(player.inventory, (SpellcastingWand) stack2.getItem()), 
			"spellTalisman", 176, 189


					);

	case TMGuis.ancientSpellTableGui:
		if(tile != null && tile instanceof TileEntityAncientSpellTable)
			return new GUIAncientSpellTable(player.inventory, (TileEntityAncientSpellTable) tile);

	case TMGuis.magicPathwayGuiNoKey:
		if(tile != null && tile instanceof TileEntityMagicPathway)
			return new GUIMagicPathway(player.inventory, (TileEntityMagicPathway) tile, new ContainerMagicPathwayBlocked(player.inventory, (TileEntityMagicPathway) tile));

	case TMGuis.keystoneGui:
		ItemStack stack1 = player.getHeldItem();

		if(stack1.itemID == TMItems.keyStone.itemID)
			return new GUIKeystone(stack1, player.inventory);

	case TMGuis.magicPathwayGuiKey:
		if(tile != null && tile instanceof TileEntityMagicPathway)
			return new GUIMagicPathway(player.inventory, (TileEntityMagicPathway) tile, new ContainerMagicPathwayOpen(player.inventory, (TileEntityMagicPathway) tile));

	case TMGuis.itemTransferNetworkBaseGui:
		if(tile != null && tile instanceof TileEntityItemTransferNetworkBase)
			return new GuiItemTransferNetworkBase((TileEntityItemTransferNetworkBase) tile, player);

	case TMGuis.itemTransferNetworkPusherGui:
		if(tile != null && tile instanceof TileEntityItemPusher)
			return new GuiItemPusher((TileEntityItemPusher) tile, player);

	case TMGuis.itemTransferNetworkAccessGui:
		if(tile != null && tile instanceof TileEntityItemNetworkAccess)
			return new GuiItemNetworkAccess((TileEntityItemNetworkAccess) tile, player);

	case TMGuis.blockPlacer:
		ItemStack stack3 = player.getHeldItem();

		if(stack3.itemID == TMItems.blockPlacer.itemID)
			return new TN3GUIContainer(player.inventory, 
					new ContainerBlockPlacer(player.inventory, (ItemBlockPlacer) stack3.getItem()), 
					"blockPlacer", 176, 130);

	}

	return null;
}


}

 

 

 

Making inventories for Items is a little complicated, here is mine:

 

Item:

 

 

package Technomage3.both.Spell;

import java.util.ArrayList;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import Technomage3.Core.Items.TN3ItemTool;
import Technomage3.Core.Utils.StackUtil;
import Technomage3.Core.Utils.TN3Utils;
import Technomage3.both.TechnologicalMagic;
import Technomage3.both.Interfaces.TMGuis;
import Technomage3.both.Spell.talismans.SpellTargeter;

public class SpellcastingWand extends TN3ItemTool {

public SpellcastingWand(String realName, String unlocalizedName,
		CreativeTabs tab) {
	super(realName, unlocalizedName, tab);
}

public int getTargeter(ItemStack stack){
	NBTTagCompound nbt = StackUtil.getOrCreateNbtData(stack);
	return nbt.getInteger("Targeter");
}
public int getSpell(ItemStack stack){
	NBTTagCompound nbt = StackUtil.getOrCreateNbtData(stack);
	return nbt.getInteger("Spell");
}

public void setTargeter(ItemStack stack, int i){
	NBTTagCompound nbt = StackUtil.getOrCreateNbtData(stack);
	nbt.setInteger("Targeter", i);
}
public void setSpell(ItemStack stack, int i){
	NBTTagCompound nbt = StackUtil.getOrCreateNbtData(stack);
	nbt.setInteger("Spell", i);
}

public ItemStack[] getHeldItems(ItemStack stack){

	ItemStack[] inv = new ItemStack[16];

	NBTTagCompound nbt = StackUtil.getOrCreateNbtData(stack);

	for(int i = 0 ; i < inv.length ; i++){

		inv[i] = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("Stack" + i));

	}

	return inv;

}

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
    {
	ItemStack[] items = getHeldItems(stack);
	if(player.isSneaking()) {
		player.openGui(TechnologicalMagic.instance, TMGuis.spellcastingWandGui, world, (int) player.posX, (int) player.posY, (int) player.posZ);			
	} else if(items[getSpell(stack)] != null && items[getTargeter(stack)] != null){
		//Spell.cast(player, world, SpellUtils.getSpell(items[getSpell(stack)]), (SpellTargeter) items[getTargeter(stack)].getItem(), 1);

		TN3Utils.sendChat(player, "Targeter: " + getTargeter(stack) + ", Spell:" + getSpell(stack));

	}

        return stack;
    }

public void onCreated(ItemStack stack, World world, EntityPlayer player) {
	setSpell(stack, 0);
	setTargeter(stack, 0);
}

public void nextTargeter(ItemStack stack) {

	int target = getTargeter(stack);

	if(target == 7)
		target = 0;
	else
		target++;

	setTargeter(stack, target);


}

public void previousTargeter(ItemStack stack) {
	int target = getTargeter(stack);

	if(target == 0)
		target = 7;
	else
		target--;

	setTargeter(stack, target);

}

public void nextSpell(ItemStack stack) {

	int target = getSpell(stack);

	if(target == 7)
		target = 0;
	else
		target++;

	setSpell(stack, target);


}

public void previousSpell(ItemStack stack) {
	int target = getSpell(stack);

	if(target == 0)
		target = 7;
	else
		target--;

	setSpell(stack, target);

}

}

 

 

 

Container:

 

 

package Technomage3.both.Interfaces.containers;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import Technomage3.Core.Utils.StackUtil;
import Technomage3.both.Interfaces.GUIUtils;
import Technomage3.both.Interfaces.TN3Container;
import Technomage3.both.Interfaces.inventories.InventorySpellcastingWand;
import Technomage3.both.Interfaces.slots.SlotSubclassOfItem;
import Technomage3.both.Spell.ItemSpell;
import Technomage3.both.Spell.SpellcastingWand;
import Technomage3.both.Spell.talismans.SpellTargeter;

public class ContainerSpellcastingWand extends TN3Container {

private World world;
public InventorySpellcastingWand input;
ItemStack stack = null;
EntityPlayer player = null;
private int blockSlot;
private SpellcastingWand item;

public ContainerSpellcastingWand(InventoryPlayer iinventory, SpellcastingWand armor)
{
	this.player = iinventory.player;
	this.world = player.worldObj;
	this.stack = iinventory.getCurrentItem();
	this.blockSlot = iinventory.currentItem + 28;
	item = armor;

	input = new InventorySpellcastingWand(item, this);

	GUIUtils.addPlayerSlots(this, 8, 107, iinventory);

	for(int x = 0 ; x < 2 ; x++){
		for(int y = 0 ; y < 4 ; y++){
			this.addSlotToContainer(new SlotSubclassOfItem(input, 4*x + y, 32 + 18 * x, 16 + 18 * y, SpellTargeter.class));
		}
	}

	for(int x = 0 ; x < 2 ; x++){
		for(int y = 0 ; y < 4 ; y++){
			this.addSlotToContainer(new SlotSubclassOfItem(input, 4*x + y + 8, 99 + 18 * x, 16 + 18 * y, ItemSpell.class));
		}
	}

	if (!world.isRemote)
	{

		ItemStack[] stacks = item.getHeldItems(stack);

		for(int i = 0 ; i < stacks.length ; i++)
			this.input.setInventorySlotContents(i, stacks[i]);



	}

	this.onCraftMatrixChanged(this.input);
}

@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
	return input.isUseableByPlayer(entityplayer);

}

public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
	if (!this.world.isRemote)
	{

		for(int i = 0 ; i < input.getSizeInventory() ; i++){

			ItemStack var3 = this.input.getStackInSlotOnClosing(i);

			if (var3 != null)
			{
				NBTTagCompound var4 = new NBTTagCompound();
				var3.writeToNBT(var4);
				StackUtil.getOrCreateNbtData(stack).setCompoundTag("Stack" + i, var4);
			}
			else
			{
				StackUtil.getOrCreateNbtData(stack).setCompoundTag("Stack" + i, new NBTTagCompound());
			}

			if (this.player == null)
			{
				return;
			}

			if (this.player.getHeldItem() != null && this.player.getHeldItem().isItemEqual(this.stack))
			{
				this.player.setCurrentItemOrArmor(0, this.stack);
			}

			this.player.inventory.onInventoryChanged();
		}
	}


}

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int i){
	return null;
}


}

 

 

 

Inventory:

 

 

package Technomage3.both.Interfaces.inventories;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import Technomage3.both.Spell.ItemSpell;
import Technomage3.both.Spell.SpellcastingWand;
import Technomage3.both.Spell.talismans.SpellTargeter;

public class InventorySpellcastingWand implements IInventory {

public ItemStack[] inv;
private Container container;
private SpellcastingWand item;

public InventorySpellcastingWand(SpellcastingWand item, Container cont){

	this.item = item;
	container = cont;

	inv = new ItemStack[16];

}

@Override
public int getSizeInventory() {
	return 16;
}

@Override
public ItemStack getStackInSlot(int i) {

	return inv[i];
}

@Override
public ItemStack decrStackSize(int i, int j) {
	if (this.inv[i] != null)
        {
            ItemStack var3;

            if (this.inv[i].stackSize <= j)
            {
                var3 = this.inv[i];
                this.inv[i] = null;
                this.container.onCraftMatrixChanged(this);
                return var3;
            }
            else
            {
                var3 = this.inv[i].splitStack(j);

                if (this.inv[i].stackSize == 0)
                {
                    this.inv[i] = null;
                }

                this.container.onCraftMatrixChanged(this);
                return var3;
            }
        }
        else
        {
            return null;
        }
}

@Override
public ItemStack getStackInSlotOnClosing(int i) {

	ItemStack s = getStackInSlot(i);

	setInventorySlotContents(i, null);

	return s;
}

@Override
public void setInventorySlotContents(int i, ItemStack stack) {

	inv[i] = stack;

	this.container.onCraftMatrixChanged(this);

}

@Override
public String getInvName() {
	return "Spell Talisman";
}

@Override
public boolean isInvNameLocalized() {
	return false;
}

@Override
public int getInventoryStackLimit() {
	return 1;
}

@Override
public void onInventoryChanged() {

}

@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
	return true;
}

@Override
public void openChest() {
	// TODO Auto-generated method stub

}

@Override
public void closeChest() {
	// TODO Auto-generated method stub

}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {

	if(itemstack == null)
		return true;

	return i < 8 ? itemstack.getItem() instanceof SpellTargeter : itemstack.getItem() instanceof ItemSpell;

}



}

 

 

 

Hope it helps.  There is a lot of extra stuff.  I dont't think you need to creat a seprate inventory, but it's a good idea.

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

    • Tayo4D : Bandar Online Togel Dan Slot Terbesar Di Indonesia     Pemain taruhan Tayo4D yang berkualitas memerlukan platform yang aman, terpercaya, dan mudah digunakan. Dalam era teknologi ini, banyak situs online yang menawarkan layanan taruhan togel 4D, tetapi memilih yang tepat menjadi tuntas. Berikut adalah cara untuk membuat artikel yang membahas tentang situs online terpercaya untuk permainan taruhan togel 4D.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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