Erreur - Serveur Forge à cause de commandes.
-
Tiens, je t’envoie toute la fonction :
@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")); ((EntityPlayer)sender).openGui(References.MOD_ID, 1, null, 0, 0, 0); System.out.println(Minecraft.getMinecraft().currentScreen); } -
Et du coup openGui est appelé ?
@Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 1){ return new GuiAfficheLois(); //Test si c'est exécuté } return null; } -
C’est à dire ? J’ai mis un print avant le return new GuiAfficheLois(); et il ne s’affiche pas.
Je penses donc que la fonction ne marche pas (j’ai aussi mis un print avec la condition et il ne s’affiche pas), l’erreur peut se trouver où ? dans le register du guihandler ?
-
Et openGui est bien appelé ? Essai de mettre les bon arguments quand tu appelle openGui (le monde, la position du joueur), je ne sais ps trop, est-ce que tu a des erreurs loggés dans la console (pas forcément un crash)
-
Ton getServerGuiElement, il retourne toujours null ? Si oui, getClientGuiElement ne sera jamais appelé, du coup repasse par la commande client mais avec toujours le GuiHandler, si ça marche toujours pas mets un print dans la fonction draw du gui.
Envoyé de mon RAINBOW LITE 4G en utilisant Tapatalk
-
Broken, j’ai mis les coordonnées du joueur et son monde où il est (en faisant des get) :
((EntityPlayer)sender).openGui(References.MOD_ID, 1, sender.getEntityWorld(), sender.getPlayerCoordinates().posX, sender.getPlayerCoordinates().posY, sender.getPlayerCoordinates().posZ);J’ai aucune erreur, et ça ne marche pas.
Aymeric, en effet, mon getServerGuiElement est toujours null car mon gui affiche juste une image avec du texte dessus et ne possède donc pas d’inventaire.
Je vais remettre les commands clients.
Ok, on avance
J’ai mis deux prints avant et après la condition de l’id qui ont marché (“TEST ID” ET “BON ID”)
J’ai mis un print dans initGUI (qui a marché) et dans drawScreen(qui n’a pas marché)Et le print qui est après le openGUI (qui donne le currentScreen) m’a donné mon gui.
DONC, le problème viens du drawScreen, mais j’en ai aucune idée d’où ça peut venir

Je vous montre le code :
@Override public void drawScreen(int x, int y, float ticks){ System.out.println("DRAW SCREEN"); 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); 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); }EDIT : si ça peut aider, je met aussi mon initGUI :
public void initGui(){ System.out.println("INIT GUI"); int guiX = (width - guiWidth) / 2; int guiY = (height - guiHeight) / 2; 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"); } }); } -
Ton gui est extends GuiScreen ?
-
@‘BrokenSwing’:
Ton gui est extends GuiScreen ?
Yep, il ne faut pas ?
-
Si, si, fait voir la classe au cas où
-
@‘BrokenSwing’:
Si, si, fait voir la classe au cas où
Tiens, voici la class du GUI
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(){ System.out.println("INIT GUI"); int guiX = (width - guiWidth) / 2; int guiY = (height - guiHeight) / 2; 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"); } }); } public void drawScreen(int x, int y, float ticks){ System.out.println("DRAW SCREEN"); 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); 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); } } -
Si tu ouvres directement le gui côté client avec un Minecraft.getMinecraft().displayGuiScreen ça fonctionne ?
Car si oui, il faudrait utiliser un paquet au lieu d’un gui handler. -
@‘robin4002’:
Si tu ouvres directement le gui côté client avec un Minecraft.getMinecraft().displayGuiScreen ça fonctionne ?
Car si oui, il faudrait utiliser un paquet au lieu d’un gui handler.ça marchait en mettant les commandes avec l’event FMLServerStarting
Mais comme la, j’ai remplaçait par des clients commands, ça ne marchait plus.Pour les paquets, je ne sais pas trop comment faire ^^
-
Il y a un tutoriel sur la chaine youtube & sur le forum pour les paquets.
-
@‘robin4002’:
Il y a un tutoriel sur la chaine youtube & sur le forum pour les paquets.
Ok, j’ai testé des trucs mais bon, je comprends pas trop : (au faite tu fais comment pour que le code java rend bien ? car a chaque fois ça le colle à droite sans les espaces :/)
public class PacketGuiLois implements IMessage{ private String text; public PacketGuiLois(){ } public PacketGuiLois(String text) { this.text = text; } @Override public void fromBytes(ByteBuf buf) { text = ByteBufUtils.readUTF8String(buf); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, text); } public static class Handler implements IMessageHandler<packetguilois, imessage="">{ public IMessage onMessage(PacketGuiLois message, MessageContext ctx) { Minecraft.getMinecraft().displayGuiScreen(new GuiAfficheLois()); return null; } } }Ma commande execute : InstantRP.network.sendTo(new PacketGuiLois(), (EntityPlayerMP) sender);
Et dans mon preLoad (Class principale) j’ai mis : network.registerMessage(PacketGuiLois.Handler.class, PacketGuiLois.class, 0, Side.CLIENT);
Maintenant, je ne sais pas comment modifier le packet pour que ça marche</packetguilois,>
-
A quoi te sert le text dans le paquet ? Enlève-le, normalement ça devrait marcher …
-
Retires juste “text”, tu n’en a pas besoin. (laisses les fonction fromBytes et toBytes vide).
-
Ok, j’ai enlevé le text et ça marche coté client.
Mais quand je lance coté serveur, ça me donne une erreur : Caused by: java.lang.ClassNotFoundException: net.minecraft.client.gui.GuiScreen
Le crash donne la ligne de l’erreur : network.registerMessage(PacketGuiLois.Handler.class, PacketGuiLois.class, 0, Side.CLIENT); (situé dans le preLoad)
-
Ajoutes :
@SideOnly(Side.CLIENT) au dessus de la fonction onMessage de la classe Handler qui se trouve dans la classe PacketGuiLois. -
ENFIN, tout marche bien

Merci à tous de votre aide.
-
N’oublie pas la balise résolu
