MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Problème de GUI

    Planifier Épinglé Verrouillé Déplacé Résolu Anciennes versions
    1.6.4
    48 Messages 4 Publieurs 13.8k Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • EclipseOnFireE Hors-ligne
      EclipseOnFire
      dernière édition par

      Bon voilà, j’ai tout recodé et mon système de fenêtre fonctionne. Il reste seulement deux problèmes :

      • Ma fenêtre s’ouvre deux fois de suite (Je sais pas s’il faut check isRemote ou pas en fait)
      • Ma TileEntity ne se sauvegarde pas (lorsque je quitte le monde et que je le charge, ma TileEntity perd ses paramètres…)

      Si le problème vient de ma fenêtre, je recoderai en utilisant la méthode Minecraft mais comme je le gère pas je préfère éviter en fait.
      Voici mes classes :
      TileEntity.java

      
      public class TileEntitySoundBlock extends TileEntity{
      
      private boolean loop = false;
      private String sound = "alarm.ogg";
      private float volume = 1.0F;
      private int delay = 0;
      
      @Override
      public void readFromNBT(NBTTagCompound nbtTag){
      super.readFromNBT(nbtTag);
      nbtTag.setBoolean("Loop",this.loop);
      nbtTag.setString("Sound",this.sound);
      nbtTag.setFloat("Volume",this.volume);
      nbtTag.setInteger("Delay",this.delay);
      }
      
      @Override
      public void writeToNBT(NBTTagCompound nbtTag){
      super.writeToNBT(nbtTag);
      this.loop = nbtTag.getBoolean("Loop");
      this.sound = nbtTag.getString("Sound");
      this.volume = nbtTag.getFloat("Volume");
      this.delay = nbtTag.getInteger("Delay");
      }
      
      public void setVolume(float volume){
      this.volume = volume;
      }
      
      public float getVolume(){
      return this.volume;
      }
      
      public void setDelay(int delay){
      this.delay = delay;
      }
      public int getDelay(){
      return this.delay;
      }
      public void setSound(String sound){
      System.out.println("setSound = " + sound);
      this.sound = sound;
      }
      
      public String getSound(){
      System.out.println("getSound = " + this.sound);
      return this.sound;
      }
      
      public String getSoundToPlay(){
      return "wsmod:" + this.sound;
      }
      
      public void setIsLoop(boolean loop){
      this.loop = loop;
      }
      
      public boolean getIsLoop(){
      return this.loop;
      }
      }
      
      

      GuiHandlerSoundBlock.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;
      }
      }
      
      

      GuiSoundBlock.java

      
      public class GuiSoundBlock extends GuiContainer{
      
      private TileEntitySoundBlock soundBlock;
      
      public GuiSoundBlock(InventoryPlayer inventory, TileEntitySoundBlock tileEntity){
      super(new ContainerSoundBlock(inventory, tileEntity));
      this.soundBlock = tileEntity;
      this.ySize = 230;
      }
      
      @SideOnly(Side.CLIENT)
      @Override
      protected void drawGuiContainerForegroundLayer(int par1, int par2){
      new SoundBlockDialog(soundBlock);
      }
      
      @Override
      protected void drawGuiContainerBackgroundLayer(float f, int i, int j){}
      }
      
      

      Merci d’avance ! (Désolé d’être aussi têtu mais je gère vraiment pas les GUI Minecraft donc je ne l’utiliserai qu’en dernier recours)

      Travaille sur un super serveur, Wirestone.

      1 réponse Dernière réponse Répondre Citer 0
      • robin4002R Hors-ligne
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
        dernière édition par

        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

        1 réponse Dernière réponse Répondre Citer 0
        • EclipseOnFireE Hors-ligne
          EclipseOnFire
          dernière édition par

          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 😛

          Travaille sur un super serveur, Wirestone.

          1 réponse Dernière réponse Répondre Citer 0
          • robin4002R Hors-ligne
            robin4002 Moddeurs confirmés Rédacteurs Administrateurs
            dernière édition par

            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.

            1 réponse Dernière réponse Répondre Citer 0
            • EclipseOnFireE Hors-ligne
              EclipseOnFire
              dernière édition par

              @‘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.java

              
              public 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 !

              Travaille sur un super serveur, Wirestone.

              1 réponse Dernière réponse Répondre Citer 0
              • GuguG Hors-ligne
                Gugu
                dernière édition par

                actionPerformed = un switch avec l’id du bouton en param, et dans le case id: tu mets ton code a effectuer

                "If you have a comprehensive explanation for everything then it decreases uncertainty and anxiety and reduces your cognitive load. And if you can use that simplifying algorithm to put yourself on the side of moral virtue then you’re constantly a good person with a minimum of effort."
                ― Jordan B. Peterson

                1 réponse Dernière réponse Répondre Citer 0
                • EclipseOnFireE Hors-ligne
                  EclipseOnFire
                  dernière édition par

                  @‘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.

                  Travaille sur un super serveur, Wirestone.

                  1 réponse Dernière réponse Répondre Citer 0
                  • robin4002R Hors-ligne
                    robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                    dernière édition par

                    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)

                    1 réponse Dernière réponse Répondre Citer 0
                    • EclipseOnFireE Hors-ligne
                      EclipseOnFire
                      dernière édition par

                      @‘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…

                      Travaille sur un super serveur, Wirestone.

                      1 réponse Dernière réponse Répondre Citer 0
                      • robin4002R Hors-ligne
                        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                        dernière édition par

                        UTF oui, sinon tente le char. J’ai donné les codes de tête, je ne les connais pas tous par cœurs.

                        1 réponse Dernière réponse Répondre Citer 0
                        • EclipseOnFireE Hors-ligne
                          EclipseOnFire
                          dernière édition par

                          @‘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;
                          

                          Travaille sur un super serveur, Wirestone.

                          1 réponse Dernière réponse Répondre Citer 0
                          • robin4002R Hors-ligne
                            robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                            dernière édition par

                            Importe ton container, si tu en a pas il faut en créer un.

                            1 réponse Dernière réponse Répondre Citer 0
                            • EclipseOnFireE Hors-ligne
                              EclipseOnFire
                              dernière édition par

                              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 ^^).

                              Travaille sur un super serveur, Wirestone.

                              1 réponse Dernière réponse Répondre Citer 0
                              • robin4002R Hors-ligne
                                robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                                dernière édition par

                                La classe est bonne, envoie le crash report et ton guiHandler

                                1 réponse Dernière réponse Répondre Citer 0
                                • EclipseOnFireE Hors-ligne
                                  EclipseOnFire
                                  dernière édition par

                                  @‘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;
                                  }
                                  }
                                  

                                  Travaille sur un super serveur, Wirestone.

                                  1 réponse Dernière réponse Répondre Citer 0
                                  • robin4002R Hors-ligne
                                    robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                                    dernière édition par

                                    Ha en fait non, il y a un problème dans ton container. Envoie toute la classe du container, avec les importations.

                                    1 réponse Dernière réponse Répondre Citer 0
                                    • EclipseOnFireE Hors-ligne
                                      EclipseOnFire
                                      dernière édition par

                                      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;
                                      }
                                      }
                                      

                                      Travaille sur un super serveur, Wirestone.

                                      1 réponse Dernière réponse Répondre Citer 0
                                      • robin4002R Hors-ligne
                                        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                                        dernière édition par

                                        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 ?

                                        1 réponse Dernière réponse Répondre Citer 1
                                        • EclipseOnFireE Hors-ligne
                                          EclipseOnFire
                                          dernière édition par

                                          @‘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 ! 😛

                                          Travaille sur un super serveur, Wirestone.

                                          1 réponse Dernière réponse Répondre Citer 0
                                          • robin4002R Hors-ligne
                                            robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                                            dernière édition par

                                            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);
                                            
                                            1 réponse Dernière réponse Répondre Citer 0
                                            • 1
                                            • 2
                                            • 3
                                            • 2 / 3
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB