Stacking Behaviour - CleverNucleus/data-attributes GitHub Wiki

Stacking Behaviour is a reworked implementation of the 1.17.x "behaviour" key that existed in Attribute Functions. Instead of defining this property as an attribute function however, it now serves as an attribute specific instruction on addition from different sources. That is to say, how do different sources of Armor stack up?

FLAT

The FLAT stacking behaviour describes normal addition and functions as:

current value + adding value = resultant value

For example, you have an Iron Helmet that provides +2 armor and an Iron Chestplate that provides +6. When added together you get 8 armor:

2 + 6 = 8

DIMINISHING

The DIMINISHING stacking behaviour describes a non-linear addition function, and only works for attributes with a minimum value of between -1 and 0, and a maximum value of 1 (e.g. percentage based attributes could use this). The exact maths behind this is slightly complex, but it can be broadly summarised with the following:

resultant value = 1 - ((1 - sourceA) * (1 - sourceB) * ... (1 - sourceN))

For example, you have an Iron Helmet that provides +20% Evasion and an Iron Chestplate that provides +30% Evasion. When added together you would expect 50% Evasion with normal FLAT addition, but with DIMINISHING you get 44% Evasion:

0.44 = 1 - ((1 - 0.2) * (1 - 0.3))

How subtracting works is much the same, but negatives are treated using there absolute values and the result is subtracted from the positive result (above). It should be noted that while this is great for attributes with a range of 0% - 100%, or -100% to 100%, you have to change the resolution of your attribute's value to deal with percentages above 100%. For example, if you wanted a critical strike damage attribute that went from 0% - 500%, you would use attribute values of 0 - 0.5, and then multiply the results accordingly.