Problème de GUI
-
Pour les variables, il faut les synchroniser à l’aide de paquet.
Une fois de plus, regarde nanotech mod, le smoker, le jumper ou le projecteur.Il y a également ça pour les paquets :
http://www.minecraftforgefrance.fr/showthread.php?tid=391&pid=4167#pid4167 -
En lisant ton Smoker.java, j’ai vu que tu as laissé le “player.isSneaking” alors que Forge gère cet élément, c’est écrit dans ton tuto

-
Oui, il y a encore beaucoup de résidu de vieux code qui date du début de nanotech mod, je vais profiter de la 1.7 pour faire un gros nettoyage.
-
@‘robin4002’:
Oui, il y a encore beaucoup de résidu de vieux code qui date du début de nanotech mod, je vais profiter de la 1.7 pour faire un gros nettoyage.
Perso quand ça m’embête d’avoir de vieux trucs et des erreurs dans mon code, je m’énerve et je recode tout xD (c’est pas productif mais c’est efficace
).Bref, j’ai réussi à faire un packet mais je sais vraiment pas quoi mettre dedans ^^.
Mon PacketHandler.javapublic class PacketHandler implements IPacketHandler{ @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player){ EntityPlayer playerSender = (EntityPlayer)player; if(packet.channel.equals("wsmod|soundBlock")){ handleSoundBlockPacket(packet, playerSender); } } private void handleSoundBlockPacket(Packet250CustomPayload packet, EntityPlayer player){ try{ DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data)); //Je met quoi ici ? :P }catch(Exception e){ e.printStackTrace(); } } }TileEntitySoundBlock.java (je met que la partie modifiée hein)
public Packet getDescriptionPacket(){ NBTTagCompound nbttagcompound = new NBTTagCompound(); this.writeToNBT(nbttagcompound); return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 4, nbttagcompound); } @Override public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt){ this.readFromNBT(pkt.data); }Pour la partie “actionPerformed” je sais pas quoi mettre non plus.
Merci d’avance !
-
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.