MFF

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

    Code Cooldown, besoin d'avis

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    16 Messages 3 Publieurs 2.5k 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.
    • DeletedD Hors-ligne
      Deleted
      dernière édition par

      Le tuto de BrokenSwing par-exemple.

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

        Yep j’ai vu je me penche dessus 😉


        J’ai encore un soucis… J’ai fait cela mais en jeu cela n’a pas d’effet…

        public class ItemDes extends Item
        {
        ItemStack itemdes = new ItemStack (Heimnor.itemdes);
        
        public ItemStack onItemRightClick(ItemStack itemdes, World world, EntityPlayer player)
          {
        if (!itemdes.hasTagCompound())
        {
        itemdes.setTagCompound(new NBTTagCompound());
        itemdes.stackTagCompound.setInteger("timer", 0);
        }
        if (itemdes.stackTagCompound.getInteger("timer") == 0){
        
        }
        if(!world.isRemote)
        {
        MinecraftServer server = MinecraftServer.getServer();
              ICommandManager command = server.getCommandManager();
              command.executeCommand(player, "/dndroll 2d6");
              itemdes.stackTagCompound.setInteger("timer", 1);
        }
        
              return itemdes;       
          }
        
        public void onUpdate(ItemStack itemdes, World world, EntityPlayer player, int var1, boolean var2) 
        {
        super.onUpdate(itemdes, world, player, var1, var2);
        
        if (itemdes.hasTagCompound())
        {
        if (itemdes.stackTagCompound.getInteger("timer") > 0)
        
        {
        itemdes.stackTagCompound.setInteger("timer",
        (int) (itemdes.stackTagCompound.getInteger("timer") + 1));
        
        }
        if (itemdes.stackTagCompound.getInteger("timer") >= (int) (200))
        {
        itemdes.stackTagCompound.setInteger("timer", 0);
        
        }
        }
        }
        }
        
        

        Je ne vois toujours pas ce qui ne va pas en fait.

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

          Essaie de débug pour voir où le code s’arrête

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

            @‘Dylem’:

            3 - La fonction onUpdate prend les arguments :

            public void onUpdate(ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, boolean p_77663_5_) {}
            

            …

            Si je t'ai aidé, n'hésite pas à cliquer sur le nombre vert en dessous de mon image de profil, pour me le faire savoir. Ca me motive pour continuer …

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

              Il semblerait que la fonction OnUpdate ne marche pas d’après la console …

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

                Qu’est-ce qui ne “marche pas” ? Faut savoir détailler ses soucis quand on débute. La commande est-elle exécutée, oui ou non ? Ou est-ce seulement le counter qui ne va pas ??

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

                  Je ne crois pas que tu comprennes bien le problème que je soulève…

                  Le paramètre est Entity, pas EntityPlayer…

                  
                  public void onUpdate(ItemStack itemdes, World world, Entity entity, int var1, boolean var2) 
                  {    
                      super.onUpdate(itemdes, world, entity, var1, var2);
                  
                      if(entity != null && entity instanceof EntityPlayer) {
                  
                              if (itemdes.hasTagCompound())
                              {
                                  if (itemdes.stackTagCompound.getInteger("timer") > 0)
                                      itemdes.stackTagCompound.setInteger("timer",itemdes.stackTagCompound.getInteger("timer") + 1);
                                  if (itemdes.stackTagCompound.getInteger("timer") >= 200)
                                      itemdes.stackTagCompound.setInteger("timer", 0);
                              } 
                          }
                  }
                  
                  

                  Si je t'ai aidé, n'hésite pas à cliquer sur le nombre vert en dessous de mon image de profil, pour me le faire savoir. Ca me motive pour continuer …

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

                    Excusez moi je vais détailler plus, en fait la commande se lance, tout ce qui est dans la fonction onItemRightClick fonctionne parfaitement, en revanche, (en plaçant des System.out.println(“Etape x”)) tout ce qui se trouve dans la fonction onUpdate ne semble pas s’executer.

                    Etape 1 et 2 se lance sans soucis mais pas de signe de vie de l’Etape 3. Ce qui fait que je peux lancer la commande mais il n’y a pas de cooldown sur cette dernière.

                    EDIT : L’execution se passe bien jusqu’a cette ligne de code qui pose probleme :

                    if (itemdes.stackTagCompound.getInteger("timer") >= (200))
                    
                    public class ItemDes extends Item
                    {
                    ItemStack itemdes = new ItemStack (Heimnor.itemdes);
                    
                    public ItemStack onItemRightClick(ItemStack itemdes, World world, EntityPlayer player)
                      {
                    if (!itemdes.hasTagCompound())
                    {
                    itemdes.setTagCompound(new NBTTagCompound());
                    itemdes.stackTagCompound.setInteger("timer", 0);
                    }
                    if (itemdes.stackTagCompound.getInteger("timer") == 0){
                    
                    }
                    if(!world.isRemote)
                    {
                    System.out.println("Etape 1");
                    MinecraftServer server = MinecraftServer.getServer();
                          ICommandManager command = server.getCommandManager();
                          command.executeCommand(player, "/dndroll 2d6");
                          itemdes.stackTagCompound.setInteger("timer", 1);
                    }
                    
                          return itemdes;       
                      }
                    
                    public void onUpdate(ItemStack itemdes, World world, net.minecraft.entity.Entity entity, int var1, boolean var2) 
                    {
                    super.onUpdate(itemdes, world, entity, var1, var2);
                    
                    if(entity != null && entity instanceof EntityPlayer) {
                    
                    if (itemdes.hasTagCompound())
                    {
                    if (itemdes.stackTagCompound.getInteger("timer") > 0)
                    
                    {System.out.println("Etape 2");
                    itemdes.stackTagCompound.setInteger("timer",
                    (int) (itemdes.stackTagCompound.getInteger("timer") + 1));
                    
                    }
                    if (itemdes.stackTagCompound.getInteger("timer") >= (200))
                    {
                    itemdes.stackTagCompound.setInteger("timer", 0);
                    System.out.println("Etape 3");
                    }
                    }
                    }
                    }
                    }
                    
                    
                    1 réponse Dernière réponse Répondre Citer 0
                    • DylemD Hors-ligne
                      Dylem
                      dernière édition par

                      Alors encore une fois, plusieurs remarques  🙂

                      1 - Enlève ça au début de ton programme, je ne sais pas ce que tu voulais faire avec mais ça pourrait causer des problèmes (plusieurs variables ayant le même nom)

                      ItemStack itemdes = new ItemStack (Heimnor.itemdes);
                      

                      2 - Il n’y a rien dans cette condition :

                      
                      if (itemdes.stackTagCompound.getInteger("timer") == 0){
                      
                      }
                      
                      

                      Rajoute-là plutôt avec celle-ci :

                      if(!world.isRemote && itemdes.stackTagCompound.getInteger("timer") == 0)
                      

                      3- C’est quoi ces casts d’int en int ? Enlève les (int), ils ne servent à rien ici :

                      (int) (itemdes.stackTagCompound.getInteger("timer")
                      
                      (int) (200)
                      

                      4 - Juste pour vérifier, print ça dans onItemRightClick :

                      System.out.println(!itemdes.isStackable() ? "tout va bien" : "probleme");
                      

                      Si je t'ai aidé, n'hésite pas à cliquer sur le nombre vert en dessous de mon image de profil, pour me le faire savoir. Ca me motive pour continuer …

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

                        Ah ! Ca fonctionne, merci de votre aide 😉 Ca a refait ma journée ducoup ! Je pense que le vrai problème venait de cette fameuse condition vide … Et ducoup le print m’a mis tout va bien .

                        public class ItemDes extends Item
                        {
                        
                        public ItemStack onItemRightClick(ItemStack itemdes, World world, EntityPlayer player)
                          {
                        if (!itemdes.hasTagCompound())
                        {
                        itemdes.setTagCompound(new NBTTagCompound());
                        itemdes.stackTagCompound.setInteger("timer", 0);
                        }
                        if(!world.isRemote && itemdes.stackTagCompound.getInteger("timer") == 0)
                        {
                        
                        MinecraftServer server = MinecraftServer.getServer();
                              ICommandManager command = server.getCommandManager();
                              command.executeCommand(player, "/dndroll 2d6");
                              itemdes.stackTagCompound.setInteger("timer", 1);
                              System.out.println(itemdes.isStackable() ? "tout va bien" : "probleme");
                        }
                        
                              return itemdes;       
                          }
                        
                        public void onUpdate(ItemStack itemdes, World world, net.minecraft.entity.Entity entity, int var1, boolean var2) 
                        {
                        super.onUpdate(itemdes, world, entity, var1, var2);
                        
                        if(entity != null && entity instanceof EntityPlayer) {
                        
                        if (itemdes.hasTagCompound())
                        {
                        if (itemdes.stackTagCompound.getInteger("timer") > 0)
                        
                        {
                        itemdes.stackTagCompound.setInteger("timer", (itemdes.stackTagCompound.getInteger("timer") + 1));
                        }
                        if (itemdes.stackTagCompound.getInteger("timer") >= (20))
                        {System.out.println("Etape 2");
                        itemdes.stackTagCompound.setInteger("timer", 0);
                        System.out.println("Etape 3");
                        }
                        }
                        }
                        }
                        }
                        
                        1 réponse Dernière réponse Répondre Citer 0
                        • DeletedD Hors-ligne
                          Deleted
                          dernière édition par

                          Pense juste à sélectionner la meilleure réponse du topic.

                          1 réponse Dernière réponse Répondre Citer 1
                          • 1 / 1
                          • Premier message
                            Dernier message
                          Design by Woryk
                          ContactMentions Légales

                          MINECRAFT FORGE FRANCE © 2024

                          Powered by NodeBB