imDaniX / Dangerous-Caves-2

Minecraft Bukkit plugin for a new cave experience
MIT License
22 stars 8 forks source link

Question: how to check if a mob belongs to DC2 #50

Closed lokka30 closed 2 years ago

lokka30 commented 3 years ago

Hi there!

I'm the author of LevelledMobs, and I am interested in adding compatibility on our side to allow the plugins to coexist.

A user has alerted me that our current Dangerous-Caves compatibility code isn't working for DC2 - I found this was because we are checking for the temporary metadata value that DC1 set, which is disabled by default due to the possible memory leak for DC2.

I saw DC2 is now using the PersistentDataContainer. To achieve my question, would I use this?

A sub-question of sorts: Will I need to shade in DC2 to the project? We try to minimise our pom.xml dependencies, so if there is a suitable way of doing without any direct code access to DC2, the better. :)

Thank you very much - and have a great day! ~ lokka30.

imDaniX commented 3 years ago

As for 1.14+, I guess you can create a new instance of DC2's namespaced key with new NamespacedKey(Bukkit.getPluginManager().getPlugin("DangerousCaves"), "mob-type") and check if entity's PDC has this key with the PersistentDataType.STRING type. For <1.14 you can check if entity has "dc-mob" scoreboard tag. Now, as I'm thinking about it, I'll probably add this tag for 1.14+ too...

A sub-question of sorts: Will I need to shade in DC2 to the project? We try to minimise our pom.xml dependencies, so if there is a suitable way of doing without any direct code access to DC2, the better. :)

Surely, you don't need to shade it. But with DC2 as a dependency you can use the me.imdanix.caves.compatibility.Compatibility utility class (yeah, that's quite lame, ikr ;D) to determine if a mob is a DC2 mob by using Compatibility.isTagged(LivingEntity)

lokka30 commented 3 years ago

As for 1.14+, I guess you can create a new instance of DC2's namespaced key with new NamespacedKey(Bukkit.getPluginManager().getPlugin("DangerousCaves"), "mob-type") and check if entity's PDC has this key with the PersistentDataType.STRING type. For <1.14 you can check if entity has "dc-mob" scoreboard tag. Now, as I'm thinking about it, I'll probably add this tag for 1.14+ too...

A sub-question of sorts: Will I need to shade in DC2 to the project? We try to minimise our pom.xml dependencies, so if there is a suitable way of doing without any direct code access to DC2, the better. :)

Surely, you don't need to shade it. But with DC2 as a dependency you can use the me.imdanix.caves.compatibility.Compatibility utility class (yeah, that's quite lame, ikr ;D) to determine if a mob is a DC2 mob by using Compatibility.isTagged(LivingEntity)

Brilliant! Thank you very much. I'll try the first (possibly second as well) method that you've suggested, as soon as I can find some free time (I'll also let you know which one works).