MFF

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

    NBT Tags, ces trucs que je ne comprends pas.

    Planifier Épinglé Verrouillé Déplacé Sans suite
    1.11.x
    17 Messages 3 Publieurs 3.6k 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.
    • robin4002R En ligne
      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
      dernière édition par

      nbt.getBoolean(“xxx”) renvoies false s’il n’a jamais été défini.

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

        @‘robin4002’:

        nbt.getBoolean(“xxx”) renvoies false s’il n’a jamais été défini.

        Yep en effet, mais je dois être bête car si je fais comme tu me dis ca remet toujours à false Oo

        @Override
        public ActionResult <itemstack>onItemRightClick(World world, EntityPlayer player, EnumHand hand) //Right click action.
        {
        if (player.isSneaking()) //If player is sneaking.
        {
        if (!world.isRemote) //Server side.
        {
        
        ItemStack card = player.getHeldItem(hand);//Creating an ItemStack for the item held in hand.
        NBTTagCompound nbt = card.getTagCompound();
        if(nbt == null){ nbt = new NBTTagCompound(); }
        nbt.getBoolean("owned");
        if(nbt.getBoolean("owned") == true)//If Owned is on True, it means it has already been right clicked.
        {
        player.sendMessage(new TextComponentString("You can't create an account on an already owned card."));
        }
        else
        {
        boolean owned = true; //We pass owned at true
        int deposited = 0; //We create new account with 0 as deposited since it's new.
        String owner = player.getName().toString(); //Take player name has owner variable.
        world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); //Play a sound that alert everybody that a credit card was created.
        nbt.setString("owner", owner);
        nbt.setBoolean("owned", owned);
        System.out.println(nbt.getString("owner")); //Print owner name for debug
        System.out.println(nbt.getBoolean("owned")); //Print owned name for debug
        
        return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(this)); //Return a success.
        }
        }
        }
        return new ActionResult(EnumActionResult.PASS, new ItemStack(this)); //Return a pass.
        }
        
        ```</itemstack>

        Oui ce gif est drôle.

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

          Tu n’as plus le setTagCompound du début. Je pense que ça vient de là.

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

            @Plaigon:

            Tu n’as plus le setTagCompound du début. Je pense que ça vient de là.

            Tu veut dire ça ? Car j’ai mis et toujours rien 😕

            card.setTagCompound(nbt);
            

            Oui ce gif est drôle.

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

              Tu l’as mis où ?

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

                @‘robin4002’:

                Tu l’as mis où ?

                Je l’ai mis dans le else.

                else
                {
                boolean owned = true; //We pass owned at true
                int deposited = 0; //We create new account with 0 as deposited since it's new.
                String owner = player.getName().toString(); //Take player name has owner variable.
                world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); //Play a sound that alert everybody that a credit card was created.
                nbt.setString("owner", owner); // Set variable at owner.
                nbt.setBoolean("owned", owned); // Set variable at owned.
                
                card.setTagCompound(nbt); // Set TagCompound of card item stack.
                return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(this)); //Return a success.
                }
                ``` Mais j'ai aussi essayer de le mettre dans le ```java
                if (!world.isRemote) //Server side.
                {}
                

                EDIT : Voici un débug avec

                [13:09:31] [Server thread/INFO]: [STDOUT]: null
                [13:09:31] [Server thread/INFO]: [STDOUT]: {}
                [13:09:31] [Server thread/INFO]: [STDOUT]: {}
                [13:09:31] [Server thread/INFO]: [STDOUT]: {owner:"Legrandfifou",owned:1b}
                
                if (!world.isRemote) //Server side.
                {
                
                ItemStack card = player.getHeldItem(hand);//Creating an ItemStack for the item held in hand.
                NBTTagCompound nbt = card.getTagCompound();
                **System.out.println(nbt);**
                if(nbt == null){ nbt = new NBTTagCompound(); }
                **System.out.println(nbt);**
                nbt.getBoolean("owned");
                card.setTagCompound(nbt);
                **System.out.println(nbt);**
                if(nbt.getBoolean("owned") == true)//If Owned is on True, it means it has already been right clicked.
                {
                player.sendMessage(new TextComponentString("You can't create an account on an already owned card."));
                System.out.println(nbt.getBoolean("owned"));
                }
                else
                {
                boolean owned = true; //We pass owned at true
                int deposited = 0; //We create new account with 0 as deposited since it's new.
                String owner = player.getName().toString(); //Take player name has owner variable.
                world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); //Play a sound that alert everybody that a credit card was created.
                nbt.setString("owner", owner); // Set variable at owner.
                nbt.setBoolean("owned", owned); // Set variable at owned.
                System.out.println(nbt);
                return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(this)); //Return a success.
                }
                **System.out.println(nbt);**
                card.setTagCompound(nbt);
                **System.out.println(nbt);**
                }
                

                On peut voir que après le nbt.getBoolean(“owned”) il n’affiche rien pour lui il n’y a pas de nbt tag …

                Oui ce gif est drôle.

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

                  UP, du coup la il me faut de l’aide car je ne comprend pas trop pourquoi ça ne marche pas 😕

                  Oui ce gif est drôle.

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

                    Premièrement, tu dois finir ta fonction avec un return, or à la fin, on observe quelque println.
                    Deuxièmement, à chaque clic droit tu reset le tag compound de ton itemstack avec une nouvelle variable vide. Le setTagCompound(nbt), doit être placé uniquement dans le cas où ton itemstack n’en possède pas, donc dans le if(itemstack.getTagCompound() == null).
                    Ensuite ceci : nbt.getBoolean(“owned”); sert strictement à rien (ligne 10). Ensuite ta variable owned, comme dit précédemment ne doit pas toujours donner true, mais soit donner la valeur précédente (lors du dernier clic droit, logique), ou true si il s’agit du premier clic droit. Donc avec une condition ternaire, cela devrait ressebler à ceci :
                    boolean owned = itemstack.getTagCompound().hasKey(“owned”) ? itemstack.getTagCompound.getBoolean(“owned”) : true;

                    Sinon concernant le reste, ça m’a l’air bon, auquel cas robin, ou un autre membre, revérifiera !

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

                      Non, ça variable owned doit bien être sur false par défaut.
                      Donc un simple boolean owned = nbt.getBoolean(“owned”) est ok.
                      Par contre le code qui remet le tag doit être avant le return.

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

                        Du coup je dois avouer que je suis un peu perdu j’ai compris la condition ternaire mais je ne vois toujours aucun changement, le boolean est bien a false au départ, mais c’est cette histoire de card.setTagCompound que je ne comprend pas en fait.

                        @Override
                        public ActionResult <itemstack>onItemRightClick(World world, EntityPlayer player, EnumHand hand) //Right click action.
                        {
                        if (player.isSneaking()) //If player is sneaking.
                        {
                        if (!world.isRemote) //Server side.
                        {
                        
                        ItemStack card = player.getHeldItem(hand); //Creating an ItemStack for the item held in hand.
                        NBTTagCompound nbt = card.getTagCompound();
                        if(nbt == null)
                        {
                        nbt = new NBTTagCompound();
                        card.setTagCompound(nbt);
                        }
                        
                        nbt.getBoolean("owned");
                        System.out.println(nbt.getBoolean("owned"));
                        if(nbt.getBoolean("owned") == true)//If Owned is on True, it means it has already been right clicked.
                        {
                        player.sendMessage(new TextComponentString("You can't create an account on an already owned card."));
                        }
                        else
                        {
                        boolean owned = card.getTagCompound().hasKey("owned") ? card.getTagCompound().getBoolean("owned") : true; //We check if card hasKey("owned"), if yes we just take the value of the "owned" if not, we pass it at True.
                        int deposited = 0; //We create new account with 0 as deposited since it's new.
                        String owner = player.getName().toString(); //Take player name has owner variable.
                        world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); //Play a sound that alert everybody that a credit card was created.
                        nbt.setString("owner", owner); // Set variable at owner.
                        nbt.setBoolean("owned", owned); // Set variable at owned.
                        return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(this)); //Return a success.
                        }
                        }
                        return new ActionResult(EnumActionResult.FAIL, new ItemStack(this)); //Return a pass.
                        }
                        
                        return new ActionResult(EnumActionResult.PASS, new ItemStack(this)); //Return a pass.
                        }
                        
                        

                        Merci de votre aide en tout cas :)</itemstack>

                        Oui ce gif est drôle.

                        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