Jump to content

[1.10.2] Code Improvement/Optimization


LogicTechCorp

Recommended Posts

Hello everyone!

 

I am working on a mod that will allow others and I to add biomes to the Nether. I have been working on it for quite some time and just updated to 1.10.2. Before I go further, I would like to know if I could improve/optimize my code and what I should and should not be doing. All help is appreciated!

 

Github:

https://github.com/LogicTechCorp/NetherEx

 

-LTC

Link to comment
Share on other sites

You have duplicated code in your proxies: that's not how the proxy system work

 

All game-logic and non-side-specific code should go in a "base" proxy class. You then extend this class to create a "server" proxy class (this will not happen very often) and a "client" proxy class for side-specific code

 

In the most common scenario you will end with a CommonProxy class to use as the server proxy and a ClientProxy (created extending CommonProxy) as the client proxy (you can name the classes as you like it, those are just the most used names)

 

Link to comment
Share on other sites

You have duplicated code in your proxies: that's not how the proxy system work

 

All game-logic and non-side-specific code should go in a "base" proxy class. You then extend this class to create a "server" proxy class (this will not happen very often) and a "client" proxy class for side-specific code

 

In the most common scenario you will end with a CommonProxy class to use as the server proxy and a ClientProxy (created extending CommonProxy) as the client proxy (you can name the classes as you like it, those are just the most used names)

 

 

While it is true - "Code duplicates = bad" - you are wrong with "that's not how the proxy system work".

 

Just because he is not following 1st tutorial you find on google, doesn't mean he's doing it wrong.

 

Code he has is 100% valid, it can just be made better by making abstract common (or default interface), instead of normal interface.

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

Link to comment
Share on other sites

First off all, I don't care what the 1st tutorial you find on Google say and I was not talking about his use of interfaces to abstract the proxies :)

 

It's his implementation the problem

 

With the way he is doing it, he will end with "common" code both in his ServerProxy and ClientProxy classes, be it a straight copy of the full code (like he has now) or calls to other classes, as he have to execute it on both enviroments

 

And that's "bad" :)

Link to comment
Share on other sites

All game-logic and non-side-specific code should go in a "base" proxy class.

 

Eehhh.  I prefer that common goes goes in the base mod class.  I see way to much "it should be in the proxy" so the main mod class tells the proxy about the init events, then the proxy goes "well all the code is over in the ModBlocks class" and shunts the event over there.

 

It's a right pain in the ass to debug when the person has a problem because we have to ask for THREE classes to identify the problem (oops, their ModBlocks.preInit() method is actually called durring an init event).

 

There's no reason to shunt method calls around, sure it adheres to some abstract notion of encapsulation, but encapsulation really isn't that good (if encapsulation is followed to the letter, then no package would ever import any package other than itself, its direct parent, and its direct children sub-packages and all cross-package invocation would be fired up or down this chain*).

 

*That is, in order for a block to reference an item, the block would have to ask ModBlocks to forward a call to BaseMod, which would then forward the call to ModItems, and so forth.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You have duplicated code in your proxies

While it is true - "Code duplicates = bad"

 

I don't see how my post was in any way "against" yours. If any - I agreed with you on moving code to common class.

 

If you smited me for that then damn, you are angry person (again - IF, because some just did, lol) :D

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

Link to comment
Share on other sites

It looked like it, a bit at least :D

 

Nop, wasn't me. I like forums so much that I was not aware that you could smite someone gh

 

PS: @Draco18s, to solve your THREE-CLASSES problem you could have a barebone mod class and delegate all the work to the proxy as you are kind of obbligate to use it anyway :D

Link to comment
Share on other sites

Or I could do everything in the base mod class and delegate to the proxy when, and only when, sided code is required.

i.e. the registering of event handlers, renderers, and suchlike.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.