Problème de GUI
-
actionPerformed = un switch avec l’id du bouton en param, et dans le case id: tu mets ton code a effectuer
-
@‘Gugu42’:
actionPerformed = un switch avec l’id du bouton en param, et dans le case id: tu mets ton code a effectuer
Non, ça d’accord ! Je veux dire le code pour les packets.
-
Dans ton gui, tu remplace :
tileEntity.setIsLoop(loopCheckBox.isSelected()); tileEntity.setSound((String)soundChooser.getSelectedItem()); tileEntity.setDelay((int)delayChooser.getValue()); tileEntity.setVolume((float)volumeChooser.getValue()/100);Par :
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream); try { dataoutputstream.writeBoolean(loopCheckBox.isSelected()); dataoutputstream.writeString((String)soundChooser.getSelectedItem()); dataoutputstream.writeInt((int)delayChooser.getValue()); dataoutputstream.writeFloat((float)volumeChooser.getValue()/100)); this.mc.getNetHandler().addToSendQueue(new Packet250CustomPayload("wsmod|soundBlock", bytearrayoutputstream.toByteArray())); } catch(Exception exception) { exception.printStackTrace(); }Et dans ton //Je mets quoi la
tu mets :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);Et normalement devrait être bon. Si ça fonctionne pas, c’est qu’il n’aime pas la gui java (d’ailleurs, elle s’affiche comment en jeu ? j’aimerai bien voir ça). Ou alors que le nom du chanel est trop long, ou que tu ne l’a pas enregistré dans la classe principale. (Dans le @NetworkMod il faut mettre la classe du packet handler et les chanel utilisés)
-
@‘robin4002’:
dataoutputstream.writeString((String)soundChooser.getSelectedItem());Cette méthode n’existe pas O_o. Ya writeUTF(String s) ou writeChars(String s). Je vais tenter le writeUTF…
-
UTF oui, sinon tente le char. J’ai donné les codes de tête, je ne les connais pas tous par cœurs.
-
@‘robin4002’:
UTF oui, sinon tente le char. J’ai donné les codes de tête, je ne les connais pas tous par cœurs.
Ouais j’ai dû changer le readUTF() de l’autre côté, ça à l’air de marcher. J’ai juste un souci de cast au niveau du
(ContainerSoundBlock)player.openContainer; -
Importe ton container, si tu en a pas il faut en créer un.
-
Nan c’est un problème de cast, pas d’import (ClassCastException). J’ai dû gaffer quelque part en suivant le tuto je pense…
public class ContainerSoundBlock extends Container{ private TileEntitySoundBlock tileEntity; public ContainerSoundBlock(InventoryPlayer playerInventory, TileEntitySoundBlock teChest){ this.tileEntity = teChest; } @Override public boolean canInteractWith(EntityPlayer player){ return true; } public TileEntitySoundBlock getSoundBlockTile() { return tileEntity; } }En parlant d’imports, vu que ça arrive souvent (j’ai pu le constater :P), je conseille vivement (pour ceux qui ne le savent pas) d’utiliser Ctrl + Shift + O ça génère les imports nécéssaires, supprime ceux qui ne sont pas utilisés et les organise automatiquement (tellement plus simple ^^).
-
La classe est bonne, envoie le crash report et ton guiHandler
-
@‘robin4002’:
La classe est bonne, envoie le crash report et ton guiHandler
Ca roule !
Voilà le stackTrace :
java.lang.ClassCastException: net.minecraft.inventory.ContainerPlayer cannot be cast to fr.wsmod.ContainerSoundBlock 2014-01-12 15:33:58 [Infos] [STDERR] at fr.wsmod.PacketHandler.handleSoundBlockPacket(PacketHandler.java:29) 2014-01-12 15:33:58 [Infos] [STDERR] at fr.wsmod.PacketHandler.onPacketData(PacketHandler.java:18) 2014-01-12 15:33:58 [Infos] [STDERR] at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255) 2014-01-12 15:33:58 [Infos] [STDERR] at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245) 2014-01-12 15:33:58 [Infos] [STDERR] at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.network.NetServerHandler.handleCustomPayload(NetServerHandler.java:1130) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:70) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484) 2014-01-12 15:33:58 [Infos] [STDERR] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)GuiHandler.java
public class GuiHandlerSoundBlock implements IGuiHandler{ @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){ TileEntity te = world.getBlockTileEntity(x, y, z); if(te instanceof TileEntitySoundBlock){ return new ContainerSoundBlock(player.inventory, (TileEntitySoundBlock)te); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity te = world.getBlockTileEntity(x, y, z); if(te instanceof TileEntitySoundBlock){ return new GuiSoundBlock(player.inventory, (TileEntitySoundBlock)te); } return null; } } -
Ha en fait non, il y a un problème dans ton container. Envoie toute la classe du container, avec les importations.
-
Quel trisomique ! Moi qui remet mon GUIHandler… Sérieux T_T
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; public class ContainerSoundBlock extends Container{ private TileEntitySoundBlock tileEntity; public ContainerSoundBlock(InventoryPlayer playerInventory, TileEntitySoundBlock teChest){ this.tileEntity = teChest; } @Override public boolean canInteractWith(EntityPlayer player){ return true; } public TileEntitySoundBlock getSoundBlockTile(){ return tileEntity; } } -
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 ?