-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiplier based attribute functions
+Added multiplier based attribute functions. Why: among other things such as being a requested enhancement, flat Attack Speed buffs are too OP and really need a multiplier type mechanic. How: when defining attribute functions in JSON, instead of the value being a number/double, it is an object containing aforementioned number as well as a FunctionBehaviour reference. This lets the game know how the value should be used. This is a breaking change, hence the buff in middle version number. All mods/datapacks will need to adjust their data JSON accordingly.
- Loading branch information
1 parent
aba3910
commit c04e106
Showing
13 changed files
with
175 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/github/clevernucleus/dataattributes/api/attribute/FunctionBehaviour.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.clevernucleus.dataattributes.api.attribute; | ||
|
||
/** | ||
* @since 1.3.0 | ||
* @author CleverNucleus | ||
*/ | ||
public enum FunctionBehaviour { | ||
/** Addition of values as defined by the parent attribute. Equivalent of EntityAttributeModifier.Operation.ADDITION. */ | ||
ADDITION((byte)0), | ||
/** Multiplication of parent attribute. Equivalent of EntityAttributeModifier.Operation.MULTIPLY_TOTAL. */ | ||
MULTIPLY((byte)1); | ||
|
||
private final byte id; | ||
|
||
private FunctionBehaviour(final byte id) { | ||
this.id = id; | ||
} | ||
|
||
public static FunctionBehaviour of(final byte id) { | ||
return switch(id) { | ||
case 0 -> ADDITION; | ||
case 1 -> MULTIPLY; | ||
default -> ADDITION; | ||
}; | ||
} | ||
|
||
public byte id() { | ||
return this.id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(this.id); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/github/clevernucleus/dataattributes/api/attribute/IAttributeFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.clevernucleus.dataattributes.api.attribute; | ||
|
||
/** | ||
* @since 1.3.0 | ||
* @author CleverNucleus | ||
*/ | ||
public interface IAttributeFunction { | ||
|
||
/** | ||
* @return The FunctionBehaviour associated with this attribute function. | ||
*/ | ||
FunctionBehaviour behaviour(); | ||
|
||
/** | ||
* @return The value associated with this attribute function. | ||
*/ | ||
double value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/github/clevernucleus/dataattributes/json/AttributeFunctionJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.clevernucleus.dataattributes.json; | ||
|
||
import com.github.clevernucleus.dataattributes.api.attribute.FunctionBehaviour; | ||
import com.github.clevernucleus.dataattributes.api.attribute.IAttributeFunction; | ||
import com.github.clevernucleus.dataattributes.api.util.Maths; | ||
import com.google.gson.annotations.Expose; | ||
|
||
public final class AttributeFunctionJson implements IAttributeFunction { | ||
@Expose private FunctionBehaviour behaviour; | ||
@Expose private double value; | ||
|
||
private AttributeFunctionJson() {} | ||
|
||
public static AttributeFunctionJson read(byte[] byteArray) { | ||
AttributeFunctionJson functionTypeJson = new AttributeFunctionJson(); | ||
functionTypeJson.behaviour = FunctionBehaviour.of(byteArray[8]); | ||
functionTypeJson.value = Maths.byteArrayToDouble(byteArray); | ||
return functionTypeJson; | ||
} | ||
|
||
public byte[] write() { | ||
byte[] byteArray = Maths.doubleToByteArray(this.value, 9); | ||
byteArray[8] = this.behaviour.id(); | ||
return byteArray; | ||
} | ||
|
||
@Override | ||
public FunctionBehaviour behaviour() { | ||
return this.behaviour; | ||
} | ||
|
||
@Override | ||
public double value() { | ||
return this.value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.