We do not save ItemMeta between method calls, so getting/setting an NBT tag is taking up too many resources. This is because ItemStack#getItemMeta
In a lot of our handlers and events, we pass the same 3-5 arguments every time.
data class WeaponData(
val shooter: LivingEntity,
val weaponTitle: String,
val weaponStack: ItemStack,
val weaponMeta: ItemMeta,
val slot: EquipmentSlot,
): CastData {
val mainhand: Boolean
get() = (slot == EquipmentSlot.HAND)
// other methods for getting NBT tags
// other methods for CastData for easy mechanics casting
}
Pros
Cleaner code
Removes null checks from code since we only do it once
Performance increase from saving the weaponMeta
Performance increase from caching all values
Performance increase from skipping new CastData instantiations
Cons
Refractoring in:
Events API constructors
All handlers
boiler plate at the start of handlers (weaponData#getWeaponStack)
Notes
This does not have to be in Kotlin, just wrote in kotlin for example
If anybody would like to fund to have this coded, let me know :)
The Problem(s)
ItemMeta
between method calls, so getting/setting an NBT tag is taking up too many resources. This is becauseItemStack#getItemMeta
Pros
new CastData
instantiationsCons
weaponData#getWeaponStack
)Notes