MFF

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

    Item qui a un cooldown

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    19 Messages 5 Publieurs 4.8k Vues 2 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.
    • M Hors-ligne
      mosca421
      dernière édition par

      Je les met en place comment pareil qu’un bloc ?

      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

        Non pour les items ça passe par l’item stack.
        Pas possible de faire un tile entity (et pas besoin).
        Dans la fonction onRightClick si !stack.hasTagCompound() tu mets un tag (stack.setTagCompound(new NBTTagCompound()). Ensuite tu peux utiliser stack.getTagCompound() pour le get et donc tu peux mettre des valeurs dedans. (exemple : stack.getTagCompound().setInteger(“timer”, 20); )
        Ensuite dans la fonction update si le stack a un tag nbt et que la valeur de stack.getTagCompound().getInteger(“timer”) > 0 tu diminue de 1.

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

          robin j’ai fais un truc du genre :

          
          package fr.Mosca421.mods.Items;
          
          import cpw.mods.fml.relauncher.Side;
          import cpw.mods.fml.relauncher.SideOnly;
          import net.minecraft.entity.Entity;
          import net.minecraft.entity.player.EntityPlayer;
          import net.minecraft.item.Item;
          import net.minecraft.item.ItemStack;
          import net.minecraft.nbt.NBTTagCompound;
          import net.minecraft.potion.Potion;
          import net.minecraft.potion.PotionEffect;
          import net.minecraft.world.World;
          
          public class strengthstick extends Item {
          
          public strengthstick(){
          super();
          this.setMaxDamage(16);
          this.setMaxStackSize(1);
          
          }
          public ItemStack onUpdate(ItemStack item, World world, EntityPlayer player)
          {
          
          if(item.getTagCompound().getInteger("timer") > 0)
          item.getTagCompound().getInteger("timer");
          
          return item;
          
          }
          
          public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) {
          
          if(!item.hasTagCompound())
          {
          item.setTagCompound(new NBTTagCompound());
          item.getTagCompound().setInteger("timer", 20);
          item.damageItem(1, player);
          player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 50, 2));
          }
          return item;
          
          }
          
          @SideOnly(Side.CLIENT)
              public boolean hasEffect(ItemStack item)
              {
          return true;
              }
          
          }
          
          

          Il me manque pour eleveer 1 a timer je fais comment au juste ?

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

            Dans on update, si timer > 0, tu enlève 1 à timer
            Je pense que c’est plutôt un truc comme

            
            public ItemStack onUpdate(ItemStack item, World world, EntityPlayer player)
            {
            
            if(!item.hasTagCompound())
            {
            item.setTagCompound(new NBTTagCompound());
            item.getTagCompound().setInteger("timer"), 0);
            }
            
            if(item.getTagCompound().getInteger("timer") > 0)
            {
            item.getTagCompound().setInteger("timer", item.getTagCompound().getInteger("timer") - 1)
            }
            
            return item;
            
            }
            
            public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) {
            
            if(item.getTagCompound().getInteger("timer") <= 0)
            {
            item.getTagCompound().setInteger("timer", 20);
            item.damageItem(1, player);
            player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 50, 2));
            }
            return item;
            
            
            1 réponse Dernière réponse Répondre Citer 0
            • M Hors-ligne
              mosca421
              dernière édition par

              Petit crash =/ :

              
              – Head --
              Stacktrace:
              at fr.Mosca421.mods.Items.strengthstick.onItemRightClick(strengthstick.java:43)
              at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:164)
              at net.minecraft.client.multiplayer.PlayerControllerMP.sendUseItem(PlayerControllerMP.java:430)
              at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1557)
              
              -- Affected level --
              Details:
              Level name: MpServer
              All players: 1 total; [EntityClientPlayerMP['Player487'/245, l='MpServer', x=-748,61, y=5,62, z=602,93]]
              Chunk stats: MultiplayerChunkCache: 625, 625
              Level seed: 0
              Level generator: ID 01 - flat, ver 0\. Features enabled: false
              Level generator options: 
              Level spawn location: World: (-741,4,260), Chunk: (at 11,0,4 in -47,16; contains blocks -752,0,256 to -737,255,271), Region: (-2,0; contains chunks -64,0 to -33,31, blocks -1024,0,0 to -513,255,511)
              Level time: 462682 game time, 106716 day time
              Level dimension: 0
              Level storage version: 0x00000 - Unknown?
              Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
              Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
              Forced entities: 1 total; [EntityClientPlayerMP['Player487'/245, l='MpServer', x=-748,61, y=5,62, z=602,93]]
              Retry entities: 0 total; []
              Server brand: fml,forge
              Server type: Integrated singleplayer server
              Stacktrace:
              at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)
              at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566)
              at net.minecraft.client.Minecraft.run(Minecraft.java:991)
              at net.minecraft.client.main.Main.main(Main.java:164)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
              at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
              at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
              at GradleStart.main(Unknown Source)
              
              

              A propos du code j’ai environs le meme que bodri j’ai juste modifier le haseffect

              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

                Ta fonction onUpdate ne sera jamais appelé car tu n’as pas les bons arguments (ni le bon type).

                   public void onUpdate(ItemStack stack, World world, Entity entity, int slotIndex, boolean inHand) {}
                

                Donc ça serait plutôt comme ça :

                   public void onUpdate(ItemStack stack, World world, Entity entity, int slotIndex, boolean inHand)
                    {
                        if(!stack.hasTagCompound() && stack.getTagCompound().getInteger("timer") > 0)
                            stack.getTagCompound().setInteger("timer", stack.getTagCompound().getInteger("timer") - 1);
                    }
                

                Et pour onItemRightClick :

                   public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
                    {
                        if(!stack.hasTagCompound())
                        {
                            stack.setTagCompound(new NBTTagCompound());
                        }
                        item.getTagCompound().setInteger("timer", 20);
                        item.damageItem(1, player);
                        player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 50, 2));
                        return stack;
                    }
                
                1 réponse Dernière réponse Répondre Citer 0
                • DeletedD Hors-ligne
                  Deleted
                  dernière édition par

                  Et puis ton code n’est pas adapté, tu veux mettre un effet de potion si ton timer est fini. Genre un effet de potion possible toutes les 20 secondes par-exemple ?

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

                    Non quand le mec clique dessus sa fait l’effet après il ne peut pas l’effectuer pendant 10 seconde ansi de suite

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

                      Ouep c’est ce que je dis …
                      Je t’envois le code 😃

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

                        Tu es un coeur Merci =p

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

                          Voilà, je t’ai même ajouté quelque commentaires =D

                          
                          package fr.mrplaigon.testmod.common.item;
                          
                          import cpw.mods.fml.relauncher.Side;
                          import cpw.mods.fml.relauncher.SideOnly;
                          import net.minecraft.entity.Entity;
                          import net.minecraft.entity.player.EntityPlayer;
                          import net.minecraft.item.Item;
                          import net.minecraft.item.ItemStack;
                          import net.minecraft.nbt.NBTTagCompound;
                          import net.minecraft.potion.Potion;
                          import net.minecraft.potion.PotionEffect;
                          import net.minecraft.util.ChatComponentTranslation;
                          import net.minecraft.world.World;
                          
                          public class StrengthStick extends Item
                          {
                          
                          public StrengthStick()
                          {
                          this.setMaxDamage(16);
                          this.setMaxStackSize(1);
                          }
                          
                          @Override
                          public void onUpdate(ItemStack item, World world, Entity player, int slotIndex, boolean inHand)
                          {
                          if(item.hasTagCompound())//Si ton item n'a pas de tag alors on ne fait rien
                          {
                          if(item.stackTagCompound.getInteger("timer") > 0)//si ton timer est supérieur à 0 (après un clic droit logiquement)
                          {
                          item.stackTagCompound.setInteger("timer", (int) (item.stackTagCompound.getInteger("timer") + 1));//On l'incrémente de 1 à chaque tick
                          }
                          if(item.stackTagCompound.getInteger("timer") >= (int) (6*20))//Remplace 6 par le nombre de secondes du timer souhaité
                          {
                          item.stackTagCompound.setInteger("timer", 0);//On remet à 0 si le timer est arrivé à la limite souhaitée
                          }
                          }
                          super.onUpdate(item, world, player, slotIndex, inHand);
                          }
                          
                          public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player)
                          {
                          if(!item.hasTagCompound())//Même condition, si ton item n'a pas de tag on lui en ajoute avec l'int timer en +
                          {
                          item.setTagCompound(new NBTTagCompound());
                          item.stackTagCompound.setInteger("timer", 0);
                          }
                          if(item.stackTagCompound.getInteger("timer") == 0)
                          {
                          player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 120, 2));
                          item.stackTagCompound.setInteger("timer", 1);//On le met à 1 pour pouvoir rentrer dans la condition de onUpdate()
                          }
                          else
                          {
                          if(world.isRemote)
                          player.addChatComponentMessage(new ChatComponentTranslation("Tu dois attendre que le baton se recharge !"));//On indique au joueur via ce message si le timer n'est pas encore arrivé à la limite souhaitée
                          }
                          return item;
                          }
                          
                          @SideOnly(Side.CLIENT)
                          public boolean hasEffect(ItemStack item)
                          {
                          return true;
                          }
                          }
                          
                          

                          N’oublie pas le petit + stp

                          1 réponse Dernière réponse Répondre Citer 2
                          • M Hors-ligne
                            mosca421
                            dernière édition par

                            Si tu me dis ou il est je veux bien =p

                            Edit : Juste j’ai essayer de mon coter de faire que l’item ne soit pas enchanter si l’item est inutilisable et enchanter quand il l’es sauf que je crash a chaque fois =/

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

                              Juste j’ai essayer de mon coter de faire que l’item ne soit pas enchanter si l’item est inutilisable et enchanter quand il l’es sauf que je crash a chaque fois =/

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

                                Ok voici le code =D

                                
                                @SideOnly(Side.CLIENT)
                                public boolean hasEffect(ItemStack item)
                                {
                                return item.hasTagCompound() ? (item.stackTagCompound.getInteger("timer") == 0 ? true : false) : false;//On vérifie déjà si l'ItemStack a set un NBTTagCompound si oui, on vérifie si Timer en fait partie et si il est égal à 0, si oui, on return true à la méthode
                                }
                                
                                
                                1 réponse Dernière réponse Répondre Citer 0
                                • M Hors-ligne
                                  mosca421
                                  dernière édition par

                                  Merci =p

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

                                    N’oublie pas la balise résolue 🙂

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

                                      Merci! Grâce à toi, Deleted, j’ai enfin réussie à développer mon item! Merci beaucoup!

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

                                      MINECRAFT FORGE FRANCE © 2024

                                      Powered by NodeBB