The first thing you want to do when setting up a mod, is go into your mcp and create this folder:
Inside that folder create a folder titled something like 'YourMod'. This means that in eclipse, your package will be 'mods.YourMod'. After you have your package, open eclipse and create a new file inside that package, and name it 'YourMod.java'. For the sake of the tutorial, it will be 'YourMod.java', but you can call it whatever you want.
The first thing you want to type in this new file is your package. To do this, type the code:
package mods.YourMod;
This just tells the program where your mod is located.
Then, you need to give your class a title, type this code:
@Mod(modid = "YourMod", name = "YourMod", version = "1.0")
public class YourMod
{
}
The @Mod tells forge to load your mod, with the info next to it, i.e. the mod ID, name, and version number.
Make sure your Mod ID is all in lower case.
Everything that is in your mod, will be written inside the YourMod class.
Next, you need three new methods inside YourMod. These are:
@EventHandler
public void preLoad(FMLPreInitializationEvent event)
{
}
@EventHandler
public void load(FMLInitializationEvent event)
{
}
@EventHandler
public void postLoad(FMLPostInitializationEvent event)
{
}
Although all of these methods are pretty self explanatory, I will explain them anyway. The first method, is for things that you want to load before your mod is initialized. This method is usually used for generating configuration files. The next method is where the bulk of your mod will be written, because it loads things while your mod is initialized. The last method loads things after your mod is initialized, don't worry about that method because you most likely won't use it too much.
After adding all of those things, you will notice that a lot of code is underlined in red. This is most likely because you didn't import the necessary files. To import them, simply hover your mouse over the word highlighted in red, and click 'Import ******'
Your final file should look like this:
package mods.YourMod;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = "yourmod", name = "YourMod", version = "1.0")
public class YourMod
{
@EventHandler
public void preLoad(FMLPreInitializationEvent event)
{
}
@EventHandler
public void load(FMLInitializationEvent event)
{
}
@EventHandler
public void postLoad(FMLPostInitializationEvent event)
{
}
}
Now you're ready to mod!
Creating Blocks
Basic Block
Before anything, set up your main mod file from the previous tutorial, so it looks like this:
package mods.TutorialBlock;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = "tutorialblock")
public class TutorialBlock
{
@EventHandler
public void preLoad(FMLPreInitializationEvent event)
{
}
@EventHandler
public void load(FMLInitializationEvent event)
{
}
@EventHandler
public void postLoad(FMLPostInitializationEvent event)
{
}
}
The first thing you have to do for a block, is write this code in the body of your mod file:
public static Block YourBlock;
This code tells minecraft that your making a block. Next, you will start assigning properties to your block by typing this into your load() function:
YourBlock = new YourOwnBlock(256, Material.rock).setUnlocalizedName("yourblock").setHardness(1F).setResistance(1F);
There are many properties you can set here that I will go into depth about later, but for now I will leave it to this. That first 256, is your blocks ID, and the material is what material your block is made of, this is crucial for things such as what tools will be effective against certain blocks. The UnlocalizedName IS NOT the name that will show up to people using your mod, it is simply for texturing. For example, if the name of my texture in the 'assets/tutorialblock/textures/blocks/' folder was 'testblock.png' my UnlocalizedName would be 'testblock'. All of that last sentence about texturing will be better explained in the texturing section of the tutorial. The hardness is how long the block will take to break, and its resistance is its resistance to explosions from things such as creepers and TNT.
At this point, eclipse will be giving you an error. YourOwnBlock should be underlined in red, but to fix this just hover over it and click 'Create class YourOwnBlock'.
You should now have a new class that looks like this:
package net.tutorialblock;
public class YourOwnBlock
{
}
Now you have to make your class extend Block, to do this, type 'extends Block' after 'YourOwnBlock' and then import Block by hovering over it and clicking 'import'. Next, you have to add a constructor, and you can do this by hovering over 'YourOwnBlock' (which should be underlined in red) and clicking 'Add constructor "YourOwnBlock(int, Material)"'. After all of this, your file should look like this:
package mods.TutorialBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
public class YourOwnBlock extends Block
{
public YourOwnBlock(int par1, Material par2Material)
{
super(par1, par2Material);
}
}
After this, you have to head back to your main mod file for a few more lines of code.
Firstly, you have to register your block. Do this by writing this code in your load() function:
The first YourBlock, is simply the name of your block in the code, the String is the same as the name that you declared in your blocks properties when you typed .setUnlocalizedName("yourblock").
Next, you have to set a name for your block that will show up to the player. You do this by typing this in your load() function:
LanguageRegistry.addName(YourBlock, "My First Block");
You will have to import LanguageRegistry.
The first field again is the name of your block in the code, but this time the String is what name will show up inside of minecraft, in this case it's 'My First Block'.
Now your block is completely finished! In the next tutorial you will learn how to add your block to the creative menu.
Adding Your Block to Creative
This tutorial will be very quick, and is only one small line of code. When you are declaring the properties for your block (hardness, resistance, etc.) you can just write one more line and have your block added to the creative inventory. Type this with your block:
YourBlock = new YourOwnBlock(256, Material.rock).setUnlocalizedName("yourblock").setHardness(1F).setResistance(1F).setCreativeTab(CreativeTabs.tabBlock);
This will make it show up in the creative inventory under 'Blocks'. Here are the names to all of the different tabs:
Now if you've already tested your block, you'll realize that its texture is pretty gross:
Ewww...
So to fix that you have to do a little more. First, you need to make your own texture. Open up a program to edit images, such as Photoshop, or Gimp, and create a new file that is 16x16. Draw anything on it (hopefully appropriate) for your texture and save it to a folder in your mcp called 'assets/tutorialblock/textures/blocks/' and make sure the title is the same as the UnlocalizedName of your block. For the purposes of this tutorial the second folder is 'tutorialblock' however that folder should be named the same as your mod ID.
After this, there's a little bit of code you need to add. First, go into your block file, and add this method:
This method registers your icon, and tells Minecraft where to find it. However you will see that it gives you an error at 'TutorialBlock.modid'. This is because your main mod file, TutorialBlock.java, doesn't have a field called 'modid'. To fix this, hover over 'modid' and select 'Create field modid in type TutorialBlock', and it will create that field for you. Once created, your mod file should look like this:
package mods.TutorialBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = "tutorialblock")
public class TutorialBlock
{
@EventHandler
public void preLoad(FMLPreInitializationEvent event)
{
}
public static Block YourBlock;
public static String modid;
@EventHandler
public void load(FMLInitializationEvent event)
{
YourBlock = new YourOwnBlock(1000, Material.rock).setUnlocalizedName("yourblock").setHardness(1F).setResistance(1F).setCreativeTab(CreativeTabs.tabBlock);
GameRegistry.registerBlock(YourBlock, "yourblock");
LanguageRegistry.addName(YourBlock, "My First Block");
}
@EventHandler
public void postLoad(FMLPostInitializationEvent event)
{
}
}
We're almost done! The last thing you have to do before it will work properly is set the String 'modid' equal to your mods ID. This is done like this:
Most of what you have to do will take place in the main class of your mod, which should be set up similar to this.
package mods.AchievementTutorial;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = "tutorial")
public class AchievementMod
{
@EventHandler
public void config(FMLPreInitializationEvent event)
{
}
@EventHandler
public void load(FMLInitializationEvent event)
{
}
@EventHandler
public void modsLoaded(FMLPostInitializationEvent event)
{
}
}
The first thing you will have to do is make your public static Achievement, and you will also have to import Achievement. It should look like this:
import net.minecraft.stats.Achievement;
public static Achievement Tutorial;
Next, you want to assign properties to your achievement like this:
Tutorial = new Achievement("", "TutorialAchievement", 0, 0, Items.golden_apple, null);
It takes the form ("string", "string", int, int, Item, Achievement);
This line of code will go in your load() function.
The first String is only for more advanced achievements, we'll leave it blank for now, the String after that is your achievements name, this will be used later, the two ints after that dictate where your achievement appears on the achievement page, and will require a little bit of tinkering to get it in the right place (0, 0 will place your achievement directly on top of taking inventory), the item after that is only for what icon your achievement will show in the achievement page, in this case, a Golden Apple, and finally, the last field is what achievement yours requires to be triggered, but for now we will leave that as null.
Next, you will want to add a name and description to your achievement like this:
First you need to create a file called en_US.lang in the package "assets/tutorial/lang/en_US.lang" with tutorial being your mods package.
Inside of this file you will write:
Eclipse will now give you an error, and to solve this, hover over that error and click the option 'Create class "EventListener"' and eclipse will create that class for you.
You can call this class anything you want, but this is where you will put all of your forge events including crafting events, smelting events, and pickup events for triggering achievements.
After you have your event listener created, you can trigger your achievement by crafting by adding this line of code:
What this code says, is if the item crafted is a golden apple, or smelted or picked up is a gold ingot, then give the player the achievement Tutorial (our achievement we made earlier).
Advanced Achievement Triggers
These advanced triggers don't necessarily pertain to specifically pickups, or crafting/smelting, but they can be helpful for both.
In this section, you will learn how to trigger an achievement on multiple item pickups/crafts/smelts.
First, you will need to set up an integer and set it equal to 0, for the sake of the tutorial, we'll call it 'applesFound'. To do this, you will want to add this line of code to your PickupHandler or CraftingHandler:
public int applesFound = 0;
For my achievement, I would like to trigger it when I find 2 apples. To make this happen, you will change the code in the 'pickup' method to this:
This tells mine craft that every time an apple is picked up, the int 'applesFound' should have 1 added to it. After that, it checks to see if 'applesFound' is equal to 2, and if it is, the achievement is triggered.
For triggering an achievement on multiple items, you would simply do the same thing with multiple variables.
Say I want an achievement to be triggered when an apple and an iron ingot are found. For this, I would set up my variables like so:
public int applesFound = 0;
public int ironFound = 0;
And then I would go about setting the amounts I want for each item. Lets say I want it to be triggered when 2 iron ingots are found, and 1 apple is found. For this, I would have to add more parameters than before, and the code would end up looking like this:
Is giving you an error, but thats simply because we have not created that method yet, we will do so in a second. First, I would like to explain the code.
The first method is similar to before, adds 1 to 'applesFound' but then after that, runs the method 'triggerAchievementSecond()'. This is because we are working with 2 items.
The second method has the exact same function except it adds one to 'ironFound' instead.
Now we must create our new method to look like this:
First, it checks to see what the player has found, then, if the player has found 2 apples, and 1 iron, it triggers the achievement.
Important
Make sure that your variables in the if statement are written with a '>=' rather than a simple '=='. This ensures that your achievement will always be triggered. If they were set to '==' and the player found 3 apples before they found an iron, the achievement would never be triggered. Regardless of whether or not that makes any sense to you, just make sure that they are '>='.
The finished file will look a little something like this:
package com.AchievementTutorial;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemPickupEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemSmeltedEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class EventListener
{
public int applesFound = 0;
public int ironFound = 0;
public void pickup(ItemPickupEvent event)
{
if (event.pickedUp.getEntityItem().getItem() == Items.apple)
{
applesFound = applesFound + 1;
this.triggerAchievmentSecond(event);
}
if (event.pickedUp.getEntityItem().getItem() == Items.iron_ingot)
{
ironFound = ironFound + 1;
this.triggerAchievmentSecond(event);
}
}
private void triggerAchievmentSecond(ItemPickupEvent event)
{
if(applesFound >= 2)
{
if(ironFound >= 1)
{
event.player.addStat(AchievementMod.TutorialSecond, 1);
}
}
}
}
The lines that are commented out are our original trigger, with only one apple.
Custom Achievement Page
The last thing I will be going over with achievements, is making a custom achievement page for your mod. This way it is much easier to keep your achievements organized, and much easier to understand the two Ints we talked about earlier, that dictate where your achievement is placed. The reason we left those both at 0, is because then on a custom achievement page, your achievement will be placed directly in the center of the screen, which is the same as the 'Taking Inventory' achievement in vanilla.
For an achievement page to work properly, you need at least two achievements so I quickly threw together this one.
public static Achievement TutorialSecond;
TutorialSecond = new Achievement("", "TutorialSecondAchievement", 2, 0, Items.apple, Tutorial).setSpecial();
Don't forget to add a name and description to your lang file like you did with the first achievement.
You can trigger this achievement using any of the methods we learned earlier, but for me I will trigger it upon picking up a Red Apple.
You'll notice a few different things about this second achievement. First, the numbers are no longer 0, 0, this is because we don't want our second achievement to cover up our first one on our new page. Second, you'll notice instead of 'null' at the end, I've written 'Tutorial'. This way, the only way we can trigger that achievement is if we first trigger 'Tutorial'. And finally, you'll notice the .setSpecial() after the achievement is registered. This simply makes the achievement look like a special achievement in vanilla, such as 'The End'.
Now we can begin our new page.
First, you need to give your page a name, by writing this line of code in your main mod class:
public static AchievementPage TutorialPage;
This will give you an error because you have to import AchievementPage, so hover over that error and import it.
Next, you have to specify your achievement pages properties like this in your load() function:
TutorialPage = new AchievementPage("Tutorial Achievements", Tutorial, TutorialSecond);
AchievementPage.registerAchievementPage(TutorialPage);
The first field is what your page will be titled, in this case, "Tutorial Achievements", and the second and third fields are the achievements that will show up on the page. Here we have only two, but you can add as many as you want, just separate them with commas. The line below that, much like registering each individual achievement, simply registers your achievement page and is required for your page to work.
Looks great!! First time seeing a Forge Tut for this topic.
Looks like I am going to start working on some achievements tomorrow for my mods
The tut is clear, clean and simple to follow. The screen shots and code downloads is icing on the cake. Thank you very much for sharing your knowledge with the community.
Looks great!! First time seeing a Forge Tut for this topic.
Looks like I am going to start working on some achievements tomorrow for my mods
The tut is clear, clean and simple to follow. The screen shots and code downloads is icing on the cake. Thank you very much for sharing your knowledge with the community.
Nice too see you around Phobophobe, Is this your first time making tutorials?
Yup! The Achievements one was my first, made it on a request. I guess I was one of the first to figure out PickupHandlers for 1.4.6 so I figured I would share the knowledge. But the setting up a mod I just decided to make and I'll probably be adding much more soon, I'd love to hear what you think
New tutorial on blocks! Includes creating the block, adding to creative, and texturing. Next tuts will be recipes, also check the advanced section later for more advanced block properties.
I have encountered a small issue that I hope you would be able to help me in :/
I've figured out how to add entities and made an item that you can throw.
The item entity is registering properly, I've tested this through changing the damage the entity causes when it hits a mob.
My problem is that instead of the entity (while in mid air after thrown) showing the texture that I want it to, it instead renders as a small white cube. Is there something I'm doing wrong?
I threw it into the air and took a snapshot of it as it was coming back down to illustrate what I mean.
Picture:
I have encountered a small issue that I hope you would be able to help me in :/
I've figured out how to add entities and made an item that you can throw.
The item entity is registering properly, I've tested this through changing the damage the entity causes when it hits a mob.
My problem is that instead of the entity (while in mid air after thrown) showing the texture that I want it to, it instead renders as a small white cube. Is there something I'm doing wrong?
I threw it into the air and took a snapshot of it as it was coming back down to illustrate what I mean.
Picture:
public class EntityScrapMetal extends EntityThrowable {
[Lots of code including constructors and code that works]
public String getTexture() { return "/kyler/items/entScrap.png"; } }
I've never made throwable entities but if thats how its rendering then you probably need a renderer. Try copying rendersnowball and then you'll also have to register your renderer
I've never made throwable entities but if thats how its rendering then you probably need a renderer. Try copying rendersnowball and then you'll also have to register your renderer
Edit: Main question: How do you properly register a renderer in Forge?
It would be really nice if you would show how to set up a workspace for Mac/Windows/Lunix users.
Also please add how to make mobs and new dimensions and how to remove stuff the game already has.
If I added the setting up a workspace it would only be for mac, thats the only type of computer I have.
Also, because I have a mac, I can only make mobs that use the models already in minecraft.
Not really sure how to remove vanilla features other than editing base code, but I can look into it.
And finally, I can do a dimension tutorial, but currently my dimension mod isn't working when trying to add custom blocks, but I could show a dimension with all vanilla blocks.
Setting Up Your Mod Class
Inside that folder create a folder titled something like 'YourMod'. This means that in eclipse, your package will be 'mods.YourMod'. After you have your package, open eclipse and create a new file inside that package, and name it 'YourMod.java'. For the sake of the tutorial, it will be 'YourMod.java', but you can call it whatever you want.
The first thing you want to type in this new file is your package. To do this, type the code:
This just tells the program where your mod is located.
Then, you need to give your class a title, type this code:
The @Mod tells forge to load your mod, with the info next to it, i.e. the mod ID, name, and version number.
Make sure your Mod ID is all in lower case.
Everything that is in your mod, will be written inside the YourMod class.
Next, you need three new methods inside YourMod. These are:
Although all of these methods are pretty self explanatory, I will explain them anyway. The first method, is for things that you want to load before your mod is initialized. This method is usually used for generating configuration files. The next method is where the bulk of your mod will be written, because it loads things while your mod is initialized. The last method loads things after your mod is initialized, don't worry about that method because you most likely won't use it too much.
After adding all of those things, you will notice that a lot of code is underlined in red. This is most likely because you didn't import the necessary files. To import them, simply hover your mouse over the word highlighted in red, and click 'Import ******'
Your final file should look like this:
Now you're ready to mod!
Creating Blocks
The first thing you have to do for a block, is write this code in the body of your mod file:
This code tells minecraft that your making a block. Next, you will start assigning properties to your block by typing this into your load() function:
There are many properties you can set here that I will go into depth about later, but for now I will leave it to this. That first 256, is your blocks ID, and the material is what material your block is made of, this is crucial for things such as what tools will be effective against certain blocks. The UnlocalizedName IS NOT the name that will show up to people using your mod, it is simply for texturing. For example, if the name of my texture in the 'assets/tutorialblock/textures/blocks/' folder was 'testblock.png' my UnlocalizedName would be 'testblock'. All of that last sentence about texturing will be better explained in the texturing section of the tutorial. The hardness is how long the block will take to break, and its resistance is its resistance to explosions from things such as creepers and TNT.
At this point, eclipse will be giving you an error. YourOwnBlock should be underlined in red, but to fix this just hover over it and click 'Create class YourOwnBlock'.
You should now have a new class that looks like this:
Now you have to make your class extend Block, to do this, type 'extends Block' after 'YourOwnBlock' and then import Block by hovering over it and clicking 'import'. Next, you have to add a constructor, and you can do this by hovering over 'YourOwnBlock' (which should be underlined in red) and clicking 'Add constructor "YourOwnBlock(int, Material)"'. After all of this, your file should look like this:
After this, you have to head back to your main mod file for a few more lines of code.
Firstly, you have to register your block. Do this by writing this code in your load() function:
You will have to import GameRegistry.
The first YourBlock, is simply the name of your block in the code, the String is the same as the name that you declared in your blocks properties when you typed .setUnlocalizedName("yourblock").
Next, you have to set a name for your block that will show up to the player. You do this by typing this in your load() function:
You will have to import LanguageRegistry.
The first field again is the name of your block in the code, but this time the String is what name will show up inside of minecraft, in this case it's 'My First Block'.
Now your block is completely finished! In the next tutorial you will learn how to add your block to the creative menu.
Adding Your Block to Creative
This will make it show up in the creative inventory under 'Blocks'. Here are the names to all of the different tabs:
And now your block is in creative!
Textureing Your Block
Ewww...
So to fix that you have to do a little more. First, you need to make your own texture. Open up a program to edit images, such as Photoshop, or Gimp, and create a new file that is 16x16. Draw anything on it (hopefully appropriate) for your texture and save it to a folder in your mcp called 'assets/tutorialblock/textures/blocks/' and make sure the title is the same as the UnlocalizedName of your block. For the purposes of this tutorial the second folder is 'tutorialblock' however that folder should be named the same as your mod ID.
After this, there's a little bit of code you need to add. First, go into your block file, and add this method:
This method registers your icon, and tells Minecraft where to find it. However you will see that it gives you an error at 'TutorialBlock.modid'. This is because your main mod file, TutorialBlock.java, doesn't have a field called 'modid'. To fix this, hover over 'modid' and select 'Create field modid in type TutorialBlock', and it will create that field for you. Once created, your mod file should look like this:
We're almost done! The last thing you have to do before it will work properly is set the String 'modid' equal to your mods ID. This is done like this:
And now your block is perfectly textured!
Completed Code and Screenshots
Compiled
Decompiled
Screenshots of the Block
Advanced Updated for 1.7.10
Achievements
The first thing you will have to do is make your public static Achievement, and you will also have to import Achievement. It should look like this:
Next, you want to assign properties to your achievement like this:
It takes the form ("string", "string", int, int, Item, Achievement);
This line of code will go in your load() function.
The first String is only for more advanced achievements, we'll leave it blank for now, the String after that is your achievements name, this will be used later, the two ints after that dictate where your achievement appears on the achievement page, and will require a little bit of tinkering to get it in the right place (0, 0 will place your achievement directly on top of taking inventory), the item after that is only for what icon your achievement will show in the achievement page, in this case, a Golden Apple, and finally, the last field is what achievement yours requires to be triggered, but for now we will leave that as null.
Next, you will want to add a name and description to your achievement like this:
First you need to create a file called en_US.lang in the package "assets/tutorial/lang/en_US.lang" with tutorial being your mods package.
Inside of this file you will write:
The first line gives the name of the achievement, and the second gives the description.
Now you have officially created your own achievement.
Your file should now look like this:
There are many many different methods of triggering achievements, but I will be going over three of them.
First, you will need to register a new class in your load() function of your main mod file, like this:
Eclipse will now give you an error, and to solve this, hover over that error and click the option 'Create class "EventListener"' and eclipse will create that class for you.
You can call this class anything you want, but this is where you will put all of your forge events including crafting events, smelting events, and pickup events for triggering achievements.
After you have your event listener created, you can trigger your achievement by crafting by adding this line of code:
Or you can trigger it by smelting, by adding this line of code:
Or finally by picking up an item with this code:
What this code says, is if the item crafted is a golden apple, or smelted or picked up is a gold ingot, then give the player the achievement Tutorial (our achievement we made earlier).
Advanced Achievement Triggers
In this section, you will learn how to trigger an achievement on multiple item pickups/crafts/smelts.
First, you will need to set up an integer and set it equal to 0, for the sake of the tutorial, we'll call it 'applesFound'. To do this, you will want to add this line of code to your PickupHandler or CraftingHandler:
For my achievement, I would like to trigger it when I find 2 apples. To make this happen, you will change the code in the 'pickup' method to this:
This tells mine craft that every time an apple is picked up, the int 'applesFound' should have 1 added to it. After that, it checks to see if 'applesFound' is equal to 2, and if it is, the achievement is triggered.
For triggering an achievement on multiple items, you would simply do the same thing with multiple variables.
Say I want an achievement to be triggered when an apple and an iron ingot are found. For this, I would set up my variables like so:
And then I would go about setting the amounts I want for each item. Lets say I want it to be triggered when 2 iron ingots are found, and 1 apple is found. For this, I would have to add more parameters than before, and the code would end up looking like this:
You will see that the line:
Is giving you an error, but thats simply because we have not created that method yet, we will do so in a second. First, I would like to explain the code.
The first method is similar to before, adds 1 to 'applesFound' but then after that, runs the method 'triggerAchievementSecond()'. This is because we are working with 2 items.
The second method has the exact same function except it adds one to 'ironFound' instead.
Now we must create our new method to look like this:
First, it checks to see what the player has found, then, if the player has found 2 apples, and 1 iron, it triggers the achievement.
Important
Make sure that your variables in the if statement are written with a '>=' rather than a simple '=='. This ensures that your achievement will always be triggered. If they were set to '==' and the player found 3 apples before they found an iron, the achievement would never be triggered. Regardless of whether or not that makes any sense to you, just make sure that they are '>='.
The finished file will look a little something like this:
The lines that are commented out are our original trigger, with only one apple.
Custom Achievement Page
For an achievement page to work properly, you need at least two achievements so I quickly threw together this one.
Don't forget to add a name and description to your lang file like you did with the first achievement.
You can trigger this achievement using any of the methods we learned earlier, but for me I will trigger it upon picking up a Red Apple.
You'll notice a few different things about this second achievement. First, the numbers are no longer 0, 0, this is because we don't want our second achievement to cover up our first one on our new page. Second, you'll notice instead of 'null' at the end, I've written 'Tutorial'. This way, the only way we can trigger that achievement is if we first trigger 'Tutorial'. And finally, you'll notice the .setSpecial() after the achievement is registered. This simply makes the achievement look like a special achievement in vanilla, such as 'The End'.
Now we can begin our new page.
First, you need to give your page a name, by writing this line of code in your main mod class:
This will give you an error because you have to import AchievementPage, so hover over that error and import it.
Next, you have to specify your achievement pages properties like this in your load() function:
The first field is what your page will be titled, in this case, "Tutorial Achievements", and the second and third fields are the achievements that will show up on the page. Here we have only two, but you can add as many as you want, just separate them with commas. The line below that, much like registering each individual achievement, simply registers your achievement page and is required for your page to work.
Now your done!
Decompiled
Screenshots of the finished Achievement Mod
Looks like I am going to start working on some achievements tomorrow for my mods
The tut is clear, clean and simple to follow. The screen shots and code downloads is icing on the cake. Thank you very much for sharing your knowledge with the community.
Glad i could help
I'd love to see your mod when your done
Farewell everyone o/
Yup! The Achievements one was my first, made it on a request. I guess I was one of the first to figure out PickupHandlers for 1.4.6 so I figured I would share the knowledge. But the setting up a mod I just decided to make and I'll probably be adding much more soon, I'd love to hear what you think
Check it out here: http://www.minecraftforum.net/topic/1653560-147forge-brownies-100
I've added a reference to your profile and this topic.
Glad I helped
Vehicle Tutorial?
I've never really tampered with vehicles :/ So maybe after I take some time to figure them out
I have encountered a small issue that I hope you would be able to help me in :/
I've figured out how to add entities and made an item that you can throw.
The item entity is registering properly, I've tested this through changing the damage the entity causes when it hits a mob.
My problem is that instead of the entity (while in mid air after thrown) showing the texture that I want it to, it instead renders as a small white cube. Is there something I'm doing wrong?
I threw it into the air and took a snapshot of it as it was coming back down to illustrate what I mean.
Picture:
Entity Code:
package kyler.scrapmetal;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class EntityScrapMetal extends EntityThrowable {
[Lots of code including constructors and code that works]
public String getTexture() {
return "/kyler/items/entScrap.png";
}
}
I've never made throwable entities but if thats how its rendering then you probably need a renderer. Try copying rendersnowball and then you'll also have to register your renderer
Edit: Main question: How do you properly register a renderer in Forge?
Edit: Ah.. Nvm.. Figured it out.
Removing things from the game is something I would like to learn as well!
If I added the setting up a workspace it would only be for mac, thats the only type of computer I have.
Also, because I have a mac, I can only make mobs that use the models already in minecraft.
Not really sure how to remove vanilla features other than editing base code, but I can look into it.
And finally, I can do a dimension tutorial, but currently my dimension mod isn't working when trying to add custom blocks, but I could show a dimension with all vanilla blocks.