Hey All, this is my first tutorial so bear with me. I am primarily a Microsoft developer and I was at Build 2015 when they announced the new Minecraft Mod project type. Since my kids and I are really in to Minecraft, I had to give it a shot. Without further ado, here's a guide on how to build a mod using VS 2015 (which you can download for free by the way). This was originally a blog post but I wanted to post it here as well in case it helps any of you out (and I got permission to do so just to make sure I wasn't being rude).
Getting Started
To get started, make sure you have the x64 version of Java SE Development Kit (JDK) for Windows. With that out of the way, you are ready to grab the Minecraft Mod Developer Pack extension for Visual Studio. Once installation is complete, create a new project:
IMPORTANT NOTE: You probably already know this, but, the difference between Version 1.7.10 and 1.8 is vast. If you choose to create a 1.8 mod (and you should; no sense in learning an old version), make sure the documentation you are looking at is for 1.8 and not an older version. For example, setting textures on blocks/items is totally different as of 1.8 (it is configured via JSON instead of by calling a method).
As you can see, in a fit of cleverness and originality I have named my project “Hello Minecraft”. When your project is created, Visual Studio will download a bunch of third-party packages and do a one-time provisioning build. It takes 5-20 minutes. For the curious, here is my build log. At this point we are ready to rock. Let’s hit F5 to debug the project just to make sure everything is working (since I am a skeptic at heart):
Creating a Block
Getting the mod project up and running was surprisingly easy. Next, we need to figure out something we want to modify. Since nobody else in the world is making custom TNT blocks (hah), let’s go ahead and build a custom TNT block.
Most of the TNT mods I have seen have been focused on making a bigger, better explosion. Being a man of restraint, I am going to create a smaller, wimpy explosion. In fact, Wimpy TNT is a great name for our new block! In /src/main/java/com/wimpy-tnt/WimpyTNTBlock (you will have to create the wimpy-tnt and WimpyTNTBlock subfolders) let’s create a class called WimpyTNTBlock. In that class, we will start to define our new block:
package hellominecraft.wimpytntmod;
// I know there are a lot of imports here... we will use them later in the demo!
import net.minecraft.block.Block;
import net.minecraft.block.BlockTNT;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraft.world.World;
import net.minecraft.world.Explosion;
import net.minecraft.util.BlockPos;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.init.Items;
import net.minecraft.client.Minecraft;
public class WimpyTNTBlock extends Block
{
private final String name = "wimpyTNT";
public WimpyTNTBlock ()
{
super(Material.tnt);
setUnlocalizedName(name);
// We want this to show up on the "block" tab in creative mode.
setCreativeTab(CreativeTabs.tabBlock);
}
public String getName()
{
return name;
}
}
Disclaimer: the spacing in my code here is messed up because I couldn't figure out how to get the forum software to not remove my whitespace (and using the pre tag makes the newlines FUBAR). Reformat it as you wish.
Next, we are going to need to set our mod up and instantiate / register our new block. In/src/main/java/com/wimpy-tnt/ create a class called WimpyTNTMod with the following content:
@Mod(modid = WimpyTNTMod.MODID, name = WimpyTNTMod.NAME, version = WimpyTNTMod.VERSION)
public class WimpyTNTMod
{
public static final String MODID = "WimpyTNT";
public static final String VERSION = "1.0";
public static final String NAME = "Wimpy TNT Mod";
public static Block wimpyTNT;
@EventHandler
public void init(FMLInitializationEvent event)
{
wimpyTNT = new WimpyTNTBlock();
GameRegistry.registerBlock(wimpyTNT, "wimpyTNT");
}
}
Your /src folder should now look something like this in solution explorer:
Alright - let’s fire this baby up. For testing, debugging (at least on my machine) is painfully slow. For a faster experience, let’s fire the project up without debugging (Ctrl + F5):
If you go to the Mod List, you should find that our new mod shows up with the correct Name and Version:
Create a new world in Creative mode and you will see our new block is available:
Custom Textures
Let’s give our new block a custom texture. Using the most cutting-edge tools available (*ahem*), I created a PNG that I want to use as the texture for Wimpy TNT:
In order to set our block’s texture, we first need to add our texture image (named wimpyTNT.png) to/src/main/resources/assets/wimpytnt/textures/blocks. Next we need to create 3 JSON configuration files for our block:
To do this, I used an invaluable utility created by wuppy21. It will auto-generate the JSON files for you and all you have to do is move them in to your project. When you have all 3 JSON files and the texture image, your solution explorer should look like this:
Now when you run the project you can place the block and it will have the correct texture:
To fix the texture on inventory and when holding the item in your hand, we need to register a renderer for our block. Add the following to your init method in your WimpyTNTMod class:
// Register a renderer for our wimpy TNT block
renderItem.getItemModelMesher().register(Item.getItemFromBlock(wimpyTNT), 0, new ModelResourceLocation(WimpyTNTMod.MODID + ":" + ((WimpyTNTBlock)wimpyTNT).getName(), "inventory"));
}
This page was extremely helpful to me when trying to figure this out since most of the samples I found were prior to version 1.8. With this code in place, fire up the project and you will see that you are in good shape with regards to textures:
Give it a Name
Our name is still not ideal. To fix this, we need to add a lang file to/src/main/resources/assets/wimpytnt/lang/. Let’s create the lang folder and add en_US.lang to it:
The file needs the following line to give our block a name: tile.wimpyTNT.name=Wimpy TNT (huge thanks to this thread for helping me figure this out). The next time you debug the app, when you hover over your new block, the name is displayed:
Explode!
Let’s make this block explode when you activate it with flint. I did a bit of spelunking in to the decompiled code for BlockTNT and, luckily, creating an explosion is easy. Add the following method to your WimpyTNTBlock class:
if (item == Items.flint_and_steel || item == Items.fire_charge)
{
// Let's set our wimpy TNT block to air because it is exploding...
worldIn.setBlockToAir(pos);
// You can bump the force up/down here if you like.
float force = .5F;
// Create the explosion in our world.
worldIn.createExplosion(null, pos.getX(),
pos.getY(), pos.getZ(), force, true);
You should now be able to hit it with flint and steel to make it explode. It’s pretty underwhelming, but, that’s why we named it Wimpy TNT. Here is a video of it in action:
... and that's it. You can download the source for this project here. If you have any suggestions for edits, send me a pull request! Also, let me know what you think or if you have any suggestions for edits on this guide.
I did not know that it was possible to develop using VS! What are the Minecraft templates/framework available? Is it just the three in the picture?
Other reaction; Java in VS? What kind of sorcery is this
Dark magic to be sure! Well, maybe not *that* dark:
Sam Harwell's Java Language Support VS extension is the project providing the Java project system, build system, basic editor facilities and the rich Java debugger capabilities in Visual Studio.
Eclipse JDT is bundled together with this project as an Eclipse application and is used to provide all IntelliSense and browsing information inside the VS editor.
The example you posted looks correct to me. Which probably means there is something else that is preventing you from seeing the correct name associated with your block. Off the top of my head, I would say check these lines to make sure you are using "wimpyTNT" exactly (case-sensitive) as the name (when you click on these links, there will be a line highlighted):
Ferdz, I forgot to answer your question. Yes, at the moment it is just the three available in the picture. I would have edited my previous post but every time I edit a post with a quote my quote tags get messed up for some reason. Editing the markup doesn't seem to fix it.
Thanks for starting this, as there is not much out there to help get started yet with this path.
Just messing around with it was pretty simple and easy to understand. Some additions I uncovered as I followed the trail of some of the objects you used in your tutorial are elaborated on below. If there is a better way to do any of these things, please share feedback.
To specify block properties like hardness, resistance, and step sound:
Edit WimpyTNTMod.java
In the beginning of the class, add a sound:
public static final Block.SoundType soundTypeStone = new Block.SoundType("stone", 1.0F, 1.5F);
More examples of sounds are available if you follow the definition (F12) to the Block class
I believe the string is for associating to existing sound files, and there are additional ways to specify dig and break sounds if different than main source
The 2nd and 3rd arguments are for volume and frequency respectively
At the beginning of the init method, update the setting of the wimpyTNT static block to:
wimpyTNT = (new WimpyTNTBlock()).setHardness(0.0F).setResistance(0.0F).setStepSound(soundTypeStone);
Again, the Block class is your friend here for other references on values for hardness (how long it takes to destroy a block) and resistance (how strong the block is against explosions); thanks to Creating_Blocks for the extra details on these methods
The soundTypeStone value passed into setStepSound is what you defined earlier
Also if you could answer another question for me as I am absolutely new to java, that would be appreciated.
When I want to set attributes such as sound or crafting recipes, where exactly do I put the code? Like a screenshot, so I know where in the class it goes would be appreciated.
Excellent tutorial! I was able to follow along and get it to work.
I wish that Visual Studio would include the templates for the json and lang files when you select to add a new item, but that's outside the scope of the tutorial and just a wish on my part.
Other reaction; Java in VS? What kind of sorcery is this
Try VS 2015, Microsoft added full Java support!
As far as MC modding goes, there's actually a extension (published by microsoft) which does the entire work of setting up the project for you. (And includes Mekanism as an example mod to boot!)
So as far as I can tell, Microsoft is using it's acquiring of Minecraft for good, not evil! : )
As far as MC modding goes, there's actually a extension (published by microsoft) which does the entire work of setting up the project for you. (And includes Mekanism as an example mod to boot!)
So as far as I can tell, Microsoft is using it's acquiring of Minecraft for good, not evil! : )
Mankind is the caretaker of nature, having been granted this responsibility by the Creator. Naturally, we screwed up and the Creator had to sacrifice His Son so we would not be destroyed. He is risen, as all shall be one day. Anyone who puts his trust in the Son of God will reign with Him forever; anyone who does not will be destroyed forever.
Also if you could answer another question for me as I am absolutely new to java, that would be appreciated.
When I want to set attributes such as sound or crafting recipes, where exactly do I put the code? Like a screenshot, so I know where in the class it goes would be appreciated.
I know this is *way* late (I have been really busy!) but did you get it working? If not, I will try to help you troubleshoot it.
Is it really? I guess that kind of makes sense because in terms of performance, C++ is hard to compete with. I just did some searching and it doesn't appear as though Minecraft 10 has taken over yet. It also is purely for Windows 10 (hence them ditching previous versioning numbers) and I wonder if they abandoned that project. Completely scrapping the codebase and starting over seems like a pretty large undertaking.
Hey All, this is my first tutorial so bear with me. I am primarily a Microsoft developer and I was at Build 2015 when they announced the new Minecraft Mod project type. Since my kids and I are really in to Minecraft, I had to give it a shot. Without further ado, here's a guide on how to build a mod using VS 2015 (which you can download for free by the way). This was originally a blog post but I wanted to post it here as well in case it helps any of you out (and I got permission to do so just to make sure I wasn't being rude).
Getting Started
To get started, make sure you have the x64 version of Java SE Development Kit (JDK) for Windows. With that out of the way, you are ready to grab the Minecraft Mod Developer Pack extension for Visual Studio. Once installation is complete, create a new project:
IMPORTANT NOTE: You probably already know this, but, the difference between Version 1.7.10 and 1.8 is vast. If you choose to create a 1.8 mod (and you should; no sense in learning an old version), make sure the documentation you are looking at is for 1.8 and not an older version. For example, setting textures on blocks/items is totally different as of 1.8 (it is configured via JSON instead of by calling a method).
As you can see, in a fit of cleverness and originality I have named my project “Hello Minecraft”. When your project is created, Visual Studio will download a bunch of third-party packages and do a one-time provisioning build. It takes 5-20 minutes. For the curious, here is my build log. At this point we are ready to rock. Let’s hit F5 to debug the project just to make sure everything is working (since I am a skeptic at heart):
Creating a Block
Getting the mod project up and running was surprisingly easy. Next, we need to figure out something we want to modify. Since nobody else in the world is making custom TNT blocks (hah), let’s go ahead and build a custom TNT block.
Most of the TNT mods I have seen have been focused on making a bigger, better explosion. Being a man of restraint, I am going to create a smaller, wimpy explosion. In fact, Wimpy TNT is a great name for our new block! In /src/main/java/com/wimpy-tnt/WimpyTNTBlock (you will have to create the wimpy-tnt and WimpyTNTBlock subfolders) let’s create a class called WimpyTNTBlock. In that class, we will start to define our new block:
package hellominecraft.wimpytntmod;
// I know there are a lot of imports here... we will use them later in the demo!
import net.minecraft.block.Block;
import net.minecraft.block.BlockTNT;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraft.world.World;
import net.minecraft.world.Explosion;
import net.minecraft.util.BlockPos;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.init.Items;
import net.minecraft.client.Minecraft;
public class WimpyTNTBlock extends Block
{
private final String name = "wimpyTNT";
public WimpyTNTBlock ()
{
super(Material.tnt);
setUnlocalizedName(name);
// We want this to show up on the "block" tab in creative mode.
setCreativeTab(CreativeTabs.tabBlock);
}
public String getName()
{
return name;
}
}
Disclaimer: the spacing in my code here is messed up because I couldn't figure out how to get the forum software to not remove my whitespace (and using the pre tag makes the newlines FUBAR). Reformat it as you wish.
Next, we are going to need to set our mod up and instantiate / register our new block. In/src/main/java/com/wimpy-tnt/ create a class called WimpyTNTMod with the following content:
package hellominecraft.wimpytntmod;
import net.minecraft.init.Blocks;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.client.resources.model.ModelResourceLocation;
@Mod(modid = WimpyTNTMod.MODID, name = WimpyTNTMod.NAME, version = WimpyTNTMod.VERSION)
public class WimpyTNTMod
{
public static final String MODID = "WimpyTNT";
public static final String VERSION = "1.0";
public static final String NAME = "Wimpy TNT Mod";
public static Block wimpyTNT;
@EventHandler
public void init(FMLInitializationEvent event)
{
wimpyTNT = new WimpyTNTBlock();
GameRegistry.registerBlock(wimpyTNT, "wimpyTNT");
}
}
Your /src folder should now look something like this in solution explorer:
Alright - let’s fire this baby up. For testing, debugging (at least on my machine) is painfully slow. For a faster experience, let’s fire the project up without debugging (Ctrl + F5):
If you go to the Mod List, you should find that our new mod shows up with the correct Name and Version:
Create a new world in Creative mode and you will see our new block is available:
Custom Textures
Let’s give our new block a custom texture. Using the most cutting-edge tools available (*ahem*), I created a PNG that I want to use as the texture for Wimpy TNT:
In order to set our block’s texture, we first need to add our texture image (named wimpyTNT.png) to/src/main/resources/assets/wimpytnt/textures/blocks. Next we need to create 3 JSON configuration files for our block:
To do this, I used an invaluable utility created by wuppy21. It will auto-generate the JSON files for you and all you have to do is move them in to your project. When you have all 3 JSON files and the texture image, your solution explorer should look like this:
Now when you run the project you can place the block and it will have the correct texture:
To fix the texture on inventory and when holding the item in your hand, we need to register a renderer for our block. Add the following to your init method in your WimpyTNTMod class:
//register renders
if(event.getSide() == Side.CLIENT)
{
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
// Register a renderer for our wimpy TNT block
renderItem.getItemModelMesher().register(Item.getItemFromBlock(wimpyTNT), 0, new ModelResourceLocation(WimpyTNTMod.MODID + ":" + ((WimpyTNTBlock)wimpyTNT).getName(), "inventory"));
}
This page was extremely helpful to me when trying to figure this out since most of the samples I found were prior to version 1.8. With this code in place, fire up the project and you will see that you are in good shape with regards to textures:
Give it a Name
Our name is still not ideal. To fix this, we need to add a lang file to/src/main/resources/assets/wimpytnt/lang/. Let’s create the lang folder and add en_US.lang to it:
The file needs the following line to give our block a name: tile.wimpyTNT.name=Wimpy TNT (huge thanks to this thread for helping me figure this out). The next time you debug the app, when you hover over your new block, the name is displayed:
Explode!
Let’s make this block explode when you activate it with flint. I did a bit of spelunking in to the decompiled code for BlockTNT and, luckily, creating an explosion is easy. Add the following method to your WimpyTNTBlock class:
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (playerIn.getCurrentEquippedItem() != null)
{
Item item = playerIn.getCurrentEquippedItem().getItem();
if (item == Items.flint_and_steel || item == Items.fire_charge)
{
// Let's set our wimpy TNT block to air because it is exploding...
worldIn.setBlockToAir(pos);
// You can bump the force up/down here if you like.
float force = .5F;
// Create the explosion in our world.
worldIn.createExplosion(null, pos.getX(),
pos.getY(), pos.getZ(), force, true);
return true;
}
}
return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
}
You should now be able to hit it with flint and steel to make it explode. It’s pretty underwhelming, but, that’s why we named it Wimpy TNT. Here is a video of it in action:
... and that's it. You can download the source for this project here. If you have any suggestions for edits, send me a pull request! Also, let me know what you think or if you have any suggestions for edits on this guide.
I did not know that it was possible to develop using VS! What are the Minecraft templates/framework available? Is it just the three in the picture?
Other reaction; Java in VS? What kind of sorcery is this
Check out my mod, Placeable Items!
If my comment helped you or you just like me, hit the green arrow down there!
I can't do the texture, what did you use? Also, the name won't work, even when I put in, tile.wimpyTNT.name=Wimpy TNT what else do I have to put?
Dark magic to be sure! Well, maybe not *that* dark:
I used Paint to create the texture. You can snag the actual texture I am using from the project on GitHub here:
https://github.com/DeanPDX/hello-minecraft/blob/master/Hello Minecraft/src/main/resources/assets/wimpytnt/textures/blocks/wimpyTNT.png
Regarding the Lang file, you can see the entire contents of my en_US.lang file here:
https://github.com/DeanPDX/hello-minecraft/blob/master/Hello Minecraft/src/main/resources/assets/wimpytnt/lang/en_US.lang
The example you posted looks correct to me. Which probably means there is something else that is preventing you from seeing the correct name associated with your block. Off the top of my head, I would say check these lines to make sure you are using "wimpyTNT" exactly (case-sensitive) as the name (when you click on these links, there will be a line highlighted):
https://github.com/DeanPDX/hello-minecraft/blob/master/Hello Minecraft/src/main/java/com/wimpy-tnt/WimpyTNTBlock/WimpyTNTBlock.java#L22
https://github.com/DeanPDX/hello-minecraft/blob/master/Hello Minecraft/src/main/java/com/wimpy-tnt/WimpyTNTMod.java#L31
Ferdz, I forgot to answer your question. Yes, at the moment it is just the three available in the picture. I would have edited my previous post but every time I edit a post with a quote my quote tags get messed up for some reason. Editing the markup doesn't seem to fix it.
Yeah I know the feeling, the text editor of the forums is so broken .. :/
Check out my mod, Placeable Items!
If my comment helped you or you just like me, hit the green arrow down there!
Thanks! I got it now.
Thanks for starting this, as there is not much out there to help get started yet with this path.
Just messing around with it was pretty simple and easy to understand. Some additions I uncovered as I followed the trail of some of the objects you used in your tutorial are elaborated on below. If there is a better way to do any of these things, please share feedback.
To specify block properties like hardness, resistance, and step sound:
To give your block a crafting recipe:
Nice! I like these additions!
Thanks deeewwwwwwwwwwwwwwwddddddd this is great!
I got this error please help
What error did you get?
Hello. I seem to be having trouble with the textures and name. Everything else seems to work fine and I appreciate your help.
I even copied and pasted from your github to make sure it was correct, and I also downloaded your json files and texture.
Here is the project zip so you can look at it in VS if you wouldn't mind.
https://www.mediafire.com/?wftk1h78ed0xb2c
Also if you could answer another question for me as I am absolutely new to java, that would be appreciated.
When I want to set attributes such as sound or crafting recipes, where exactly do I put the code? Like a screenshot, so I know where in the class it goes would be appreciated.
Sig by Bigkaboom12.
Excellent tutorial! I was able to follow along and get it to work.
I wish that Visual Studio would include the templates for the json and lang files when you select to add a new item, but that's outside the scope of the tutorial and just a wish on my part.
Try VS 2015, Microsoft added full Java support!
As far as MC modding goes, there's actually a extension (published by microsoft) which does the entire work of setting up the project for you. (And includes Mekanism as an example mod to boot!)
So as far as I can tell, Microsoft is using it's acquiring of Minecraft for good, not evil! : )
Except that Minecraft 10 is in C++ D':
Check out my mod, Placeable Items!
If my comment helped you or you just like me, hit the green arrow down there!
Which version of VS2015 did you use? Express, Community, Code, Enterprise??
Why did you purposely avoid sarcasm?
Mankind is the caretaker of nature, having been granted this responsibility by the Creator. Naturally, we screwed up and the Creator had to sacrifice His Son so we would not be destroyed. He is risen, as all shall be one day. Anyone who puts his trust in the Son of God will reign with Him forever; anyone who does not will be destroyed forever.
I know this is *way* late (I have been really busy!) but did you get it working? If not, I will try to help you troubleshoot it.
Is it really? I guess that kind of makes sense because in terms of performance, C++ is hard to compete with. I just did some searching and it doesn't appear as though Minecraft 10 has taken over yet. It also is purely for Windows 10 (hence them ditching previous versioning numbers) and I wonder if they abandoned that project. Completely scrapping the codebase and starting over seems like a pretty large undertaking.
Community Edition.