Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeaponData class for common data #388

Open
CJCrafter opened this issue Jan 13, 2024 · 0 comments
Open

WeaponData class for common data #388

CJCrafter opened this issue Jan 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@CJCrafter
Copy link
Member

The Problem(s)

  1. 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
  2. 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 :)
@CJCrafter CJCrafter added the enhancement New feature or request label Jan 13, 2024
CJCrafter added a commit that referenced this issue May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant