Important: This section is now outdated and unsupported. Click here for the latest release.
Structure and Overview
Data Attributes includes an API package, located at com.github.clevernucleus.dataattributes.api
and contains the following:
📂api
┣📂attribute
┃ ┣📄IEntityAttribute.java interface
┃ ┣📄IEntityAttributeInstance.java interface
┃ ┣📄IItemEntityAttributeModifiers.java interface
┃ ┗📄StackingBehaviour.java enum
┃
┣📂event
┃ ┣📂client
┃ ┃ ┗📄ClientSyncedEvent.java class
┃ ┃
┃ ┣📄EntityAttributeModifiedEvents.java class
┃ ┣📄ItemStackCreatedEvent.java class
┃ ┗📄ServerSyncedEvent.java class
┃
┣📂util
┃ ┣📄ItemFields.java class
┃ ┣📄Maths.java class
┃ ┣📄RandDistribution.java class
┃ ┗📄VoidConsumer.java interface
┃
┗📄API.java class
API Content
The following subsections detail every method/field in each java class located in the api
package.
1. attribute.IEntityAttribute.java
Modifiers and Type | Method/Field and Description |
---|---|
double |
minValue() Returns the attribute’s minimum value. |
double |
maxValue() Returns the attribute’s maximum value. |
StackingBehaviour |
stackingBehaviour() Returns the attribute’s stacking behaviour enum type. |
Map<IEntityAttribute, Double> |
children() Returns an immutable map of the function-children attached to this attribute. |
Collection<String> |
properties() Returns an immutable collection of the properties’ keys attached to this attribute. |
boolean |
hasProperty(String property) Returns true if this attribute has the input property key, false if not or if the input is null. |
String |
getProperty(String property) Returns the attribute’s property value mapped to the input key. If it does not exist or is null, returns "" . |
2. attribute.IEntityAttributeInstance.java
Modifiers and Type | Method/Field and Description |
---|---|
void |
updateModifier(UUID uuid, double value) Changes the value of the input modifier (if it exists) and updates the instance and all children. |
3. attribute.IItemAttributeModifiers.java
Modifiers and Type | Method/Field and Description |
---|---|
default Multimap<EntityAttribute, EntityAttributeModifier> |
getAttributeModifiers(ItemStack stack, EquipmentSlot slot) This method provides a mutable attribute modifier multimap so that items can have dynamically changing modifiers based on nbt. By default returns an empty HashMultimap . |
4. attribute.StackingBehaviour.java
Modifiers and Type | Method/Field and Description |
---|---|
public static final StackingBehaviour |
FLAT Flat/normal stacking behaviour. |
public static final StackingBehaviour |
DIMINISHING Flat/normal stacking behaviour. |
public byte |
id() Returns the byte id of the behaviour enum. |
public double |
result(double current, double input) Returns the inputs through the correct function for the specific behaviour type. |
public static StackingBehaviour |
of(byte id) Takes a byte id and retusn the corresponding behaviour type. |
5. event.client.ClientSyncedEvent.java
Modifiers and Type | Method/Field and Description |
---|---|
public static final Event<Synced> |
EVENT Provides a hook to the client, AFTER it has received server-side packets and synced all Data Attribute’s relevant data, but BEFORE the player exists (i.e. during login). |
public interface |
Synced {…} Nested functional interface for EVENT . |
6. event.EntityAttributeModifiedEvents.java
Modifiers and Type | Method/Field and Description |
---|---|
public static final Event<Modified> |
MODIFIED Fires when the value of an attribute instance has been modified, either by adding/removing a modifier or changing the value of a modifier. |
public static final Event<Clamp> |
CLAMPED Fires after the attribute instance value is calculated, but before it is output. This offers one last chance to alter the value in some way (for example round a decimal to an integer). |
public interface |
Modified {…} Nested functional interface for MODIFIED . |
public interface |
Clamp {…} Nested functional interface for CLAMPED . |
7. event.ItemStackCreatedEvent.java
Modifiers and Type | Method/Field and Description |
---|---|
public static final Event<Created> |
EVENT Offers a hook into ItemStack constructor, allowing nbt data to be attached to stacks on creation. |
public interface |
Created {…} Nested functional interface for EVENT . |
8. event.ServerSyncedEvent.java
Modifiers and Type | Method/Field and Description |
---|---|
public static final Event<Synced> |
EVENT Provides a hook to the server, AFTER it has sent packets to the client and synced all Data Attribute’s relevant data, but BEFORE the player exists (i.e. during login). |
public interface |
Synced {…} Nested functional interface for EVENT . |
9. util.ItemFields.java
Modifiers and Type | Method/Field and Description |
---|---|
public static UUID |
attackDamageModifierID() Returns Item#ATTACK_DAMAGE_MODIFIER_ID . |
public static UUID |
attackSpeedModifierID() Returns Item#ATTACK_SPEED_MODIFIER_ID . |
10. util.Maths.java
Modifiers and Type | Method/Field and Description |
---|---|
public static Map<K, V> |
enumLookupMap(V[] values, Function<V, K> mapping) Creates a static lookup map for the input enum#values implementation. |
public static float |
parse(String string) Parses a string to a float. If it cannot be parsed, returns 0F . |
11. util.RandDistribution.java
Modifiers and Type | Method/Field and Description |
---|---|
public |
RandDistribution(T fallback) Constructor. |
public void |
add(T input, float weight) Adds to the internal inventory of the distributor. |
public T |
getDistributedRandom() Returns a randomly distributed and weighted result. |
12. util.VoidConsumer.java
Modifiers and Type | Method/Field and Description |
---|---|
void |
accept() A functional interface equivalent to a Consumer, but with no parameters. |
13. DataAttributesAPI.java
Modifiers and Type | Method/Field and Description |
---|---|
public static final String |
MODID The mod id. |
public static Supplier<EntityAttribute> |
getAttribute(Identifier registryKey) Returns a Supplier getting the registered attribute assigned to the input key. Uses a supplier because attributes added through json are null until datapacks are loaded/synced to the client, so static initialisation would not work. |
public static boolean |
checkHasAttribute(LivingEntity entity, ItemStack stack, EquipmentSlot slot) Checks to see if the entity has the attributes required of hte itemStack’s attribute modifiers; returns true if so, false if not. |
public static T |
ifPresent(LivingEntity entity, Supplier<EntityAttribute> attribute, T fallback, Function<Float, T> function) Allows for Optional-like use of attributes that may or may not exist all the time. This is the correct way of getting and using values from attributes loaded by datapacks. If the entity is not null and the input attribute exists, and the entity has the input attribute, passes and returns the input function. Otherwise, returns the fallback input. |