Since no-one has posted anything about minecraft clients recently, I thought why not just keep some new people refreshed on coding a client more efficiently..
So we have our client set up, everything works, it loads. Yey.
Now we want to add in our modules, hacks, whatever you want to call them.
So lets create a basic template for our hacks. Lets call it a Module.
This module will contain some of the vital methods we would want our hacks to have. These could range from their key bind, name, to things like onClick methods or anything else you would want.
So something like that would look like this:
Code:
public class Module
{
private String name;
private int key;
public Module(String name, int key)
{
this.name = name;
this.key = key;
}
public void onEnable()
{
}
public void onDisable()
{
}
}
And everyone has probably seen these everywhere in the tutorials. Now what a smart thing to do would be is to use the Java language to its fullest and use what it gives us.
So why not create a handler for the hacks. This handler would have an array list which would hold modules.
Code:
private ArrayList<Module> modules;
Then we would initialize the arraylist to a new arraylist. Afterwards, we want to add every hack into the array list.
Now the fun part is getting them to work.
Java provides a really useful loop called the for loop which, when used with arrays can be very very very useful.
So why not create one?
Code:
for(Module m : modules)
{
if(ck.checkKey(m.getKey()))
{
m.onEnable(); //Or just create a toggle for this
}
}
So if we write that in pseudocode,
Code:
For every Module (which we call m) in the modules array list, do the following :
check if the key matches that modules key. If it does then proceed to enable method of the module.
So now it gives more organization to the client, instead of creating all of the different methods for every hack.
This was just a refresher for a client coding. If you have any questions just ask? I guess..