1.15.2 Is there a way to store custom mob data?

Discussion in 'Spigot Plugin Development' started by iCodinqs, Jan 28, 2020.

  1. Hello All!

    So I am wondering, is there a way to store custom mob data to mobs that have spawned?

    e.g. to store what level a mob is

    thank you!
  2. Yes, that's exactly what PersistentDataHolder is for. You can get the PersistentDataContainer of any entity or even ItemStacks and write whatever data you want to that container. Thanks to NamespacedKey you can be sure that you only get data from a specific (probably your) plugin.

    You would likely want to write to the mob during the EntitySpawnEvent. (Maybe consider narrowing it down to CreatureSpawnEvent?)
    • Agree Agree x 1
  3. Ah super! Didn't know about this. This will be a big help :)

    Thanks a ton!