Jump to content

[1.7.2]Is there a way to "redirect" methods of an existing vanilla class?


Manic_Cure

Recommended Posts

I'm writing a mod to create wood fences for all the different types of wood in minecraft, but I want them all to connect to each other. It was easy enough to override the fences' canConnectFenceTo() methods, so now the only one left is the vanilla fence. Is there a way to override or circumvent the vanilla fence's canConnectFenceTo() method so that it connects to the other fences?

 

I have just begun learning mincraft modding, but I know Java pretty well. I'm just used to creating my own projects from scratch, and far less experienced working around someone else's code.

 

Thanks in advance.

Link to comment
Share on other sites

Firstly, if your fence classes extend the vanilla fence class then the vanilla fence class will consider them fences.

 

Secondly, if there is a cancellable event at the time of interest you can intercept it by subscribing to it and doing your own processing.  Like maybe when player places a block you could intercept it.

 

Thirdly you can replace the vanilla block with your own that extends the vanilla block but overrides the methods you want to customize.  You can do the replacement by maybe changing the crafting recipe for the fence to output yours instead, or you can look for any instances of fence and simply replace them with yours, and so forth.  Not necessarily elegant but possible.

 

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

Link to comment
Share on other sites

Thanks for the reply, jabelar. My fence class does extend the vanilla fence, however, it doesn't seem to recognize a child of the BlockFence class as a Block.fence, and therefore the method mentioned above returns a false boolean.

 

Your second suggestion might solve my problem, but I have yet to look into tapping into subscribing to game events, and am unfamiliar with how minecraft handles player events. I'll check this method out, thanks!

Link to comment
Share on other sites

Thanks for the reply, jabelar. My fence class does extend the vanilla fence, however, it doesn't seem to recognize a child of the BlockFence class as a Block.fence, and therefore the method mentioned above returns a false boolean.

 

Yeah, the problem is the way it checks if it is a fence.  If it had checked the class using isMemberOf then your blocks would be considered fences, but since it is checking specifically against the registered instance then yeah that won't work.

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

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.