From 0cba38ad98a91d595caa7db821e5c3f5b22ff325 Mon Sep 17 00:00:00 2001 From: Edelweiss Date: Tue, 2 Apr 2024 01:15:09 -0500 Subject: [PATCH] Added extra interfaces, renamed JSON objects, instantiated math --- ...teFunction.kt => AttributeFunctionJSON.kt} | 6 ++-- ...teOverride.kt => AttributeOverrideJSON.kt} | 2 +- .../playerex/attributes/json/EntityTypes.kt | 6 ---- .../attributes/json/EntityTypesJSON.kt | 6 ++++ .../playerex/attributes/json/Functions.kt | 6 ---- .../playerex/attributes/json/FunctionsJSON.kt | 6 ++++ .../playerex/attributes/json/Properties.kt | 6 ---- .../attributes/json/PropertiesJSON.kt | 6 ++++ .../attributes/overrides/AttributeFunction.kt | 11 ++++++ .../overrides/ItemEntityAttributeModifiers.kt | 14 ++++++++ .../overrides/PEXEntityAttribute.kt | 34 +++++++++++++++++++ .../overrides/PEXEntityAttributeInstance.kt | 8 +++++ .../attributes/utils/{Enums.kt => enums.kt} | 0 .../playerex/attributes/utils/math.kt | 1 + 14 files changed, 90 insertions(+), 22 deletions(-) rename src/main/kotlin/com/edelweiss/playerex/attributes/json/{AttributeFunction.kt => AttributeFunctionJSON.kt} (85%) rename src/main/kotlin/com/edelweiss/playerex/attributes/json/{AttributeOverride.kt => AttributeOverrideJSON.kt} (98%) delete mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/json/EntityTypes.kt create mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/json/EntityTypesJSON.kt delete mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/json/Functions.kt create mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/json/FunctionsJSON.kt delete mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/json/Properties.kt create mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/json/PropertiesJSON.kt create mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/overrides/AttributeFunction.kt create mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/overrides/ItemEntityAttributeModifiers.kt create mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/overrides/PEXEntityAttribute.kt create mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/overrides/PEXEntityAttributeInstance.kt rename src/main/kotlin/com/edelweiss/playerex/attributes/utils/{Enums.kt => enums.kt} (100%) create mode 100644 src/main/kotlin/com/edelweiss/playerex/attributes/utils/math.kt diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeFunction.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeFunctionJSON.kt similarity index 85% rename from src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeFunction.kt rename to src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeFunctionJSON.kt index 445adf5d..65db7ce6 100644 --- a/src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeFunction.kt +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeFunctionJSON.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable import java.nio.ByteBuffer @Serializable -data class AttributeFunction( +data class AttributeFunctionJSON( /** The behavior associated with the attribute function. */ @SerialName("behaviour") val behavior: FunctionBehavior, @@ -20,9 +20,9 @@ data class AttributeFunction( * Attempts to read the data through a byte array. * This is prone to fail, and will return null if it does. * */ - fun read(array: ByteArray): AttributeFunction? { + fun read(array: ByteArray): AttributeFunctionJSON? { val behavior = (FunctionBehavior::id from array[8]) ?: return null - return AttributeFunction(behavior, ByteBuffer.wrap(array).getDouble()) + return AttributeFunctionJSON(behavior, ByteBuffer.wrap(array).getDouble()) } } diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeOverride.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeOverrideJSON.kt similarity index 98% rename from src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeOverride.kt rename to src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeOverrideJSON.kt index 7ecfec11..30d7d104 100644 --- a/src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeOverride.kt +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/json/AttributeOverrideJSON.kt @@ -18,7 +18,7 @@ import net.minecraft.nbt.NbtCompound //} @Serializable -data class AttributeOverride( +data class AttributeOverrideJSON( private var default: Double, private var min: Double, private var max: Double, diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/json/EntityTypes.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/json/EntityTypes.kt deleted file mode 100644 index 35791cf1..00000000 --- a/src/main/kotlin/com/edelweiss/playerex/attributes/json/EntityTypes.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.edelweiss.playerex.attributes.json - -import kotlinx.serialization.Serializable - -@Serializable -data class EntityTypes(val values: MutableMap>) : DataMerger(values); diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/json/EntityTypesJSON.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/json/EntityTypesJSON.kt new file mode 100644 index 00000000..b4973b24 --- /dev/null +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/json/EntityTypesJSON.kt @@ -0,0 +1,6 @@ +package com.edelweiss.playerex.attributes.json + +import kotlinx.serialization.Serializable + +@Serializable +data class EntityTypesJSON(val values: MutableMap>) : DataMerger(values); diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/json/Functions.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/json/Functions.kt deleted file mode 100644 index a364c2dc..00000000 --- a/src/main/kotlin/com/edelweiss/playerex/attributes/json/Functions.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.edelweiss.playerex.attributes.json - -import kotlinx.serialization.Serializable - -@Serializable -data class Functions(val values: MutableMap>) : DataMerger(values); \ No newline at end of file diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/json/FunctionsJSON.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/json/FunctionsJSON.kt new file mode 100644 index 00000000..26f30724 --- /dev/null +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/json/FunctionsJSON.kt @@ -0,0 +1,6 @@ +package com.edelweiss.playerex.attributes.json + +import kotlinx.serialization.Serializable + +@Serializable +data class FunctionsJSON(val values: MutableMap>) : DataMerger(values); \ No newline at end of file diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/json/Properties.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/json/Properties.kt deleted file mode 100644 index 0a147f72..00000000 --- a/src/main/kotlin/com/edelweiss/playerex/attributes/json/Properties.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.edelweiss.playerex.attributes.json - -import kotlinx.serialization.Serializable - -@Serializable -data class Properties(val values: MutableMap>) : DataMerger(values) diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/json/PropertiesJSON.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/json/PropertiesJSON.kt new file mode 100644 index 00000000..8b040215 --- /dev/null +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/json/PropertiesJSON.kt @@ -0,0 +1,6 @@ +package com.edelweiss.playerex.attributes.json + +import kotlinx.serialization.Serializable + +@Serializable +data class PropertiesJSON(val values: MutableMap>) : DataMerger(values) diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/AttributeFunction.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/AttributeFunction.kt new file mode 100644 index 00000000..7492cb09 --- /dev/null +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/AttributeFunction.kt @@ -0,0 +1,11 @@ +package com.edelweiss.playerex.attributes.overrides + +import com.edelweiss.skillattributes.enums.FunctionBehavior + +interface AttributeFunction { + /** Behavior associated with this function. */ + fun behavior(): FunctionBehavior + + /** The value provided by the function. */ + fun value(): Double +} \ No newline at end of file diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/ItemEntityAttributeModifiers.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/ItemEntityAttributeModifiers.kt new file mode 100644 index 00000000..483692b7 --- /dev/null +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/ItemEntityAttributeModifiers.kt @@ -0,0 +1,14 @@ +package com.edelweiss.playerex.attributes.overrides + +import com.google.common.collect.HashMultimap +import com.google.common.collect.Multimap +import net.minecraft.entity.EquipmentSlot +import net.minecraft.entity.attribute.EntityAttribute +import net.minecraft.entity.attribute.EntityAttributeModifier +import net.minecraft.item.ItemStack + +/** Meant to be implemented in the `Item` class. */ +interface ItemEntityAttributeModifiers { + /** Provides a mutable attribute modifier `MultiMap` so items can have dynamically changing modifiers based on the NBT. */ + fun get(stack: ItemStack, slot: EquipmentSlot): Multimap = HashMultimap.create() +} \ No newline at end of file diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/PEXEntityAttribute.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/PEXEntityAttribute.kt new file mode 100644 index 00000000..51727d0e --- /dev/null +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/PEXEntityAttribute.kt @@ -0,0 +1,34 @@ +package com.edelweiss.playerex.attributes.overrides + +import com.edelweiss.skillattributes.enums.StackingFormula + +/** + * An interface meant for `EntityAttribute` to implement in a mixin. + * + * This allows for access provided by the attributes system. + * */ +interface PEXEntityAttribute { + /** The minimum value of the attribute. */ + fun min(): Double + + /** The maximum value of the attribute. */ + fun max(): Double + + /** The attributes' stacking formula. */ + fun formula(): StackingFormula + + /** Immutable map of the parents attached to the attribute. */ + fun parents(): Map + + /** Immutable map of the children attached to the attribute. */ + fun children(): Map + + /** Immutable collection of the property keys attached to the attribute. */ + fun properties(): Collection + + /** Checks whether this attribute has the input property key. */ + fun hasProperty(property: String): Boolean + + /** Tries to get the attributes property value assigned to the input property key. */ + fun getProperty(): String +} \ No newline at end of file diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/PEXEntityAttributeInstance.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/PEXEntityAttributeInstance.kt new file mode 100644 index 00000000..868b5a7f --- /dev/null +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/overrides/PEXEntityAttributeInstance.kt @@ -0,0 +1,8 @@ +package com.edelweiss.playerex.attributes.overrides + +import java.util.UUID + +interface PEXEntityAttributeInstance { + /** Changes the value of the input modifier if in existence, and updates the instance & children. */ + fun updateModifier(uuid: UUID, value: Double) +} \ No newline at end of file diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/utils/Enums.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/utils/enums.kt similarity index 100% rename from src/main/kotlin/com/edelweiss/playerex/attributes/utils/Enums.kt rename to src/main/kotlin/com/edelweiss/playerex/attributes/utils/enums.kt diff --git a/src/main/kotlin/com/edelweiss/playerex/attributes/utils/math.kt b/src/main/kotlin/com/edelweiss/playerex/attributes/utils/math.kt new file mode 100644 index 00000000..95765218 --- /dev/null +++ b/src/main/kotlin/com/edelweiss/playerex/attributes/utils/math.kt @@ -0,0 +1 @@ +package com.edelweiss.playerex.attributes.utils