Skip to content

Instantly share code, notes, and snippets.

@IamRob-
Created February 12, 2014 12:56
Show Gist options
  • Select an option

  • Save IamRob-/8955117 to your computer and use it in GitHub Desktop.

Select an option

Save IamRob-/8955117 to your computer and use it in GitHub Desktop.
//GUI Handler Class
public class GuiHandler implements IGuiHandler {
public GuiHandler() {
NetworkRegistry.instance().registerGuiHandler(MultiLink.instance, this);
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
System.out.println("Server Gui");
switch(ID) {
case 0:
ItemStack stack = player.getHeldItem();
Item item = stack.getItem();
if (item instanceof ItemLinkHolder) {
InventoryLinkHolder inv = new InventoryLinkHolder();
if (inv != null) {
System.out.println("Server returned");
return new ContainerLinkHolder(player.inventory, stack, inv);
}
}
break;
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
System.out.println("Client Gui");
switch(ID) {
case 0:
ItemStack stack = player.getHeldItem();
Item item = stack.getItem();
if (item instanceof ItemLinkHolder) {
InventoryLinkHolder inv = new InventoryLinkHolder();
if (inv != null) {
System.out.println("Client returned");
return new GuiLinkHolder(player.inventory, stack, inv);
}
}
break;
}
return null;
}
}
//When openGUI is called
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
if (player.isSneaking()) {
if (!world.isRemote) {
player.openGui(MultiLink.instance, 0, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
}
return itemstack;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment