Hi guys, this is the first tutorial in my advanced modding tutorial series (The GTs tag stands for "Geforces tutorials" FYI). Anyway, lets get right to it!
How to write to a file:
PrintWriter writer = new PrintWriter("tutorial.txt"); //This will create a .txt file named "tutorial" in your .minecraft folder
writer.println("5,true") //This will print "5,true" into the tutorial.txt file
writer.close(); //This closes the .txt file when your done editting it.
//And thats it
How to read a file:
Scanner file = new Scanner(new File("tutorial.txt")); //This loads the tutorial.txt text file into a scanner
scanner.useDelimiter(","); //This tells Java that our variables (5, true) are comma-separated.
int number;
boolean shouldPrint;
//-------------------- This whole if statement loads the two variables into variables that we can use.
if(scanner.hasNextInt()){
number = scanner.nextInt();
}else if(!scanner.hasNextInt() && scanner.hasNextBoolean()){
shouldPrint = scanner.nextBoolean();
}
//---------------------
How to use these things:
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){
//INSERT READING CODE HERE
if(shouldPrint){
par1World.setBlock(par2, par3, par4, number); //This will set the block that has this code in it to oak wood
}
}
I hope you like it! If this helped you, hit that green arrow in the corner there. If people like this, ill definitely do more!
-
View User Profile
-
View Posts
-
Send Message
ModeratorHow to write to a file:
PrintWriter writer = new PrintWriter("tutorial.txt"); //This will create a .txt file named "tutorial" in your .minecraft folder writer.println("5,true") //This will print "5,true" into the tutorial.txt file writer.close(); //This closes the .txt file when your done editting it. //And thats it
How to read a file:
Scanner file = new Scanner(new File("tutorial.txt")); //This loads the tutorial.txt text file into a scanner scanner.useDelimiter(","); //This tells Java that our variables (5, true) are comma-separated. int number; boolean shouldPrint; //-------------------- This whole if statement loads the two variables into variables that we can use. if(scanner.hasNextInt()){ number = scanner.nextInt(); }else if(!scanner.hasNextInt() && scanner.hasNextBoolean()){ shouldPrint = scanner.nextBoolean(); } //---------------------How to use these things:
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){ //INSERT READING CODE HERE if(shouldPrint){ par1World.setBlock(par2, par3, par4, number); //This will set the block that has this code in it to oak wood } }I hope you like it! If this helped you, hit that green arrow in the corner there. If people like this, ill definitely do more!
Thanks!
Mapping and Modding rules | Global rules | MCFStaff Youtube channel
Follow @I_Mod_Minecraft
-
View User Profile
-
View Posts
-
Send Message
Moderator-
View User Profile
-
View Posts
-
Send Message
ModeratorThanks!
Mapping and Modding rules | Global rules | MCFStaff Youtube channel
Follow @I_Mod_Minecraft