MFF

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

    Modifier les attribut d'un item sans alterer les attributs deja present

    Planifier Épinglé Verrouillé Déplacé Résolu 1.12.x
    1.12.2
    4 Messages 1 Publieurs 304 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.
    • P Hors-ligne
      PlagueZ
      dernière édition par

      Bonjour,

      je cherche a modifier les attributs d’un item sans altérer ceux présents pour le moment j’ai essayer ca

              ItemStack sword = new ItemStack(ItemInit.SWORD);
      		sword.addAttributeModifier((SharedMonsterAttributes.ATTACK_DAMAGE).getName(),new AttributeModifier(UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"), "Weapon boost", 100, 0),EntityEquipmentSlot.MAINHAND);
      		sword.addAttributeModifier((SharedMonsterAttributes.ATTACK_DAMAGE).getName(),new AttributeModifier(UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"), "Weapon boost", 100, 0),EntityEquipmentSlot.MAINHAND);
              			GameRegistry.addSmelting(new ItemStack(ItemInit.SWORD), sword, 0.4F);
              
      

      j’avoue ne pas avoir coder depuis la 1.7.10 et le soucis c’est que je comprend pas tellement le système des attribut a la base je voudrait ajouter un bonus en % a mon arme avec :

      AttributeModifier(UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"), "Weapon boost", 0.05D, 1),EntityEquipmentSlot.MAINHAND); //opertionIn set to 1
      

      problème lorsque je fait ça les dégâts de l’arme passe a 1.0D et applique le % sur 1.0D je comprend pas pourquoi la Multimap des attributs se vide a chaque ajouts / altération de paramètre

      Si quelqu’un peut éclairer ma lanterne

      “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

        Bon problème résolut pour tout ceux qui cherche comment on fait petit cadeau c’était pas de tout repos de comprendre comment fonctionnait tout ca 😜

        import java.util.UUID;
        
        import com.raiden.virusz.items.tools.ToolSword;
        
        import net.minecraft.entity.SharedMonsterAttributes;
        import net.minecraft.entity.ai.attributes.AttributeModifier;
        import net.minecraft.entity.ai.attributes.IAttribute;
        import net.minecraft.inventory.EntityEquipmentSlot;
        import net.minecraft.item.ItemStack;
        import net.minecraft.nbt.NBTTagCompound;
        import net.minecraft.nbt.NBTTagList;
        
        
        
        public class Upgrades 
        
        {
        
        	public final static UUID MODIFIER_UUID = UUID.randomUUID();
        
        
        	public static ItemStack upgrade(ToolSword item,EntityEquipmentSlot slot ,double upgradeDamage, double upgradeSpeed) {
        
        			double Damage = 4 + item.getAttackDamage();
        			double Speed = item.getAttackSpeed();
        			AttributeModifier attackModifier = new AttributeModifier(MODIFIER_UUID, "Weapon Upgrade", upgradeDamage + Damage, 0);
        			AttributeModifier speedModifier = new AttributeModifier(MODIFIER_UUID, "Weapon Upgrade", upgradeSpeed + Speed, 0);
        			NBTTagCompound modifierATQ = writeAttributeModifierToNBT(SharedMonsterAttributes.ATTACK_DAMAGE, attackModifier, EntityEquipmentSlot.MAINHAND);
        			NBTTagCompound modifierSpd = writeAttributeModifierToNBT(SharedMonsterAttributes.ATTACK_SPEED, speedModifier, EntityEquipmentSlot.MAINHAND);
        			NBTTagCompound stackTagCompound = new NBTTagCompound();
        			NBTTagList list = new NBTTagList();
        			list.appendTag(modifierATQ);
        			list.appendTag(modifierSpd);
        			stackTagCompound.setTag("AttributeModifiers", list);
        			ItemStack stack = new ItemStack(item);
        			stack.setTagCompound(stackTagCompound);
        		return stack;
        	}
        
        	
        
        	private static NBTTagCompound writeAttributeModifierToNBT(IAttribute attribute, AttributeModifier modifier, EntityEquipmentSlot slot) {
        		NBTTagCompound nbttagcompound = new NBTTagCompound();
        		nbttagcompound.setString("AttributeName", attribute.getName());
        		nbttagcompound.setString("Name", modifier.getName());
        		nbttagcompound.setDouble("Amount", modifier.getAmount());
        		nbttagcompound.setInteger("Operation", modifier.getOperation());
        		nbttagcompound.setString("Slot", slot.getName());
        		nbttagcompound.setLong("UUIDMost", modifier.getID().getMostSignificantBits());
        		nbttagcompound.setLong("UUIDLeast", modifier.getID().getLeastSignificantBits());
        		return nbttagcompound;
        	}
        
        
        

        pour l’appel je le fait de cette façon

        //usage Upgrades.upgrade(item, slot, +Damage, +SpeedReduction);
        		ItemStack sword = Upgrades.upgrade(ItemInit.SWORD, EntityEquipmentSlot.MAINHAND, 12.0D, 0.0D);
        			GameRegistry.addSmelting(new ItemStack(ItemInit.SWORD_RUBY), sword, 0.4F);
        

        “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

          je pense que il faut récupérer les stats de l’arme avant de la modifier sinon ça remplace la multimap des attributs de départ et ça modifie pas les stats deja presente j’ai essayé quelques trucs:

                  sword.getAttributeModifiers(EntityEquipmentSlot.MAINHAND).put("generic.attackDamage", new AttributeModifier(UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"), "Weapon modifier", 15.0D, 0));
          

          “generic.attackDamage” a été trouver grace a un print de la map de l’item avec

          sword.getAttributeModifiers(EntityEquipmentSlot.MAINHAND).keys()
          

          j’ai aussi essayer de clear() ou de remove(“generic.attackDamage”) mais ca n’a aucun effet par contre si je met un des item qui a les stats effacée des tentatives faites avant ca ca remet les stats normale en retirant le bonus appliqué a mon arme 🤔

          je comprend vraiment pas le système des attributs ca semble être la pour faciliter les modification des stats des items dans le jeu mais c’est pas super intuitif si quelqu’un met le doigt sur la source de mon problème il peut prendre ce cookie ==>🍪

          “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

            je suis arriver a quelques chose qui marche

            public class Upgrades 
            
            {
            
            	public final static UUID MODIFIER_UUID = UUID.fromString("294093da-54f0-4c1b-9dbb-13b77534a84c");
            
            
            	public static ItemStack upgrade(ToolSword item,EntityEquipmentSlot slot ,double upgradeDamage, double upgradeSpeed) {
            
            			double Damage = 4 + item.getAttackDamage();
            			double Speed = item.getAttackSpeed();
            			AttributeModifier attackModifier = new AttributeModifier(MODIFIER_UUID, "Weapon Upgrade", upgradeDamage + Damage, 0);
            			AttributeModifier speedModifier = new AttributeModifier(MODIFIER_UUID, "Weapon Upgrade", upgradeSpeed + Speed, 0);
            			NBTTagCompound modifierATQ = writeAttributeModifierToNBT(SharedMonsterAttributes.ATTACK_DAMAGE, attackModifier);
            			NBTTagCompound modifierSpd = writeAttributeModifierToNBT(SharedMonsterAttributes.ATTACK_SPEED, speedModifier);
            			NBTTagCompound stackTagCompound = new NBTTagCompound();
            			NBTTagList list = new NBTTagList();
            			list.appendTag(modifierATQ);
            			list.appendTag(modifierSpd);
            			stackTagCompound.setTag("AttributeModifiers", list);
            			ItemStack stack = new ItemStack(item);
            			stack.setTagCompound(stackTagCompound);
            		return stack;
            	}
            
            	
            
            	private static NBTTagCompound writeAttributeModifierToNBT(IAttribute attribute, AttributeModifier modifier) {
            		NBTTagCompound nbttagcompound = new NBTTagCompound();
            		nbttagcompound.setString("AttributeName", attribute.getName());
            		nbttagcompound.setString("Name", modifier.getName());
            		nbttagcompound.setDouble("Amount", modifier.getAmount());
            		nbttagcompound.setInteger("Operation", modifier.getOperation());
            		nbttagcompound.setLong("UUIDMost", modifier.getID().getMostSignificantBits());
            		nbttagcompound.setLong("UUIDLeast", modifier.getID().getLeastSignificantBits());
            		return nbttagcompound;
            	}
            
            }
            

            Me reste un problème ça applique les modifier sur toutes les categorie onFeet, onHead, mainhand ofhand etc

            je trouve pas comment utiliser ou définit le slot sur le quel écrire l’upgrade

            “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

              Bon problème résolut pour tout ceux qui cherche comment on fait petit cadeau c’était pas de tout repos de comprendre comment fonctionnait tout ca 😜

              import java.util.UUID;
              
              import com.raiden.virusz.items.tools.ToolSword;
              
              import net.minecraft.entity.SharedMonsterAttributes;
              import net.minecraft.entity.ai.attributes.AttributeModifier;
              import net.minecraft.entity.ai.attributes.IAttribute;
              import net.minecraft.inventory.EntityEquipmentSlot;
              import net.minecraft.item.ItemStack;
              import net.minecraft.nbt.NBTTagCompound;
              import net.minecraft.nbt.NBTTagList;
              
              
              
              public class Upgrades 
              
              {
              
              	public final static UUID MODIFIER_UUID = UUID.randomUUID();
              
              
              	public static ItemStack upgrade(ToolSword item,EntityEquipmentSlot slot ,double upgradeDamage, double upgradeSpeed) {
              
              			double Damage = 4 + item.getAttackDamage();
              			double Speed = item.getAttackSpeed();
              			AttributeModifier attackModifier = new AttributeModifier(MODIFIER_UUID, "Weapon Upgrade", upgradeDamage + Damage, 0);
              			AttributeModifier speedModifier = new AttributeModifier(MODIFIER_UUID, "Weapon Upgrade", upgradeSpeed + Speed, 0);
              			NBTTagCompound modifierATQ = writeAttributeModifierToNBT(SharedMonsterAttributes.ATTACK_DAMAGE, attackModifier, EntityEquipmentSlot.MAINHAND);
              			NBTTagCompound modifierSpd = writeAttributeModifierToNBT(SharedMonsterAttributes.ATTACK_SPEED, speedModifier, EntityEquipmentSlot.MAINHAND);
              			NBTTagCompound stackTagCompound = new NBTTagCompound();
              			NBTTagList list = new NBTTagList();
              			list.appendTag(modifierATQ);
              			list.appendTag(modifierSpd);
              			stackTagCompound.setTag("AttributeModifiers", list);
              			ItemStack stack = new ItemStack(item);
              			stack.setTagCompound(stackTagCompound);
              		return stack;
              	}
              
              	
              
              	private static NBTTagCompound writeAttributeModifierToNBT(IAttribute attribute, AttributeModifier modifier, EntityEquipmentSlot slot) {
              		NBTTagCompound nbttagcompound = new NBTTagCompound();
              		nbttagcompound.setString("AttributeName", attribute.getName());
              		nbttagcompound.setString("Name", modifier.getName());
              		nbttagcompound.setDouble("Amount", modifier.getAmount());
              		nbttagcompound.setInteger("Operation", modifier.getOperation());
              		nbttagcompound.setString("Slot", slot.getName());
              		nbttagcompound.setLong("UUIDMost", modifier.getID().getMostSignificantBits());
              		nbttagcompound.setLong("UUIDLeast", modifier.getID().getLeastSignificantBits());
              		return nbttagcompound;
              	}
              
              
              

              pour l’appel je le fait de cette façon

              //usage Upgrades.upgrade(item, slot, +Damage, +SpeedReduction);
              		ItemStack sword = Upgrades.upgrade(ItemInit.SWORD, EntityEquipmentSlot.MAINHAND, 12.0D, 0.0D);
              			GameRegistry.addSmelting(new ItemStack(ItemInit.SWORD_RUBY), sword, 0.4F);
              

              “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

              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