Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.15.2] What does "@Override" do?
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
axilirate

[1.15.2] What does "@Override" do?

By axilirate, March 22, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

axilirate    0

axilirate

axilirate    0

  • Tree Puncher
  • axilirate
  • Members
  • 0
  • 10 posts
Posted March 22, 2020

Thanks.

  • Quote

Share this post


Link to post
Share on other sites

Ugdhar    232

Ugdhar

Ugdhar    232

  • World Shaper
  • Ugdhar
  • Members
  • 232
  • 2215 posts
Posted March 22, 2020

The @Override notation is used when overriding a method defined in a parent class, to either replace or add additional functionality.

 

  • Quote

Share this post


Link to post
Share on other sites

Cerandior    26

Cerandior

Cerandior    26

  • Diamond Finder
  • Cerandior
  • Members
  • 26
  • 384 posts
Posted March 22, 2020 (edited)

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, 2020 by Cerandior
  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    818

TheGreyGhost

TheGreyGhost    818

  • Reality Controller
  • TheGreyGhost
  • Members
  • 818
  • 3280 posts
Posted March 22, 2020

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

 

 

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

DragonITA    12

DragonITA

DragonITA    12

  • Dragon Slayer
  • DragonITA
  • Members
  • 12
  • 552 posts
Posted March 22, 2020
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

  • Quote

New in Modding? == Still learning!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      Failure message: Missing License Information in file Mod File

      By diesieben07 · Posted 10 minutes ago

      I am locking this thread now, because too many irrelevant replies are coming in. If you have an issue, make your own thread and post logs.
    • diesieben07
      Failure message: Missing License Information in file Mod File

      By diesieben07 · Posted 10 minutes ago

      It is impossible for you to get this message on 1.14.4. Make your own thread and post logs.
    • Ronshark
      Bug logs Minecraft Code sortie 0

      By Ronshark · Posted 15 minutes ago

      je vous remercie énormement
    • Sr_endi
      [1.16.4]How to set the light value of an block

      By Sr_endi · Posted 30 minutes ago

      Thank you! I will try that.
    • Ironhead_
      Failure message: Missing License Information in file Mod File

      By Ironhead_ · Posted 1 hour ago

      I'm playing on 1.14.4 and am only using the create mod, however I'm having to resort to adding JEI to see some recipes I'm stuck on. it doesn't let me use JEI without a licence
  • Topics

    • arkeN
      50
      Failure message: Missing License Information in file Mod File

      By arkeN
      Started October 11, 2020

    • Ronshark
      2
      Bug logs Minecraft Code sortie 0

      By Ronshark
      Started 16 hours ago

    • Sr_endi
      2
      [1.16.4]How to set the light value of an block

      By Sr_endi
      Started 20 hours ago

    • e2rifia
      1
      (1.16.2) How do I use onPlayerTick?

      By e2rifia
      Started 1 hour ago

    • PotatoEz1
      4
      7 FPS with a GT 1030 + i5-4690 (1.16.3)

      By PotatoEz1
      Started 3 hours ago

  • Who's Online (See full list)

    • Choonster
    • diesieben07
    • e2rifia
    • RedBobKid
    • XenoPyax
    • Ironhead_
    • GenElectrovise
    • Funyaah
    • Master_Fenix01
    • Ronshark
    • alexropi00
    • FreshMod
    • Angercraft
    • GreenBerry
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.15.2] What does "@Override" do?
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community