Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5890

Access to Entity type specific default attributes

    XMLWordPrintable

Details

    • New Feature
    • Resolution: Unresolved
    • Minor
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-ad703da-e2403a3 (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)
    • Yes

    Description

      I previously assumed that I would be able to reset a Player's attributes to their default via something like this:

      for (Attribute attribute : Attribute.values()) {
          AttributeInstance attributeInstance = player.getAttribute(attribute);
          if (attributeInstance != null) {
              for (AttributeModifier modifier : attributeInstance.getModifiers()) {
                  attributeInstance.removeModifier(modifier);
              }
              attributeInstance.setBaseValue(attributeInstance.getDefaultValue());
          }
      }
      

      I.e. clearing all modifiers and resetting the the base value to the default. (I my case the player's inventory is guaranteed to be empty, so there should be no issue with removing modifiers for items)

      However, as it turns out attributeInstance.getDefaultValue() doesn't actually return the player's default base value for this attribute (which should be 0.1) but the 'global default' for this attribute (0.7), which different types of entities (such as players) replace with their own default value during the setup of their attributes.

      This has gone unnoticed by me before. However, in MC 1.16 the player's movement speed is now controlled not only by the value of the player's walkingSpeed property, but the value of the movement speed attribute. So this has broken now.

      Would it be possible expose these entity-type specific default values?
      In MC 1.16 this might have become easier to do, since there is now a class 'AttributeDefaults' which provides lookups for the default attributes for a given entity type.

      Attachments

        Activity

          People

            Unassigned Unassigned
            blablubbabc blablubbabc
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: