Skip to content

Commit

Permalink
Added extra interfaces, renamed JSON objects, instantiated math
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Apr 2, 2024
1 parent a92daeb commit 0cba38a
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.edelweiss.playerex.attributes.json

import kotlinx.serialization.Serializable

@Serializable
data class EntityTypesJSON(val values: MutableMap<String, MutableMap<String, Double>>) : DataMerger<String, String, Double>(values);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.edelweiss.playerex.attributes.json

import kotlinx.serialization.Serializable

@Serializable
data class FunctionsJSON(val values: MutableMap<String, MutableMap<String, AttributeFunctionJSON>>) : DataMerger<String, String, AttributeFunctionJSON>(values);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.edelweiss.playerex.attributes.json

import kotlinx.serialization.Serializable

@Serializable
data class PropertiesJSON(val values: MutableMap<String, MutableMap<String, String>>) : DataMerger<String, String, String>(values)
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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<EntityAttribute, EntityAttributeModifier> = HashMultimap.create()
}
Original file line number Diff line number Diff line change
@@ -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<PEXEntityAttribute, AttributeFunction>

/** Immutable map of the children attached to the attribute. */
fun children(): Map<PEXEntityAttribute, AttributeFunction>

/** Immutable collection of the property keys attached to the attribute. */
fun properties(): Collection<String>

/** 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
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.edelweiss.playerex.attributes.utils

0 comments on commit 0cba38a

Please sign in to comment.