Hello all,
A few days ago I started playing around with Forge, and I'm having fun with it for the most part, but I'm stuck on getting the gui buttons to upgrade my item.
What I want:
Rightclick an item -> open interface -> options/buttons to upgrade item in question -> actually upgrade the item [dmg/speed/etc.]
I've searched for a while and followed tutorials such as http://www.minecraftforge.net/wiki/Containers_and_GUIs
I know I'm supposed to do something with a Container in order to sync the client with the server but I'm not sure how.
I could really use a push in the right direction.
What I'm doing currently:
In my Pickaxe<Extends ItemTool>'s onItemRightClick I'm calling player.openGui()
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
if (world.isRemote) {//client
player.openGui(PassiveEnchanting.instance, PassiveEnchanting.GUI_ITEM_UPGRADE, world, (int) player.posX, (int) player.posY, (int) player.posZ);
}
return super.onItemRightClick(itemStack, world, player);
}
In my mod's preinit I've registered a gui handler which goes like
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiProxy());
}
The guiproxy creates the gui object for the client.
public class GuiProxy implements IGuiHandler {
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == PassiveEnchanting.GUI_ITEM_UPGRADE) {
return new ItemUpgradeGui(player);
}
return null;
}
}
I think the problem lies in the ItemUpgradeGui.actionPerformed method. At the moment I'm just sending the player's equiped itemstack to the Item class.
The complete project can be found at https://bitbucket.org/novaz/passive-enchants/src