March 22, 20205 yr The @Override notation is used when overriding a method defined in a parent class, to either replace or add additional functionality.
March 22, 20205 yr When a class/object is a child of another (it extends from it), it also has its fields and methods (only public and protected fields can be accessed directly). If you want to have a different implementation of any of the parent methods, you override them. For example, if you have a base class which describes all GeometricShapes and in it you have a method getArea(). You can override this method in the class triangles and rectangles which extend from GeometricShapes and you can make them return the respective areas. Edited March 22, 20205 yr by Cerandior
March 22, 20205 yr Hi The reason you should use @Override (it's optional) is so that, when Forge or minecraft updates and the signature for a method changes, your compiler tells you that there is a problem. eg public class ItemVariants extends Item { // what animation to use when the player holds the "use" button @Override public UseAction getUseAction(ItemStack stack) { return UseAction.DRINK; } } When minecraft is updated, and getUseAction(ItemStack stack) changes to getUseActionAnimationType(ItemStack stack), or changes to getUseAction(ItemStack stack, Hand whichHandUsing), then your compiler will give you an error. Otherwise your code will silently stop working because your item will now use the Item base method which is public UseAction getUseAction(ItemStack stack) { return stack.getItem().isFood() ? UseAction.EAT : UseAction.NONE; } This happens a lot and from bitter experience I can tell you that @Override can save you hours of pain and frustration. -TGG
March 22, 20205 yr 1 hour ago, axilirate said: Thanks. Override is typical Java. If you don‘t know Java 8 then learn this before you begin. Java has a JavaDoc, in them you can see what methods or functions can make. Hope this will help you New in Modding? == Still learning!
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.