Un GUI basique
-
#Classe principale(Classe principale)
Dans la déclarationpublic static Main INSTANCE;Dans le onInit
KeyBindingRegistry.registerKeyBinding(new TutoKeyBind());#Crée ta classe qui gère les touches (Crée ta classe qui gère les touches )
public class TutoKeyBind extends KeyHandler { public static KeyBinding tutoKey = new KeyBinding("key.button.tutoKey", Keyboard.KEY_P); public FicheKeyBind() { super(new KeyBinding[] {tutoKey}, new boolean[] {false}); } @Override public String getLabel() { return "Key Tutorial"; } @Override public void keyDown(EnumSet <ticktype>types, KeyBinding kb, boolean tickEnd, boolean isRepeat) { } @Override public void keyUp(EnumSet <ticktype>types, KeyBinding kb, boolean tickEnd) { EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer; Minecraft mc = Minecraft.getMinecraft(); if(kb.keyCode == tutoKey.keyCode && mc.currentScreen == null) // Tu vérifie qu'il à appuyer sur la touche et qu'il a pas d'autre gui d'ouvert. { player.openGui(Main.INSTANCE,TutorielGuiHandler.tutoGuiHandler,player.worldObj,(int) player.posX,(int) player.posY,(int) player.posZ); } } @Override public EnumSet <ticktype>ticks() { return EnumSet.allOf(TickType.class); } }#Ton GuiHandler(Ton GuiHandler)
Attention un seul HuiGandler par mod.public class TutorielGuiHandler implements IGuiHandler{ public static final int tutoGuiHandler = 1; private EntityLiving entityL; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch(ID){ case 1: return new ContainerTuto(); default : return null; } } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch(ID){ case 1: return new GuiTuto(); default : return null; } } } ```</ticktype></ticktype></ticktype> -
Voila, et les classes ContainerTuto et GuiTuto maintenant ? Je mets quoi dedans ?
-
Regarde le code du livre. Pour le bouton, il faudra faire que lorsque tu clic, ça ouvre un autre gui au joueur (l’id 2 ducoup).
-
Dans la console, il m’affiche
2014-02-18 17:57:44 [Avertissement] [ForgeModLoader] A mod tried to open a gui on the server without being a NetworkMod 2014-02-18 17:57:44 [Avertissement] [ForgeModLoader] A mod tried to open a gui on the server without being a NetworkMod 2014-02-18 17:57:45 [Avertissement] [ForgeModLoader] A mod tried to open a gui on the server without being a NetworkMod 2014-02-18 17:57:45 [Avertissement] [ForgeModLoader] A mod tried to open a gui on the server without being a NetworkModDès que j’appuie sur P ?
-
@NetworkMod(clientSideRequired = true, serverSideRequired = false) à mettre dans la classe principale en dessus de @Mod.
-
Il y est déjà
-
Ton gui handler est enregistré dans ta classe principale ?
NetworkRegistry.instance().registerGuiHandler(new TonGuiHandler()); (ou quelque chose comme ça, je ne connais pas par cœur la méthode) -
Toujours aucun changements.
-
Tu as le
@Instance(“modid”)
public NomDelaClasse instance; dans ta classe principale ? -
ça ?
@Mod(modid = "MGS", name = "Metal gear cubid", version = "1.1.0") -
Non, envoie toute ta classe principale (sur un paste bin si elle est longue).
-
-
NetworkRegistry.instance().registerGuiHandler(new GuiHandler(), null);
Remplace null par this.INSTANCEEt remplace :
public static Main INSTANCE;
par :
@Instance(“MGS”)
public static Main INSTANCE; -
Il me donne une erreur a @Instance(“MGS”) et a registerGuiHandler :
The method registerGuiHandler(Object, IGuiHandler) in the type NetworkRegistry is not applicable for the arguments (GuiHandler, Main) -
Pour le @Instance, importe cpw.mod.fml.common.Mod.Instance
Pour NetworkRegistry, inverse :
NetworkRegistry.instance().registerGuiHandler(this.INSTANCE, new GuiHandler()); -

CA MARCHE !
Plus qu’a faire les détails. Merci. -
j’ai un crash, voici les log: http://pastebin.com/20UhCpqY
-
Merci de créer une nouvelle discussion plutôt que de up les anciennes.
Tu as un problème avec tes proxy, mets le code de ta classe principale dans la nouvelle discussion.
Bonjour ! Vous semblez intéressé par cette conversation, mais vous n’avez pas encore de compte.
Marre de refaire défiler les mêmes messages ? Créez un compte pour retrouver votre position, recevoir des notifications des nouvelles réponses, sauvegarder vos favoris et voter pour les messages que vous appréciez.
Grâce à votre participation, ce message peut devenir encore meilleur 💗
S'inscrire Se connecter