Option to define the CraftEntity when extending entities. #10755
PlayerSchark
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your feature request related to a problem?
Let's say you want to make a buch of custom entities. A way to do this is by exteinding LivingEntity, Mob or sth else with your own class and build an inheritance structure for your Entities and let the EntityType decideswhich Entity the Client should display.
This was easaly possible in earlier versions of Paper. But since a few versions the decision to rewrite the huge if statement in CraftEntity#getEntity into EntityTypeData happened.
And there is nothing wrong at this point. I really like this solution. But now when getEntity is called a ClassCastException occours because the custom entity must now match the Class of a CraftEntities constructor.
Example:
As a result the CraftEntity is now bound to the EntityType which is also used by NMS for selecting the model on the client.
Earlier versions hat an else block for such usages. But this is not possible anymore.
Describe the solution you'd like.
A valid solution for this case is to add a method to Entity which lets you define the bukkit entity. so CraftEntity#getEntity will never be called because the BukkitEntity already has been set.
Note that the method is protected so it can only be called by inherited classes or must be reassigned explicitly
Describe alternatives you've considered.
There are multiple alternatives e.g. the Field could be made public.
Another option would be to modify the Registry in a way that CraftEntity#getEntity would return CraftLivingEntity. But for that case the EntityType must match which isn't an option here.
The last option would be to bring back the if statement but no one really wants this. XD
Other
No response
Beta Was this translation helpful? Give feedback.
All reactions