Jump to content

[1.6.4] Opening Enderchest Inventory Using An Item


FishTickler

Recommended Posts

I'm fairly new to modding but I have made a few that add items, blocks, world gen, crafting recipes etc, but this has me stumped, the item appears in game as it should etc but right-clicking with it does nothing, there isn't really much code to it, it's just supposed to open the enderchest inventory on right click, so I'm thinking I must be missing something simple!

 


package ender.stuff;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryEnderChest;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class EnderLink extends Item {
public EnderLink(int id)
    {
        super(id);
        maxStackSize = 1;
        setUnlocalizedName("EnderLink");
          }

   	public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
	InventoryEnderChest inventoryenderchest = par3EntityPlayer.getInventoryEnderChest();
	if (inventoryenderchest != null)
		par3EntityPlayer.displayGUIChest(inventoryenderchest);
        return par1ItemStack;
    }
}

 

If anyone can tell me where I am going wrong it would be much appreciated!

 

*Edited code based on suggestion from elsewhere but still not working :(

Link to comment
Share on other sites

Probably because that particular GUI is looking for a TileEntity that doesn't exist.

 

Might want to take a peek inside vanilla's GUI code and make sure.

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

GuiChest and ContainerChest themselves should be fine, since if I remember correctly they just work with a pair of IInventory instances. However the IInventory you are using there, InventoryEnderChest does depend on a tile entity, so guess the instance might not be valid where/how your using it.

Link to comment
Share on other sites

Two hours of digging through code and checking it over and guess what... there's absolutely nothing wrong with the code above, it works perfectly, I had a typo in the main class that was messing it up!

 

I'll leave it here for future reference in case anyone else wants to know how to open an enderchest inventory using an item :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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