Erreur - Serveur Forge à cause de commandes.
-
@‘BrokenSwing’:
Montre le code de ta commande qui ouvre le gui
Voici le code : (qui marche en solo)
public class CommandLois implements ICommand { @Override public String getCommandName(){ return "lois"; } @Override public String getCommandUsage(ICommandSender sender) { return "Faites /lois"; } @Override public List getCommandAliases() { return null; } @Override public void processCommand(ICommandSender sender, String[] arguments){ sender.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GRAY+"["+EnumChatFormatting.DARK_GREEN+"InstantRP"+EnumChatFormatting.GRAY+"] "+EnumChatFormatting.YELLOW+"Ouverture du tableau des lois")); Minecraft.getMinecraft().displayGuiScreen(new GuiAfficheLois()); } @Override public int compareTo(Object arg0) { // TODO Auto-generated method stub return 0; } @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { return true; } @Override public List addTabCompletionOptions(ICommandSender sender,String[] p_71516_2_) { return null; } @Override public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { return false; } } -
Dans processCommand tu utilise
Minecraft.getMinecraft().displayGuiScreen(new GuiAfficheLois());Or ce code est exécuté côté serveur, il faut que tu vérifie si la personne aillant fait la commande est un joueur, et dans ce cas utiliser ton GuiHandler pour ouvrir un Gui (ou alors avec un paquet mais avec le gui handler ça devrait le faire)
public void processCommand(ICommandSender sender, String[] args) throws CommandException { if(sender instanceof EntityPlayer) { sender.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GRAY+"["+EnumChatFormatting.DARK_GREEN+"InstantRP"+EnumChatFormatting.GRAY+"] "+EnumChatFormatting.YELLOW+"Ouverture du tableau des lois")); ((EntityPlayer)sender).openGui(ClassePrincipale.MODID, 0, null, 0, 0, 0); //Le premier 0 doit correspondre à l'id de ton gui que tu récupérera pour ouvrir le bon gui via le gui handler } } -
@‘BrokenSwing’:
Dans processCommand tu utilise
Minecraft.getMinecraft().displayGuiScreen(new GuiAfficheLois());Or ce code est exécuté côté serveur, il faut que tu vérifie si la personne aillant fait la commande est un joueur, et dans ce cas utiliser ton GuiHandler pour ouvrir un Gui (ou alors avec un paquet mais avec le gui handler ça devrait le faire)
public void processCommand(ICommandSender sender, String[] args) throws CommandException { if(sender instanceof EntityPlayer) { sender.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GRAY+"["+EnumChatFormatting.DARK_GREEN+"InstantRP"+EnumChatFormatting.GRAY+"] "+EnumChatFormatting.YELLOW+"Ouverture du tableau des lois")); ((EntityPlayer)sender).openGui(ClassePrincipale.MODID, 0, null, 0, 0, 0); //Le premier 0 doit correspondre à l'id de ton gui que tu récupérera pour ouvrir le bon gui via le gui handler } }Ok, merci de ta réponse, mais je récupère comment l’id de mon gui ?
-
Tu mets celui que tu veux, du moment qu’il correspond à celui dans le GuiHandler.
Tu aurais aussi pu faire une commande interprétée côté client. -
@‘AymericRed’:
Tu mets celui que tu veux, du moment qu’il correspond à celui dans le GuiHandler.
Tu aurais aussi pu faire une commande interprétée côté client.Ok, bon, j’ai essayé un truc :
@Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return 1000; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return 1000; }Puis dans la commande, j’ai mis ça :
((EntityPlayer)sender).openGui(References.MOD_ID, 1000, null, 0, 0, 0);Mais j’ai une erreur : java.lang.Integer cannot be cast to net.minecraft.inventory.Container
Je sais pas trop comment marche les GuiHandler ^^
Et pour les commandes coté clients, si ça serais plus simple, je veux bien savoir comme faire.
-
Pour le GuiHandler, il faut que, dans getServerGuiElement tu retournes un Container et dans getClientGuiElement, il faut que tu fasses un if(ID == 1000) dans les deux fonctions et après tu retourne le gui ou le container selon la fonction (si ton Gui n’a pas d’inventaire et n’extends pas GuiContainer, tu peux mettre return null pour le Container).
Pour les commandes client, je trouve que ça serait plus propre, je regarde comment j’avais fait dans mon mod.
EDIT : ```java
ClientCommandHandler.instance.registerCommand(new CommandClient()); -
@‘AymericRed’:
Pour le GuiHandler, il faut que, dans getServerGuiElement tu retournes un Container et dans getClientGuiElement, il faut que tu fasses un if(ID == 1000) dans les deux fonctions et après tu retourne le gui ou le container selon la fonction (si ton Gui n’a pas d’inventaire et n’extends pas GuiContainer, tu peux mettre return null pour le Container).
Pour les commandes client, je trouve que ça serait plus propre, je regarde comment j’avais fait dans mon mod.EDIT : ```java
ClientCommandHandler.instance.registerCommand(new CommandClient());J’ai mis ça, et j’ai remis mon code comme avant mais mon gui ne s’ouvre pas

La commande fonctionne car j’ai le message.
Je re montre ma commande:@Override public void processCommand(ICommandSender sender, String[] arguments){ sender.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GRAY+"["+EnumChatFormatting.DARK_GREEN+"InstantRP"+EnumChatFormatting.GRAY+"] "+EnumChatFormatting.YELLOW+"Ouverture du tableau des lois")); Minecraft.getMinecraft().displayGuiScreen(new GuiAfficheLois()); } -
Bizarre mets des prints dans le constructeur de ton gui et la foncion init du gui, ou montres-le.
-
@‘AymericRed’:
Bizarre mets des prints dans le constructeur de ton gui et la foncion init du gui, ou montres-le.
J’ai tester des prints, mais bon toujours riens :
@SideOnly(Side.CLIENT) public class GuiAfficheLois extends GuiScreen { int guiWidth = 515/2; int guiHeight = 500/2; public static String loi1 = "Aucune."; public static String loi2 = "Aucune."; public static String loi3 = "Aucune."; public static String loi4 = "Aucune."; public static String loi5 = "Aucune."; public static String loi6 = "Aucune."; public static String loi7 = "Aucune."; public static String loi8 = "Aucune."; public static String loi9 = "Aucune."; public static String loi10 = "Aucune."; public static String loi11 = "Aucune."; public static String loi12 = "Aucune."; public static String loi13 = "Aucune."; public static String loi14 = "Aucune."; public boolean doesGuiPauseGame() { return false; } public void initGui(){ } @Override public void drawScreen(int x, int y, float ticks){ int guiX = (width - guiWidth) / 2; int guiY = (height - guiHeight) / 2; GL11.glColor4f(1, 1, 1, 1); drawDefaultBackground(); mc.renderEngine.bindTexture(new ResourceLocation(References.MOD_ID, "textures/gui/backgroundlois.png")); drawTexturedModalRect(guiX, guiY, 0, 0, guiWidth, guiHeight); fontRendererObj.drawString(EnumChatFormatting.UNDERLINE+"Tableau des lois", guiX+85, guiY+11, 0x00000); this.buttonList.add(new GuiButton(30, guiX+200, guiY+5, 40, 20, "Edit"){ @Override public void mouseReleased(int x, int y) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/setlois"); } }); fontRendererObj.drawString(EnumChatFormatting.WHITE+"1\. "+loi1, guiX+10, guiY+35, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"2\. "+loi2, guiX+10, guiY+50, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"3\. "+loi3, guiX+10, guiY+65, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"4\. "+loi4, guiX+10, guiY+80, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"5\. "+loi5, guiX+10, guiY+95, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"6\. "+loi6, guiX+10, guiY+110, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"7\. "+loi7, guiX+10, guiY+125, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"8\. "+loi8, guiX+10, guiY+140, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"9\. "+loi9, guiX+10, guiY+155, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"10\. "+loi10, guiX+10, guiY+170, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"11\. "+loi11, guiX+10, guiY+185, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"12\. "+loi12, guiX+10, guiY+200, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"13\. "+loi13, guiX+10, guiY+215, 0x00000); fontRendererObj.drawString(EnumChatFormatting.WHITE+"14\. "+loi14, guiX+10, guiY+230, 0x00000); super.drawScreen(x, y, ticks); } /*@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 == 1){ this.drawScreen(0,0,0); } return null; }*/ } -
Fais voir comment tu enregistre la commande depuis la classe principale
-
@‘BrokenSwing’:
Fais voir comment tu enregistre la commande depuis la classe principale
Je l’enregistre dans l’event PreLoad
@EventHandler public void PreLoad(FMLPreInitializationEvent event){ proxy.registerRenderInfo(); MCreativeTab.initializeTabs(); BlockList.mainRegistry(); ItemsList.mainRegistry(); }Et tiens la fonction registerRenderInfo(le nom est confus mais je met tout dedans ^^) :
public void registerRenderInfo(){ MinecraftForge.EVENT_BUS.register(new GuiInGame()); MinecraftForge.EVENT_BUS.register(new GuiMenuPrincipal()); MinecraftForge.EVENT_BUS.register(new GuiDebugMenu()); FMLCommonHandler.instance().bus().register(new KeyInput()); KeyBindings.mainRegistry(); ClientCommandHandler.instance.registerCommand(new CommandLois()); ClientCommandHandler.instance.registerCommand(new CommandEditLois()); }EDIT : Après, la commande marche, car j’ai un message qui apparait ^^
-
Fais un print de Minecraft.getMinecraft().currentScreen dans ta commande après avoir ouvert le gui.
-
@‘AymericRed’:
Fais un print de Minecraft.getMinecraft().currentScreen dans ta commande après avoir ouvert le gui.
J’ai ça : fr.rremis.instantrp.gui.GuiAfficheLois@feab02
mais c’est bizarre que rien s’affiche, surtout que ça marchait très bien avant ^^
-
Selon moi du ClientCommonHandler n’a rien à faire dans une classe uniquement appelée côté serveur tel que le CommonProxy, comme le laisserait suggérer cet apel proxy.registerRenderInfo ().
Déplace ce code dans ton ClientProxy ou alors dans ta méthode preLoad, dans une conditon du genre if (event.getSide == Side.CLIENT) -
@‘Plaigon’:
Selon moi du ClientCommonHandler n’a rien à faire dans une classe uniquement appelée côté serveur tel que le CommonProxy, comme le laisserait suggérer cet apel proxy.registerRenderInfo ().
Déplace ce code dans ton ClientProxy ou alors dans ta méthode preLoad, dans une conditon du genre if (event.getSide == Side.CLIENT)Je l’ai mis dans le preLoad avec la condition mais rien ne change (bien sur, le message apparait toujours). Mais de base, il etait dans le clientProxy ^^
public class ClientProxy extends ServerProxy{ public void registerRenderInfo(){ MinecraftForge.EVENT_BUS.register(new GuiInGame()); MinecraftForge.EVENT_BUS.register(new GuiMenuPrincipal()); MinecraftForge.EVENT_BUS.register(new GuiDebugMenu()); FMLCommonHandler.instance().bus().register(new KeyInput()); KeyBindings.mainRegistry(); ClientCommandHandler.instance.registerCommand(new CommandLois()); ClientCommandHandler.instance.registerCommand(new CommandEditLois()); } } -
Bizarre, car selon mc ton gui est affiché, est-ce que après l’avoir ouvert, tu peux de déplacer ?
-
@‘AymericRed’:
Bizarre, car selon mc ton gui est affiché, est-ce que après l’avoir ouvert, tu peux de déplacer ?
Oui ^^
Je vois plus trop d’où viens le problème
-
C’est bizarre, essayes d’utiliser le GuiHandler sinon… Et par contre ceci ```java
this.buttonList.add(new GuiButton(30, guiX+200, guiY+5, 40, 20, “Edit”){
@Override
public void mouseReleased(int x, int y) {
Minecraft.getMinecraft().thePlayer.sendChatMessage(“/setlois”);
}
}); -
@‘AymericRed’:
C’est bizarre, essayes d’utiliser le GuiHandler sinon… Et par contre ceci ```java
this.buttonList.add(new GuiButton(30, guiX+200, guiY+5, 40, 20, “Edit”){
@Override
public void mouseReleased(int x, int y) {
Minecraft.getMinecraft().thePlayer.sendChatMessage(“/setlois”);
}
});Toujours rien

J’essaye le GuiHandler, j’ai remis dans la class du Gui :
@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 == 1){ } return null; }Mais je ne sais pas comment faire pour lancer le gui. (après la condition, je fais quoi ? ^^)
Apres, dans la class Server Proxy, j’ai :public void registerNetworkStuff(){ NetworkRegistry.INSTANCE.registerGuiHandler(References.MOD_ID, new GuiAfficheLois()); }Et j’ai rajouté “proxy.registerNetworkStuff();” dans la fonction PreLoad (dans la classe principale)
J’ai enlever les ClientCommandHandler du ClientProxy et j’ai remis l’event :
@EventHandler public void serverLoad(FMLServerStartingEvent event){ event.registerServerCommand(new CommandLois()); event.registerServerCommand(new CommandEditLois()); }Après test, le texte s’affiche mais comme je ne sais pas quoi mettre apres la condition (id == 1), cela ne marche pas
EDIT : Il faut mettre return new GuiAfficheLois();, non ?
-
Oui voilà dans la condition il faut mettre le return, et il faut bien que l’id que tu as mis dans openGui soit le même que l’id utilisé pour la condition