Jump to content

[1.10.2] [SOLVED] Why addVelocity() method when there is motionX, Y, Z?


Recommended Posts

Posted (edited)

Well, what is the actual purpose of Mojang creating the EntityPlayer::addVelocity(double... x, double... y, double... z); method if there is EntityPlayer::motionX, motionY, and motionZ? They are almost identically the same.

Edited by Differentiation
Posted

@DifferentiationWell, the thing with Minecraft is that it was developed over several years by programmers who were not really professional programmers. That is actually part of its charm. However, from programming practice point of view they do a lot of "bad habits" -- in this case there is a lack of "encapsulation". 

 

Your question highlights the problem with lack of encapsulation. Basically, the scope of fields and availability of setter and getter functions is very inconsistent. "Properly" speaking, motionX, Y and Z and other fields shouldn't be publicly accessible. Rather there should be setters and arguably probably just vector type ones. It is a lot "safer" to have setters because then you can add data validation, and also it allows control over if and when changes can be made.

 

You'll often find weird code in the Minecraft source that is due to lack of encapsulation. In particular you'll see all sorts of data validation sprinkled around.

 

You'll also find other things like methods and fields that have essentially been abandoned -- not used in any meaningful way.

 

Anyway, it is just part of the charm of modding. However, I do have one warning -- when calling vanilla methods or accessing vanilla fields always check carefully how they are used in the rest of the Minecraft code. You'll frequently find that a method that you think does something doesn't really do what you think, and you'll also get ideas about what sort of data validation might be needed when you use the method.

  • Like 2

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.