MFF

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

    Enregistrer les NBT Tags et Individualisé les items?

    Planifier Épinglé Verrouillé Déplacé Non résolu Sans suite
    1.12.2
    13 Messages 2 Publieurs 858 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.
    • robin4002R Hors-ligne
      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
      dernière édition par

      Tu essaies d’accéder a une valeur d’un tag NBT null.
      Avant chaque utilisation de stack.getTagCompound() il faut que tu t’assures que le tag n’est pas null, en vérifiant avec stack.hasTagCompound()

      GwarG 1 réponse Dernière réponse Répondre Citer 0
      • GwarG Hors-ligne
        Gwar @robin4002
        dernière édition par

        @robin4002 Merci beaucoup , c’était la première fois que j’utilisais les nbt tag et je suis encore pas très bon en dev en java.

        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

          De rien ! Le problème est résolu ?

          GwarG 1 réponse Dernière réponse Répondre Citer 0
          • GwarG Hors-ligne
            Gwar @robin4002
            dernière édition par

            @robin4002 enfaite je viens de remarquer un autre problème , c’est que ça enregistre les nbt tag sur l’item qui se trouve dans l’inventaire , le plus à gauche

            public class ItemWeapon extends Item  {
            
            public int maxAmmo;
            public int cooldown;
            public int timer ;
            public Item bullet;
            
                Minecraft mc = Minecraft.getMinecraft();
               public ItemWeapon(String name, int munition,Item itembullet,int cooldown){
            
                this.setUnlocalizedName(name);
                this.setRegistryName(name);
                this.setCreativeTab(Main.SpaceTab);
                Items.ITEMS.add(this);
                this.cooldown = cooldown*20;
                this.maxStackSize = 1;
                bullet = itembullet;
                this.maxAmmo = munition;
            
            }
            private void setmun(ItemStack stack,int mun){
                if(!stack.hasTagCompound()){
                    stack.setTagCompound(new NBTTagCompound());
                }
                {
                    stack.getTagCompound().setInteger("mun", mun);
                }
            }
            private int getmun(ItemStack stack){
                if(!stack.hasTagCompound()){
                    stack.setTagCompound(new NBTTagCompound());
                }
                {
                    int getmun = stack.getTagCompound().getInteger("mun");
                    return getmun;
                }
            }
            private boolean setCooldown(int x){
                return timer>= x * cooldown;
            }
            private void Cooldown(){
                mc.player.getCooldownTracker().setCooldown(this, cooldown);
            }
            @Override
            public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
                timer++;
            
                KeyBinding[] keyBindings = ClientProxy.keyBindings;
                if(!stack.hasTagCompound()){
                    stack.setTagCompound(new NBTTagCompound());
                }
                {
                    if (keyBindings[0].isPressed()) {
                        findammo(stack);
                    }
                }
                super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
            }
            private void findammo(ItemStack stack){
            
                if(!stack.hasTagCompound()) {
                    stack.setTagCompound(new NBTTagCompound());
                }else {
                NBTTagCompound nbt = stack.getTagCompound();
                    if(setCooldown(2) && mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == this) {
                        timer = 0;
            
                        if (mc.player.inventory.hasItemStack(new ItemStack(Items.Bullet)) && nbt.getInteger("mun") <= this.maxAmmo) {
            
                            if (nbt.hasKey("mun")) {
                                setmun(stack, getmun(stack) + 1);
                            } else {
                                setmun(stack, 0);
                            }
                            stack.setTagCompound(nbt);
                            mc.player.inventory.clearMatchingItems(this.bullet, 0, 1, null);
                            Cooldown();
                            System.out.println(nbt.getInteger("mun") + "tir");
                        }
                    }
                }
            }
            @Override
            public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) {
            
                Minecraft mc = Minecraft.getMinecraft();
                        if(entityLiving instanceof EntityPlayer)
                {
                    if(!entityLiving.world.isRemote)
                    {
                        if(!stack.hasTagCompound()){
                            stack.setTagCompound(new NBTTagCompound());
                        }
                        {
                            if (getmun(stack) >= 1) {
                                if (setCooldown(2)) {
                                    EntityBullet entitysnowball = new EntityBullet(entityLiving.world, mc.player);
                                    entitysnowball.shoot(mc.player, mc.player.rotationPitch + 5.0f, mc.player.rotationYaw + 5.0f, 0.0F, 1.5F, 1.0F);
                                    entityLiving.world.spawnEntity(entitysnowball);
                                    Cooldown();
                                    setmun(stack, getmun(stack) - 1);
                                }
                            } else {
                                findammo(stack);
            
                            }
                        }
                    }
                }
                return super.onEntitySwing(entityLiving, stack);
            }
            
            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

              Étrange, je ne vois pas ce qui peut expliquer ce comportement 😕

              GwarG 3 réponses Dernière réponse Répondre Citer 0
              • GwarG Hors-ligne
                Gwar @robin4002
                dernière édition par

                @robin4002 j’ai finalement réussi en utilisant la fonction :

                findammo(mc.player.inventory.getCurrentItem());

                1 réponse Dernière réponse Répondre Citer 0
                • GwarG Hors-ligne
                  Gwar @robin4002
                  dernière édition par

                  @robin4002 Enfaite je viens de regarder j’ai rien changer à mon code , mais le problème c’est que je ne sais pas pourquoi mais quand je relance le monde il y a 1 arme qui est rechargé a 1/6 et les autres à 0/6 à chaque fois que je reviens dans le monde e je ne sais pas d’ou ça viens
                  Le problème avait été résolu mais je ne sais pas pourquoi il est revenue :

                  public class ItemWeapon extends Item  {
                  
                  public int maxAmmo;
                  public int cooldown;
                  public int timer ;
                  public Item bullet;
                  
                  Minecraft mc = Minecraft.getMinecraft();
                  public ItemWeapon(String name, int munition,Item itembullet,int cooldown){
                  
                      this.setUnlocalizedName(name);
                      this.setRegistryName(name);
                      this.setCreativeTab(Main.SpaceTab);
                      Items.ITEMS.add(this);
                      this.cooldown = cooldown*20;
                      this.maxStackSize = 1;
                      bullet = itembullet;
                      this.maxAmmo = munition;
                  
                  }
                  private void setmun(ItemStack stack,int mun){
                      if(!stack.hasTagCompound()){
                          stack.setTagCompound(new NBTTagCompound());
                      }
                      {
                          stack.getTagCompound().setInteger("mun", mun);
                      }
                  }
                  private int getmun(ItemStack stack){
                      if(!stack.hasTagCompound()){
                          stack.setTagCompound(new NBTTagCompound());
                      }
                      {
                          int getmun = stack.getTagCompound().getInteger("mun");
                          return getmun;
                      }
                  }
                  private boolean setCooldown(int x){
                      return timer>= x * cooldown;
                  }
                  private void Cooldown(){
                      mc.player.getCooldownTracker().setCooldown(this, cooldown);
                  }
                  @Override
                  public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
                      timer++;
                  
                      KeyBinding[] keyBindings = ClientProxy.keyBindings;
                      if(!stack.hasTagCompound()){
                          stack.setTagCompound(new NBTTagCompound());
                      }
                      {
                          if (keyBindings[0].isPressed()) {
                              findammo(mc.player.inventory.getCurrentItem());
                  
                          }
                      }
                      super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
                  }
                  private void findammo(ItemStack stack){
                  
                      if(!stack.hasTagCompound()) {
                          stack.setTagCompound(new NBTTagCompound());
                      }else {
                          NBTTagCompound nbt = stack.getTagCompound();
                          if(setCooldown(2) && mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == this) {
                              timer = 0;
                  
                              if (mc.player.inventory.hasItemStack(new ItemStack(Items.Bullet)) && nbt.getInteger("mun") <= this.maxAmmo) {
                  
                                  if (nbt.hasKey("mun")) {
                                      setmun(stack, getmun(stack) + 1);
                                  } else {
                                      setmun(stack, 0);
                                  }
                                  stack.setTagCompound(nbt);
                                  mc.player.inventory.clearMatchingItems(this.bullet, 0, 1, null);
                                  Cooldown();
                                  System.out.println(nbt.getInteger("mun") + "tir");
                              }
                          }
                      }
                  }
                  @Override
                  public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) {
                  
                      Minecraft mc = Minecraft.getMinecraft();
                      if(entityLiving instanceof EntityPlayer)
                      {
                          if(!entityLiving.world.isRemote)
                          {
                              if(!stack.hasTagCompound()){
                                  stack.setTagCompound(new NBTTagCompound());
                              }
                              {
                                  if (getmun(stack) >= 1) {
                                      if (setCooldown(2)) {
                                          EntitySnowball entitysnowball = new EntitySnowball(entityLiving.world, mc.player);
                                          entitysnowball.shoot(mc.player, mc.player.rotationPitch + 5.0f, mc.player.rotationYaw + 5.0f, 0.0F, 1.5F, 1.0F);
                                          entityLiving.world.spawnEntity(entitysnowball);
                                          Cooldown();
                                          setmun(stack, getmun(stack) - 1);
                                      }
                                  } else {
                                      findammo(mc.player.inventory.getCurrentItem());
                  
                  
                                  }
                              }
                          }
                      }
                      return super.onEntitySwing(entityLiving, stack);
                  }
                  
                  @Override
                  public void addInformation(ItemStack stack,  World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
                      if(!stack.hasTagCompound()){
                          stack.setTagCompound(new NBTTagCompound());
                      }
                      {
                          tooltip.add(getmun(stack) + "/6 munitions");
                      }
                      super.addInformation(stack, worldIn, tooltip, flagIn);
                  }
                  
                  public void registerModels() {
                      Main.proxy.registerItemRenderer(this, 0, "inventory");
                  }
                  

                  }

                  1 réponse Dernière réponse Répondre Citer 0
                  • GwarG Hors-ligne
                    Gwar @robin4002
                    dernière édition par

                    @robin4002 tu en penses quoi robin ?

                    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

                      Je ne sais pas

                      GwarG 1 réponse Dernière réponse Répondre Citer 0
                      • GwarG Hors-ligne
                        Gwar @robin4002
                        dernière édition par

                        @robin4002 car j’ai essayé de voir de regarder mais a chaque fois ça se remet à 0 mais je ne comprend pas pourquoi

                        1 réponse Dernière réponse Répondre Citer 0
                        • robin4002R robin4002 a déplacé ce sujet de Support pour les moddeurs sur
                        • 1 / 1
                        • Premier message
                          Dernier message
                        Design by Woryk
                        ContactMentions Légales

                        MINECRAFT FORGE FRANCE © 2024

                        Powered by NodeBB