Problème de GUI
-
Finalement ton container est bon x) (on tourne en rond)
Ce qui est étrange, c’est que le openContainer du joueur est le ContainerPlayer à la place du container de ton bloc, d’où le crash.
Pourtant le gui handler est ok, je peux alors le code de ton bloc ? -
@‘robin4002’:
Finalement ton container est bon x) (on tourne en rond)
^^ c’est à n’y rien comprendre…
@‘robin4002’:Pourtant le gui handler est ok, je peux alors le code de ton bloc ?
Non c’est interdit !

import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.FMLNetworkHandler; public class SoundBlock extends BlockContainer{ public SoundBlock(int par1, Material par2Material) { super(par1, par2Material); } @Override public TileEntity createNewTileEntity(World world) { return new TileEntitySoundBlock(); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ FMLNetworkHandler.openGui(player, WirestoneMod.instance, 0, world, x, y, z); return true; } @Override//TODO Verifier méthode public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack){} }Pour t’encourager, je te plussoie !

-
Le container est bien ouvert en side serveur.
Je comprends pas.
On va faire plus simple, on va contourner le problème.
Dans ton gui, dans le code qui envoie le paquet remplace :dataoutputstream.writeBoolean(loopCheckBox.isSelected()); dataoutputstream.writeString((String)soundChooser.getSelectedItem()); dataoutputstream.writeInt((int)delayChooser.getValue()); dataoutputstream.writeFloat((float)volumeChooser.getValue()/100));par :
dataoutputstream.writeInt(tileEntity.coordX); dataoutputstream.writeInt(tileEntity.coordY); dataoutputstream.writeInt(tileEntity.coordZ); dataoutputstream.writeBoolean(loopCheckBox.isSelected()); dataoutputstream.writeString((String)soundChooser.getSelectedItem()); dataoutputstream.writeInt((int)delayChooser.getValue()); dataoutputstream.writeFloat((float)volumeChooser.getValue()/100));Et dans ton paquet handler :
boolean isLoop = data.readBoolean(); String sound = data.readString(); int delay = data.readInt(); float volume = data.readFloat(); ContainerSoundBlock container = (ContainerSoundBlock)player.openContainer; TileEntitySoundBlock tileSoundBlock = container.getSoundBlockTile(); tileSoundBlock.setIsLoop(isLoop); tileSoundBlock.setSound(sound); tileSoundBlock.setDelay(delay); tileSoundBlock.setVolume(volume); player.worldObj.markBlockForUpdate(tileSoundBlock.xCoord, tileSoundBlock.yCoord, tileSoundBlock.zCoord);devient
int x = data.readInt(); int y = data.readInt(); int z = data.readInt(); boolean isLoop = data.readBoolean(); String sound = data.readString(); int delay = data.readInt(); float volume = data.readFloat(); TileEntitySoundBlock tileSoundBlock = (TileEntitySoundBlock)player.worldObj.getBlockTileEntity(x, y, z); tileSoundBlock.setIsLoop(isLoop); tileSoundBlock.setSound(sound); tileSoundBlock.setDelay(delay); tileSoundBlock.setVolume(volume); player.worldObj.markBlockForUpdate(tileSoundBlock.xCoord, tileSoundBlock.yCoord, tileSoundBlock.zCoord); -
J’ai plus d’erreur mais c’est encore pire car lorsque je rouvre mon GUI, les valeurs reviennent aux valeurs par défaut.
-
Il y a des erreurs dans les logs ? Les valeurs valeurs se remette à 0 lors de l’ouverture du gui, ou elles prennent pas la bonne valeur quand tu ferme le gui ?
À mon avis c’est le fait de passé par une gui java qui cause problème.
-
@‘robin4002’:
Il y a des erreurs dans les logs ? Les valeurs valeurs se remette à 0 lors de l’ouverture du gui, ou elles prennent pas la bonne valeur quand tu ferme le gui ?
À mon avis c’est le fait de passé par une gui java qui cause problème.
Tout est OK pourtant. Bon je vais coder le GUI avec Minecraft. Seulement, je sais vraiment pas comment faire, les exemples ne m’aident pas trop… Je continue à poster ici si je rencontre des problèmes si ça te dérange pas ^^.___
Bon j’ai déjà un GUI vide (arrangé sous paint.NET).
https://www.dropbox.com/s/9t9uvdakxvx86tq/soundBlockGUI.png___Par contre mes boutons changent de position en permanence quand je redimensionne la fenêtre… Comment je peux les rendre fixe ? -
int x = (width) / 2; int y = (height - ySize) / 2;Ensuite tu init tes boutons en fonction de ces deux variables.
https://github.com/FFMT/nanotech_mod/blob/master/common/fr/mcnanotech/kevin_68/nanotech_mod/main/client/gui/GuiJumper.java#L38-L40 -
En fonction de coordonnées absolues donc, le milieu de l’écran ! Merci !!
D’autre part, il y aurait-t-il moyen d’avoir un texte dynamique ? Ou il faut que je crée mon propre composant pour qu’il se redessine à chaque fois ?
-
draw ton texte dans la fonction updateGui non ? (ou un truc comme ça, je ne connais pas par cœur le nom exacte).
-
Problème résolu ! J’ai juste placé mon texte dans le “drawGuiContainerForegroundLayer” ne sachant pas qu’il se mettait à jour régulièrement, donc en employant la variable “volume”, le texte se mettait à jour tout seul

-
Excuses moi Robin mais… j’ai encore une erreur, cette fois c’est avec le readUTF(). Rien a changé depuis la dernière classe (en théorie).
J’en profite pour inaugurer mon crashReporter ^^ : Crash report
Il s’agit d’une EOFException.
Code d’écriture des packets :for(int i = 1; i<=5; i++){ ByteArrayOutputStream bos = null; DataOutputStream dos = null; try{ bos = new ByteArrayOutputStream(); dos = new DataOutputStream(bos); Packet.writeString(this.sound,dos); dos.writeFloat((float)this.volume/100); dos.writeInt(this.delay); dos.writeInt(this.range); this.mc.getNetHandler().addToSendQueue(new Packet250CustomPayload("wsmod|soundBlock",bos.toByteArray())); break; }catch(Exception e){ this.logger.warning("Erreur lors de l'envoi du packet de données du SoundBlock (essai " + i + "/5)"); try{ dos.flush(); dos.close(); bos.close(); }catch(Exception e1){} } }Code de lecture des packets :
try{ DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data)); int x = data.readInt(); int y = data.readInt(); int z = data.readInt(); String sound = packet.readString(data,200); int delay = data.readInt(); float volume = data.readFloat(); int range = data.readInt(); TileEntitySoundBlock tileSoundBlock = (TileEntitySoundBlock)player.worldObj.getBlockTileEntity(x, y, z); tileSoundBlock.setRange(range); tileSoundBlock.setSound(sound); tileSoundBlock.setDelay(delay); tileSoundBlock.setVolume(volume); player.worldObj.markBlockForUpdate(tileSoundBlock.xCoord, tileSoundBlock.yCoord, tileSoundBlock.zCoord); }catch(Exception e){ new ErrorReport(e,Level.SEVERE,true); } -
Envoie le “vrai” crash log si possible

-
@‘Gugu42’:
Envoie le “vrai” crash log si possible

^^ C’est exactement le même. Je le met quand même :
Une erreur est survenue : 'null', null 2014-01-24 21:11:05 [Infos] [STDERR] java.io.EOFException 2014-01-24 21:11:05 [Infos] [STDERR] at java.io.DataInputStream.readChar(DataInputStream.java:365) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.network.packet.Packet.readString(Packet.java:231) 2014-01-24 21:11:05 [Infos] [STDERR] at fr.wirestone.PacketHandler.handleSoundBlockPacket(PacketHandler.java:29) 2014-01-24 21:11:05 [Infos] [STDERR] at fr.wirestone.PacketHandler.onPacketData(PacketHandler.java:19) 2014-01-24 21:11:05 [Infos] [STDERR] at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255) 2014-01-24 21:11:05 [Infos] [STDERR] at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245) 2014-01-24 21:11:05 [Infos] [STDERR] at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:70) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484) 2014-01-24 21:11:05 [Infos] [STDERR] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) -
Le String que tu as envoyé est null, il faudrait lui mettre une valeur par défaut.
Tu es sur du “packet.readString(data,200);” ? -
J’ai moi même recrée les deux méthodes (writeString() et readString()) et j’obtiens la même erreur.
En examinant les bytes avec des System.out.println(), j’ai pu voir que les coordonnées n’étaient pas présentes et que ma méthode donnait la longueur à partir de 0 et non de 1, ce qui provoquait une erreur dans ma méthode. J’ai corrigé le problème. Voici mes deux méthodes (pleinement opérationnelles), pour ceux qui auraient le même problème :/** * Permet d'écrire une chaîne de caractères dans un DataOutputStream * @param stream - Le DataOutputStream * @param str - La chaîne à écrire * @see readString() */ public static void writeString(DataOutputStream stream, String str) throws IOException{ char[] chrs = str.toCharArray(); stream.writeShort(chrs.length - 1); for(char i : chrs){ stream.writeChar(i); } } /** * Permet de récupérer une chaîne de caractères formée avec la méthode `writeString()` * @param stream - Le DataInputStream * @return str- La chaîne de caractère lue * @see writeString() */ public static String readString(DataInputStream stream) throws IOException{ short lenght = stream.readShort(); String str = ""; for(short i = 0; i<=lenght; i++){ str += stream.readChar(); } return str; }Bref maintenant je n’ai plus d’erreurs, sauf que les valeurs de mes boutons ne s’initialisent pas correctement, (en fait elles ne s’initialisent pas du tout), comme si mon DataInputStream n’avait aucun effet… T_T
GuiSoundBlock.java@SideOnly(Side.CLIENT) public class GuiSoundBlock extends GuiContainer{ public static ResourceLocation texture = new ResourceLocation("wsmod", "gui/soundBlock.png"); private ArrayList <string>soundList = new ArrayList<string>(); private TileEntitySoundBlock soundBlock; private int volume = 50, range = 50, delay = 50, x, y; private GuiTextField soundChooser; private String sound = "wsmod:alarm-default"; private Logger logger; public GuiSoundBlock(InventoryPlayer inventory, TileEntitySoundBlock tile){ super(new ContainerSoundBlock(inventory, tile)); this.logger = WirestoneModLogger.getLogger(); this.soundBlock = tile; this.xSize = 255; this.ySize = 255; this.soundList = Registry.soundList; this.volume = (int)tile.getVolume() * 100; } @Override public void initGui(){ super.initGui(); //Initialisation des variables this.x = (this.width) / 2; this.y = (this.height - this.ySize) / 2; this.buttonList.clear(); //Selecteur de volume this.buttonList.add(new GuiButton(1, x + 60, y + 40, 20, 20, "+")); this.buttonList.add(new GuiButton(2, x + 80, y + 40, 20, 20, "++")); this.buttonList.add(new GuiButton(3, x - 80, y + 40, 20, 20, "-")); this.buttonList.add(new GuiButton(4, x - 100, y + 40, 20, 20, "--")); //Selecteur de portée this.buttonList.add(new GuiButton(5, x + 60, y + 80, 20, 20, "+")); this.buttonList.add(new GuiButton(6, x + 80, y + 80, 20, 20, "++")); this.buttonList.add(new GuiButton(7, x - 80, y + 80, 20, 20, "-")); this.buttonList.add(new GuiButton(8, x - 100, y + 80, 20, 20, "--")); //Selecteur de délai this.buttonList.add(new GuiButton(9, x + 60, y + 120, 20, 20, "+")); this.buttonList.add(new GuiButton(10, x + 80, y + 120, 20, 20, "++")); this.buttonList.add(new GuiButton(11, x - 80, y + 120, 20, 20, "-")); this.buttonList.add(new GuiButton(12, x - 100, y + 120, 20, 20, "--")); //Selecteur de son this.soundChooser = new GuiTextField(this.fontRenderer, 8, 170, 170, 20);//Coordonnées de 'texte' this.soundChooser.setMaxStringLength(100); this.soundChooser.setFocused(true); this.soundChooser.setCanLoseFocus(false); this.buttonList.add(new GuiButton(13, x + 80, y + 160, 20, 20, "Ok")); this.buttonList.add(new GuiButton(14, x + 40, y + 200, 100, 20, "Test")); //Initialisation des variables selon le tileEntity this.volume = (int)this.soundBlock.getVolume() * 100; this.range = this.soundBlock.getRange(); this.delay = this.soundBlock.getDelay(); this.sound = this.soundBlock.getSound(); this.soundChooser.setText(this.soundBlock.getSound().replace("wsmod:","")); } @Override protected void actionPerformed(GuiButton guiButton){ String sound = "wsmod:" + this.soundChooser.getText(); switch(guiButton.id){ case 1: if(this.volume < 100){ this.volume++; } break; case 2: if(this.volume + 10 < 100){ this.volume += 10; } else{ this.volume = 100; } break; case 3: if(this.volume > 0){ this.volume--; } break; case 4: if(this.volume - 10 > 0){ this.volume -= 10; } else{ this.volume = 0; } break; case 5: if(this.range < 100){ this.range++; } break; case 6: if(this.range + 10 < 100){ this.range += 10; } else{ this.range = 100; } break; case 7: if(this.range > 0){ this.range--; } break; case 8: if(this.range - 10 > 0){ this.range -= 10; } else{ this.range = 0; } break; case 9: if(this.delay < 100){ this.delay++; } break; case 10: if(this.delay + 10 < 100){ this.delay += 10; } else{ this.delay = 100; } break; case 11: if(this.delay > 0){ this.delay--; } break; case 12: if(this.delay - 10 > 0){ this.delay -= 10; } else{ this.delay = 0; } break; case 13: if(this.soundList.contains(sound)){ this.sound = "" + sound; } else{ this.soundChooser.setText(this.sound.replace("wsmod:","")); } break; case 14: this.soundBlock.worldObj.playSoundEffect(this.soundBlock.xCoord,this.soundBlock.yCoord,this.soundBlock.zCoord,this.sound,(float)this.volume/100,1.0F); break; } for(int i = 1; i<=5; i++){ ByteArrayOutputStream bos = null; DataOutputStream dos = null; try{ bos = new ByteArrayOutputStream(); dos = new DataOutputStream(bos); dos.writeInt(this.soundBlock.xCoord); dos.writeInt(this.soundBlock.yCoord); dos.writeInt(this.soundBlock.zCoord); PacketHandler.writeString(dos,this.sound); dos.writeFloat((float)this.volume/100); dos.writeInt(this.delay); dos.writeInt(this.range); this.mc.getNetHandler().addToSendQueue(new Packet250CustomPayload("wsmod|soundBlock",bos.toByteArray())); break; }catch(Exception e){ this.logger.warning("Erreur lors de l'envoi du packet de données du SoundBlock (essai " + i + "/5)"); } } } /** * Called from the main game loop to update the screen. */ @Override public void updateScreen(){ if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead){ this.mc.thePlayer.closeScreen(); } this.soundChooser.updateCursorCounter(); } @Override public void keyTyped(char par1, int par2){ super.keyTyped(par1,par2); this.soundChooser.textboxKeyTyped(par1,par2); } @Override public void mouseClicked(int i, int j, int k){ super.mouseClicked(i, j, k); this.soundChooser.mouseClicked(i,j,k); } @Override protected void drawGuiContainerForegroundLayer(int par1, int par2){ LanguageRegistry r = LanguageRegistry.instance(); this.fontRenderer.drawString(r.getStringLocalization("container.soundblock"),8,7,0); this.drawCenteredString("Volume",125,30,0,false); this.drawCenteredString(this.volume + "%",125,45,0,false); this.drawCenteredString(r.getStringLocalization("container.soundblock.range"),125,70,0,false); this.drawCenteredString(this.range + " blocks",125,85,0,false); this.drawCenteredString(r.getStringLocalization("container.soundblock.delay"),125,110,0,false); this.drawCenteredString(this.delay + " ticks",125,125,0,false); this.drawCenteredString(r.getStringLocalization("container.soundblock.sound"),125,150,0,false); this.soundChooser.drawTextBox(); this.drawCenteredString(r.getStringLocalization("container.soundblock.sounds"),320,0,-6250336,true); int j = 0; for(String i : this.soundList){ this.drawCenteredString("- " + i.replace("wsmod:",""),320,10 + j,-6250336,true); j += 10; } } @Override protected void drawGuiContainerBackgroundLayer(float f, int i, int j){ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(texture); int x = (this.width - this.xSize) / 2; int y = (this.height - this.ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); } private void drawCenteredString(String par2Str, int par3, int par4, int par5, boolean shadow){ if(shadow){ this.fontRenderer.drawStringWithShadow(par2Str, par3 - this.fontRenderer.getStringWidth(par2Str) / 2, par4, par5); } else{ this.fontRenderer.drawString(par2Str, par3 - this.fontRenderer.getStringWidth(par2Str) / 2, par4, par5); } } }Merci d’avance :)</string></string>
-
Dans ton tile entity, ajoute ces deux fonctions :
public Packet getDescriptionPacket() { NBTTagCompound nbttagcompound = new NBTTagCompound(); this.writeToNBT(nbttagcompound); return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 4, nbttagcompound); } public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) { this.readFromNBT(pkt.data); } -
@‘robin4002’:
Dans ton tile entity, ajoute ces deux fonctions :
Elles y sont déjà, c’est ça le problème !
Je remet mes classes modifiées… [EDIT : Supprimé pour plus de clarté]
Peut être ai-je oublié d’ajouter quelque chose dans le GameRegistry ? -
Ton readFromNBT et ton writeToNBT sont inversés.
-
@‘robin4002’:
Ton readFromNBT et ton writeToNBT sont inversés.
Mince ! Le pire c’est que j’ai dû relire le code 10 fois sans le voir O_o. Ça marche parfaitement ! Merci beaucoup de ton aide, et de celle de Superloup10.
Comment vous remercier ? ^^