Jump to content

Subclassing class with a private constructor - Access Transformer or reflection?


Recommended Posts

I'm wanting to create a custom WorldType (similar to BOP), but the WorldType class has only private constructors.  What's the best way to get around this -- using Access Transformation, or Reflection?  I've looked at BOP, and it seems to be using Access Transformation since the WorldType class has public constructors there.

 

I understand how to use reflection for normal fields and methods, but I'm wondering how it could be used for a constructor since the super() call has to be the first line in the subclass's constructor.

 

Thanks for your assistance!

The best protection for all you meat-related data.

Link to comment
Share on other sites

If you scroll to the Forge section in

WorldType

, you see Forge adds a constructor that only takes the name of the

WorldType

. You can use that.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

One question - why the heck do you need those constructors? Those 2 constructoors are internal ones that should NOT be touched.

 

Only one you should be overriding is:

/**
     * Creates a new world type, the ID is hidden and should not be referenced by modders.
     * It will automatically expand the underlying workdType array if there are no IDs left.
     * @param name
     */
    public WorldType(String name)
    {
        this(getNextID(), name);
    }

 

Edit: I didn't notice previous post ;o

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Thanks all.  I didn't see that constructor because it was added by forge and "under the line" (i.e. at the bottom below the separator comment).  I'm used to constructors being at the top of a class by convention, so I didn't look down there.

 

I agree that is the one to use, now that I know it's there.

 

The best protection for all you meat-related data.

Link to comment
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.
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.