On this thread, I'm going to be talking about things you NEED to know before modding because what I noticed is that a lot of people try to mod minecraft with ought any basic programming skills. Here I'm going to be telling you all about the basics and what you need to know. To be more exact, I'll tell you how to make a class, use methods/constructors, make objects, explain the basic gates, and how to debug your mod if it has problems.
Before we start doing anything, you need to have a nice java code editing program. Notepad that come with window will not work well. That's why I recommend some kind of a IDE(Integrated Development Environment). This will help you mod minecraft 1000* better then Notepad. I recommend as a IDE, Eclipse It's fast, free, powerful, and convenient.
Depending on the IDE you've chosen, the interface is different so I cannot explain how to make a .java file but I can tell you what does in it. So that's what I'm going to be doing today. To make everything simple to understand,
I split up everything into spoilers that you can open up to lean about them if you haven't. If you're new to Java, I recommend you look at them in order.
Keywords:
Keywords are very important to know exactly what they are. Keywords are the default characters in Java for instance, "class" is a keyword to explain to the program what exactly to do. Even though this is short, it's very important to know what they do because you know exactly what the code means. Keywords break the rules of some things in java. I'll explain why later.
Comments:
I'm explaining comments to you now because I'll be putting them everywhere in the code and if you don't know what comment are and how to make them, you have a problem.
Comments are things that are ignored by the program comments never get ran by your program.
So, to make one you just up a "//" in front of you comment like: //this is a comment. Notice the "//" there that makes it so the program ignores it as I said.
Classes:
Classes are the things that you put all your code into. it is the foundation of your code.
To make one(in code) you need to place some keywords to say that it's a class and to explain the 'visibility'.
Here is a example:
public class Tutorial{
//code here (remember, this is a comment)
}
So, what I have here is two keywords followed by a name and then the body determination code (the { //code }) There is the first two keywords you are going to learn about. First we are going to lean about the "class" key. This determines if what you are making is indeed a class file (which it is). Simple right? The next thing I'm going to talk about is the name which here it's "Tutorial" your *.java file needs to be the same thing as that. E.g., Tutorial.java. The name can be whatever you want except for keywords and other things like putting a period in the name but essentially, whatever you want. The first keyword that I skipped is going to be in the next section called "Visibility".
Visibility:
Visibility determines how things access your code. There are three levels of visibility: public (the most commonly used one), protected, and private.
Public: This is the visibility level that is most commonly used in programming. public means that anything from anywhere(in the project) can access the class or anything in it.
Protected: You don't really need to know about this. In java, there are things called packages. These packages have bundles of code in them. Really what protected means is that anything that is in the SAME package can access your class or anything in it.
Private: This one is pretty obvious, your class cannot be accessed by anything. You can only make a object with this kind of visibility. (I'm going to talk about object later.)
Methods/constructors:
Methods/constructors are things that go inside of classes to make your program tick.
These things house the most basic of basic things of the java languages like a if statement (talking about those later).
Example code or a constructor:
public void hello(){
//code here
}
Here, you can see right off the bat that this also needs a visibility level (to determine what can access it). The second keyword says "void" this is all about returning things and that is almost one of the most important things to know before modding. Of course that last thing is the name. this can be named anything despite the name of the class itself. The last thing is the "()" this is very interesting the is used to determine what information gets passed to the constructor in this case. E.g., "(String a, int b, float c)". This tells the constructor that three pieces of information are needed for this constructor to run. (I will be explaining what these things are (String, int, and float) in a section called "Variables".
Example for a method:
public class Tutorial{
// I made a class here
public void Tutorial(){
//here is a method
}
}
A method lets you make objects for classes(explain those later). That's pretty much it. Notice how the method has the same name of the class. That's what makes it a method. Word of warning, when you make a method, make sure you know exactly what you're doing because they cause really weird things to happen when you put your code there in staid of a regular constructor.
Return Types:
In constructors you sometimes need to return this like maybe you want to get some information easily.
Here, I'm going to be talking about what you can return and what to return and how to specify what you want to return things. When you make a constructor, you need to put in your return type. These are: objects, variables, or void. Void is a keyword that means you're not returning anything. If you do anything other then that, you need to return something.
E.g.,
public int test(int a){
return a;
}
You can see here that I am returning a int variable (talk about those later) and my constructor needs a int variable. I'm just returning what It gave me. It's useless but you can see what this is all about.
One more thing, you can still return to some code if you need to still with the void return type. E.g.,
public void test(){
int a = 6;
return;
}
What this does is it makes a variable and it return back to some code.
How to call a constructor:
It's very easy to call a block of code that is in a constructor. First, you need to make sure that your constructor is visible by other things. To call one, you just say <constructor name>();. The () is where you put your variables you might need to pass along to the constructor. E.g.,
//Suppose I already have a constructor called test and It's visible by other things.
this.test();
Now, notice how I put a "this" keyword in the code. "this" just meant I'm referring to the class that to code is in. So what I'm doing is calling a constructor from a method/constructor in the same class. Now, let's talk about calling things from other classes. First you need to make your constructor that you want to be called "static" the "static" keyword makes the constructor able to be classed from other classes. Note, anything in the constructor needs to be static too, like variables and objects. Now for some code!
// I have a constructor that needs to be called in a class called hello
hello.test();
Now notice that instead of the "this" keyword being there referring to the class that that code is in, It's referring to another class. So, we put the name of the class instead.
the Semi-Colin.
This is going to be short but as everything important. These things ( end off a line of code like what I'm going to be talking about variables which need a semi-colin like this: int a = 5; // notice the semi-colin
Variables:
Variables let you store information.
Some variable types are: int, float, boolean, double, short, long, byte, and char.
I'll explain the variables that store numbers:
Integers:
If you pay attention in math class, you will know that integer is any full number. E.g., A Integer is 4 but not 4.5.
Some types of integer variables are: Byte, short, int, and long. You might be asking, why are there multiple? It's because computers have something called RAM(Random Access Memory) and these variables use different amounts of ram and can store different numbers.
A byte uses 1 byte of ram but can only count from -128 to 127.
A short uses 2 bytes of ram but can only count from -32768 to 32767.
A int uses 4 bytes of ram but can only count from -2147483648 to 2147483647.
A long uses 8 bytes of ram but can only count from -9223372036854775808 to -9223372036854775807.
Depending on what you need, use what is appropriate for your situation.
Decimal variable:
These store things like 4.6 and 2.742. There are two variable types for this: float and double
A float uses 4 bytes of memory but provide up to a -3.4^38 points of accuracy.
A double uses 8 bytes of memory but provide up to a -1.7^308 points of accuracy.
Everything else: This is a boolean a char
A boolean takes up 1 bit of memory and stores aether a true or a false.
A char takes up 1 bit of memory and stores one character(letter).
Just before I close this of, I need to explain how to make one.
int a = 5;
// now since you make a variable you can change it
a = 6;
// or you can do math in it
a = 5 + 7;
Objects:
Objects let you store information just like how variables do except in a more compact way.
Like a said before, you make a object by making a method. Object are very useful because they let to you make multiple instances of the same thing.
A integrated object in java (almost always used) is the String object. this lets you store a sentence like String a = "hello my name is bob";. You might be asking why is this not a keyword but a special variable???!!! Well, a string is a array of chars. Remember, a char stores a single letter. What a string does is it makes a bunch of chars and puts them together to make a word! Smart! If you haven't noticed I said "a bunch of chars". You might be asking how do you do that? Well they are called array tables. I'm going to be talking about those in the next subject.
Array Tables:
Array Tables let you make a multiple variables if you don't know how much you need.
There pretty simple so I'm going to jump into some code already:
int[] a = new int [5];
//notice the "[]" there that means I'm making a Array Table.
a[0] = 9;
a[1] = 3;
a[2] = 4;
// we can do normal things with it like math
a[3] = a[0] + a[1];
Notice that when I was initializing the variable, there is a keyword "new". this is a rather simple one. this just makes the object. From here, it is very self explanatory. You have a array index that does from 0 - 4 which is 5 variable (computers start at 0 so that's why it's from 0 - 4 and not 1 - 5). You can use this like a normal variable except you can define how many variables you want of a type.
Logic and Loops!
If statement:
This is a gate you NEED to know.
A if gate lets the computer make decisions. Your asking the computer, if this is true run that. If gates take a input of a boolean aether a true or a false. E.g.,
boolean a = true;
if (a){
//this code is ran if 'a' is true
}else{
//this code is ran is 'a' is false
}
You can see that a if statement has a basic body. I have added some extra stuff here which is not needed, like the else part. The else part is pretty self explanatory it's just saying "If a is true, run this code OTHERWISE, run this code.".
The only thing I was talking about is entering a boolean, that's not very useful to compare data. That's why Java includes gates that can make simple operations and generate a boolean value. Here are some of them:
int a = 5;
int c = 3;
a == c //this is asking if a = c.
a != c // this is asking if a does not = c.
a < c //this is asking if a is smaller then c.
a > c // this is asking if a bigger then c.
a <= c // this is asking if a is smaller or equal to c.
a >= c // this is asking is a is bigger or equal to c.
You might want to compare more then one things:
boolean a = true;
boolean c = false;
a || c // this is saying if a is true OR c is true.
a && c // this is asking if a is true AND c is true.
[code]
All of these generate a boolean value and if you're not sure, you can use it in a if statement like this:
[code]
int a = 5;
int b = 10;
int c = 3;
if (a == b || a <= c){
//if you put code here, would it run?
}
The while loop:
This loop is similar to a if statement that it needs a boolean to run
boolean a = true;
while (a){
//code that gets looped over and over again
}
What this does is that it will run some code if the condition you gave it = true every time it loops.
So, if the loop is running and the variable changed to false, it would stop to loop. There are other ways of stopping a loop. Use the "break keyword to do this. E.g.,
while (true){
//run code
if (<condition> == true){
break;
}
}
The for loop:
This is a loop that loops for a fixed amount. E.g.,
for (int a = 0; a > 10; a++){
//this will loop the code here 10 times
}
You can see that what I do is make a variable called a, check if a is more then 10 (this determines how big the variable needs to be until it breaks to loop, and the amount the variable increments by every loop of the loop.
Notice how there is a "++" in front of the variable. This makes the variable go up by one or you could use "--" to decrement the variable one. E.g.,
int a = 9;
a++;
// a will now equal 10
that is basicly -4.2^705 or the entire Java language. I just lightly scraped the surface of the Java language.
There is more to come on this topic about modding language and how to know what you're doing when it comes to modding Minecraft. I hoped you enjoyed reading this (I never enjoyed writing this entire topic), happy modding!
Nice Work!
Have some Diamond pants for each day of the week!
Note for comments.
/*
* This Comment will show as a JavaDoc and be seen in tool tips
* I can put info about its arguments here and they will be seen at each instance of the Method.
* @param par1World the world itself
* @param par2 xCord to check and set
* @param par3 yCord to check and set
* @param par4 zCord to check and set
* @param par5 side of the block
* @param par6 blockID
*/
public static comment(World par1world, int par2, int par3. int par4, int par5, int par6)
{
return this.getcomment.commentID
}
NOTE: the "Code" does nothing people... its just the */ and /* and eclipse "should automatically" put the * at each line between them.
Funny. The only language I know is Visual C#, and all this java code looks exactly the same as C# code. That will probably help me out a lot if I ever do make a mod for Minecraft. Thanks
On this thread, I'm going to be talking about things you NEED to know before modding because what I noticed is that a lot of people try to mod minecraft with ought any basic programming skills. Here I'm going to be telling you all about the basics and what you need to know. To be more exact, I'll tell you how to make a class, use methods/constructors, make objects, explain the basic gates, and how to debug your mod if it has problems.
Before we start doing anything, you need to have a nice java code editing program. Notepad that come with window will not work well. That's why I recommend some kind of a IDE(Integrated Development Environment). This will help you mod minecraft 1000* better then Notepad. I recommend as a IDE, Eclipse It's fast, free, powerful, and convenient.
Depending on the IDE you've chosen, the interface is different so I cannot explain how to make a .java file but I can tell you what does in it. So that's what I'm going to be doing today. To make everything simple to understand,
I split up everything into spoilers that you can open up to lean about them if you haven't. If you're new to Java, I recommend you look at them in order.
Keywords:
Comments:
Comments are things that are ignored by the program comments never get ran by your program.
So, to make one you just up a "//" in front of you comment like: //this is a comment. Notice the "//" there that makes it so the program ignores it as I said.
Classes:
To make one(in code) you need to place some keywords to say that it's a class and to explain the 'visibility'.
Here is a example:
So, what I have here is two keywords followed by a name and then the body determination code (the { //code }) There is the first two keywords you are going to learn about. First we are going to lean about the "class" key. This determines if what you are making is indeed a class file (which it is). Simple right? The next thing I'm going to talk about is the name which here it's "Tutorial" your *.java file needs to be the same thing as that. E.g., Tutorial.java. The name can be whatever you want except for keywords and other things like putting a period in the name but essentially, whatever you want. The first keyword that I skipped is going to be in the next section called "Visibility".
Visibility:
Public: This is the visibility level that is most commonly used in programming. public means that anything from anywhere(in the project) can access the class or anything in it.
Protected: You don't really need to know about this. In java, there are things called packages. These packages have bundles of code in them. Really what protected means is that anything that is in the SAME package can access your class or anything in it.
Private: This one is pretty obvious, your class cannot be accessed by anything. You can only make a object with this kind of visibility. (I'm going to talk about object later.)
Methods/constructors:
These things house the most basic of basic things of the java languages like a if statement (talking about those later).
Example code or a constructor:
Here, you can see right off the bat that this also needs a visibility level (to determine what can access it). The second keyword says "void" this is all about returning things and that is almost one of the most important things to know before modding. Of course that last thing is the name. this can be named anything despite the name of the class itself. The last thing is the "()" this is very interesting the is used to determine what information gets passed to the constructor in this case. E.g., "(String a, int b, float c)". This tells the constructor that three pieces of information are needed for this constructor to run. (I will be explaining what these things are (String, int, and float) in a section called "Variables".
Example for a method:
A method lets you make objects for classes(explain those later). That's pretty much it. Notice how the method has the same name of the class. That's what makes it a method. Word of warning, when you make a method, make sure you know exactly what you're doing because they cause really weird things to happen when you put your code there in staid of a regular constructor.
Return Types:
Here, I'm going to be talking about what you can return and what to return and how to specify what you want to return things. When you make a constructor, you need to put in your return type. These are: objects, variables, or void. Void is a keyword that means you're not returning anything. If you do anything other then that, you need to return something.
E.g.,
You can see here that I am returning a int variable (talk about those later) and my constructor needs a int variable. I'm just returning what It gave me. It's useless but you can see what this is all about.
One more thing, you can still return to some code if you need to still with the void return type. E.g.,
What this does is it makes a variable and it return back to some code.
How to call a constructor:
Now, notice how I put a "this" keyword in the code. "this" just meant I'm referring to the class that to code is in. So what I'm doing is calling a constructor from a method/constructor in the same class. Now, let's talk about calling things from other classes. First you need to make your constructor that you want to be called "static" the "static" keyword makes the constructor able to be classed from other classes. Note, anything in the constructor needs to be static too, like variables and objects. Now for some code!
Now notice that instead of the "this" keyword being there referring to the class that that code is in, It's referring to another class. So, we put the name of the class instead.
the Semi-Colin.
Variables:
Some variable types are: int, float, boolean, double, short, long, byte, and char.
I'll explain the variables that store numbers:
Integers:
If you pay attention in math class, you will know that integer is any full number. E.g., A Integer is 4 but not 4.5.
Some types of integer variables are: Byte, short, int, and long. You might be asking, why are there multiple? It's because computers have something called RAM(Random Access Memory) and these variables use different amounts of ram and can store different numbers.
A byte uses 1 byte of ram but can only count from -128 to 127.
A short uses 2 bytes of ram but can only count from -32768 to 32767.
A int uses 4 bytes of ram but can only count from -2147483648 to 2147483647.
A long uses 8 bytes of ram but can only count from -9223372036854775808 to -9223372036854775807.
Depending on what you need, use what is appropriate for your situation.
Decimal variable:
These store things like 4.6 and 2.742. There are two variable types for this: float and double
A float uses 4 bytes of memory but provide up to a -3.4^38 points of accuracy.
A double uses 8 bytes of memory but provide up to a -1.7^308 points of accuracy.
Everything else: This is a boolean a char
A boolean takes up 1 bit of memory and stores aether a true or a false.
A char takes up 1 bit of memory and stores one character(letter).
Just before I close this of, I need to explain how to make one.
Objects:
Like a said before, you make a object by making a method. Object are very useful because they let to you make multiple instances of the same thing.
A integrated object in java (almost always used) is the String object. this lets you store a sentence like String a = "hello my name is bob";. You might be asking why is this not a keyword but a special variable???!!! Well, a string is a array of chars. Remember, a char stores a single letter. What a string does is it makes a bunch of chars and puts them together to make a word! Smart! If you haven't noticed I said "a bunch of chars". You might be asking how do you do that? Well they are called array tables. I'm going to be talking about those in the next subject.
Array Tables:
There pretty simple so I'm going to jump into some code already:
Notice that when I was initializing the variable, there is a keyword "new". this is a rather simple one. this just makes the object. From here, it is very self explanatory. You have a array index that does from 0 - 4 which is 5 variable (computers start at 0 so that's why it's from 0 - 4 and not 1 - 5). You can use this like a normal variable except you can define how many variables you want of a type.
Logic and Loops!
If statement:
A if gate lets the computer make decisions. Your asking the computer, if this is true run that. If gates take a input of a boolean aether a true or a false. E.g.,
You can see that a if statement has a basic body. I have added some extra stuff here which is not needed, like the else part. The else part is pretty self explanatory it's just saying "If a is true, run this code OTHERWISE, run this code.".
The only thing I was talking about is entering a boolean, that's not very useful to compare data. That's why Java includes gates that can make simple operations and generate a boolean value. Here are some of them:
You might want to compare more then one things:
The while loop:
What this does is that it will run some code if the condition you gave it = true every time it loops.
So, if the loop is running and the variable changed to false, it would stop to loop. There are other ways of stopping a loop. Use the "break keyword to do this. E.g.,
The for loop:
This is a loop that loops for a fixed amount. E.g.,
You can see that what I do is make a variable called a, check if a is more then 10 (this determines how big the variable needs to be until it breaks to loop, and the amount the variable increments by every loop of the loop.
Notice how there is a "++" in front of the variable. This makes the variable go up by one or you could use "--" to decrement the variable one. E.g.,
There is more to come on this topic about modding language and how to know what you're doing when it comes to modding Minecraft. I hoped you enjoyed reading this (I never enjoyed writing this entire topic), happy modding!
Have some Diamond pants for each day of the week!
Note for comments.
NOTE: the "Code" does nothing people... its just the */ and /* and eclipse "should automatically" put the * at each line between them.
"Building a better tomorrow one dream at a time…" [ 一度に1つの夢より良い明日を構築する