Récupéré le nombre de joueurs sur un serveur
-
Sérieusement stop les balises code dans une balise spoiler. C’est complètement illisible car pas de formatage + code compacté sur 5 lignes …
Il suffit de juste mettre la balise java et voila.Et en effet comme ça ça ne risque pas de fonctionner, regardes bien dans ServerListEntryNormal il passe par un thread et il faut mettre le code dans une fonction appelé à chaque tick (comme par exemple drawScreen).
-
Bonjours, je vais me sentir nul et je pense que c’est vrais, mais sa me retourne toujours null. voic le code de drawnScreen :
public void drawScreen(int x, int y, float partialTick) { field_148302_b.submit(new Runnable() { public void run() { OldServerPinger o = new OldServerPinger(); try { o.func_147224_a(s); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); GL11.glDisable(GL11.GL_ALPHA_TEST); this.renderSkybox(x, y, partialTick); GL11.glEnable(GL11.GL_ALPHA_TEST); Tessellator tessellator = Tessellator.instance; short short1 = 274; int k = this.width / 2 - short1 / 2; byte b0 = 30; this.drawGradientRect(0, 0, this.width, this.height, -2130706433, 16777215); this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE); this.mc.getTextureManager().bindTexture(minecraftTitleTextures); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); if((double)this.updateCounter < 1.0E-4D) { this.drawTexturedModalRect(k + 0, b0 + 0, 0, 0, 99, 44); this.drawTexturedModalRect(k + 99, b0 + 0, 129, 0, 27, 44); this.drawTexturedModalRect(k + 99 + 26, b0 + 0, 126, 0, 3, 44); this.drawTexturedModalRect(k + 99 + 26 + 3, b0 + 0, 99, 0, 26, 44); this.drawTexturedModalRect(k + 155, b0 + 0, 0, 45, 155, 44); } else { this.drawTexturedModalRect(k + 0, b0 + 0, 0, 0, 155, 44); this.drawTexturedModalRect(k + 155, b0 + 0, 0, 45, 155, 44); } tessellator.setColorOpaque_I(-1); GL11.glPushMatrix(); GL11.glTranslatef((float)(this.width / 2 + 90), 70.0F, 0.0F); GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F); float f1 = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F); f1 = f1 * 100.0F / (float)(this.fontRendererObj.getStringWidth(this.splashText) + 32); GL11.glScalef(f1, f1, f1); this.drawCenteredString(this.fontRendererObj, this.splashText, 0, -8, -256); GL11.glPopMatrix(); String s = "Minecraft 1.7.10"; if(this.mc.isDemo()) { s = s + " Demo"; } List <string>brandings = Lists.reverse(FMLCommonHandler.instance().getBrandings(true)); for(int i = 0; i < brandings.size(); i++) { String brd = brandings.get(i); if(!Strings.isNullOrEmpty(brd)) { this.drawString(this.fontRendererObj, brd, 2, this.height - (10 + i * (this.fontRendererObj.FONT_HEIGHT + 1)), 16777215); } } String s1 = "Copyright Mojang AB. Do not distribute! Launcher by ph1823"; this.drawString(this.fontRendererObj, s1, this.width - this.fontRendererObj.getStringWidth(s1) - 2, this.height - 10, -1); if(this.field_92025_p != null && this.field_92025_p.length() > 0) { drawRect(this.field_92022_t - 2, this.field_92021_u - 2, this.field_92020_v + 2, this.field_92019_w - 1, 1428160512); this.drawString(this.fontRendererObj, this.field_92025_p, this.field_92022_t, this.field_92021_u, -1); this.drawString(this.fontRendererObj, this.field_146972_A, (this.width - this.field_92024_r) / 2, ((GuiButton)this.buttonList.get(0)).yPosition - 12, -1); } super.drawScreen(x, y, partialTick); }La variable field_148302_b correspond a celle de ServerListEntryNormal.</string>
-
Tu affiches où la population du serveur ?
-
Au moement ou je crée le boutons, ici :
private void addSingleplayerMultiplayerButtons(int x, int y)et voici la fonction pour ajouté le bouton :
this.buttonList.add(new GuiButton(33, this.width / 2 - 100, i, 200, 20, "GloryCraft (" + s.populationInfo + "/25)" /* EnumChatFormatting.AQUA +"F" + EnumChatFormatting.BLACK + "r" + EnumChatFormatting.BLUE + "e" + EnumChatFormatting.BOLD + "n" + EnumChatFormatting.DARK_AQUA + "c" + EnumChatFormatting.DARK_BLUE + "h" + EnumChatFormatting.DARK_GRAY + "Altis"*/)); -
Normal que ça ne fonctionne pas alors.
Car s.populationInfo ne prend que sa valeur une fois la réponse au paquet reçu.Donc il faut utiliser dans une fonction actualité à chaque tick. Le mieux dans ton cas serait de mettre le code directement dans la fonction drawScreen du bouton.
-
Oui, mais la je viens de tentée casiment toutes les fonction, vue que celle qui draw le bouton ne marché pas et se ne marche toujours pas… Je ne sais pas d’ou viens le problème…
-
Envoies moi un zip de ton dossier src je vais regarder de mon côté.
-
Voici le fichier ZIP : http://www.fichier-zip.com/2015/12/28/src/
-
Bon le résultat n’est pas vraiment concluant. J’ai tenté deux choses même résultat :
obligé de refresh le menu (ouvrir une menu et revenir) pour voir le nombre de joueur. Je ne sais pas pourquoi
-
Hello, je me permet de faire un petit up pour vous dire que ceci pourrez vous aidé : https://github.com/evilmidget38/MinecraftServerPing