Amazon Ad

Sunday, February 12, 2017

Bonus Material: Raytrace and onItemRightClick event

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW BASIC JAVA, THIS MAY NOT BE RIGHT FOR YOU!!!

I'm gonna show you some bonus material for your minecraft mod. It was asked that I cover item properties, such as a specific ability when you right click with the item in your hand. Let's get started, shall we?

Let's start by creating an item that spawns lightning right where the player is looking. Create the texture for it first. I'm gonna use this texture:


You can use the texture too, you can download it from here.

Let's create an item and a class for this item.

1
public static Item lightningSpawner;

initialize it with our new ItemLightningSpawner class that we will create momentarily. Give it the parameters of name, and creative tab. But this time we are gonna give it a third parameter of maxStackSize, we will make it NOT stack. This is done by putting 1 as our third parameter.

Let's create the class and it's constructor just like our last item, extending to ModItem.

1
2
3
4
5
public class ItemLightningSpawner extends ModItem {
 public ItemLightningSpawner(String name, CreativeTabs tab, int size) {
  super(name, tab, size);
 }
}

Now we need to override the super's method onItemRightClick. This is one of the super methods inherited from the Item class that is activated when you hold an item in your hand and right click with it. There is this and onItemUse which the difference between the two is that the latter is only called when the cursor is on a block and you right click. We need to override the former and tell it to get the raytrace of the cursor, get the block position that it is on, and then spawn a lightning bolt right where it is.

1
2
3
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
}

Let's start by testing if the side is a server or not by calling world.isRemote. This just specifies whether it is a client or not.

1
2
if(!worldIn.isRemote){
}

So we are testing if the world is on the client side or the server side because we want to spawn the lightning bolt as an entity in the world and we want it to show up for both the client and the server. Within this we need to create an object that stores the raytrace information of the player.

1
RayTraceResult pos = playerIn.rayTrace(100, 20);

The raytrace is the current position of the cursor in the world. It stores information like what block the player is looking at, what direction in the world the player is facing, what kind of block the player is looking at, etc. What we want is the block position of the cursor. We are setting the first value to 100 so that it gets the block position within 100 blocks. I don't know what the second position is but I believe it's the timespan the vector looks back in and whatever blockpos you were looking at during that time. So this example does 20 ticks, so whatever block pos you were looking at 20 ticks ago, it gets that information. I could be wrong though, so please correct me if I am wrong.

Next, we need to get the x, y, and z coordinates of the raytrace block position.

1
2
3
double x = pos.getBlockPos().getX();
double y = pos.getBlockPos().getY();
double z = pos.getBlockPos().getZ();

This does exactly what we want. It gets the x, y, and z coordinates of the current look vector of the player. Next we need to add the weather effect, and return the ActionResult as a success.


1
worldIn.addWeatherEffect(new EntityLightningBolt(worldIn, x, y, z, true));

This line of code just spawns in a new weather effect as an entity in the world. We create a new instance of EntityLightningBolt and we give it the parameters of world, x, y, z, true. It needs the world and the position it's spawning in. The true parameter, I honestly don't know what it does, but I'll look into it and update when I find out.


1
return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(this));

This returns a successful action result event. I don't know much about it except that it is necessary. We pass in our class as the item for the item stack.

We need to complete the check we did earlier but including an else statement to our if.


1
2
3
else{
    return new ActionResult(EnumActionResult.FAIL, new ItemStack(this));
}

This ensures that whether the world is on client side, it doesn't fire for only the player, but for the entire server world.

Now we need models. Create the models for the item and texture and fire up the game. Get the item out of the creative tab and right click with it in your hand. Play with the lightning. It's fun!

Thursday, February 9, 2017

Armor

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!


Let's start by creating our Armor's Items. Create a class called ArmorHandler in your Handler package. Within this we need to create our init, register, registerRenders, and registerRender(Item item) methods. Next wee need to create the items for our Armor.


1
2
3
4
public static Item tutHelmet;
public static Item tutChest;
public static Item tutLegs;
public static Item tutBoots;

We need to initialize them using a class we will create called ItemTutArmor. We are going to give it the parameters of NAME, CREATIVE TAB, ARMOR MATERIAL (we will create our own), and RENDER INDEX, EQUIPMENTSLOT.

The name and creative tab are pretty much self explanatory. The armor material is what will be our armor's durability, armor texture, strength, etc. The render index is what armor model it will use. Legs use a different model than the others. EquipmentSlot is what slot the armor is gonna go into, helmet goes into HEAD, chest goes into CHEST, etc.

1
2
3
4
tutHelmet = new ItemTutArmor("tut_helmet", CreativeTabHandler.tabCombat, MaterialHandler.TUTORIAL_ARMOR, 0, EntityEquipmentSlot.HEAD);
tutChest = new ItemTutArmor("tut_chest", CreativeTabHandler.tabCombat, MaterialHandler.TUTORIAL_ARMOR, 0, EntityEquipmentSlot.CHEST);
tutLegs = new ItemTutArmor("tut_legs", CreativeTabHandler.tabCombat, MaterialHandler.TUTORIAL_ARMOR, 1, EntityEquipmentSlot.LEGS);
tutBoots = new ItemTutArmor("tut_boots", CreativeTabHandler.tabCombat, MaterialHandler.TUTORIAL_ARMOR, 0, EntityEquipmentSlot.FEET);

Now we need to create the ItemTutArmor class. We need to set it up so that it utilizes our name and creative tab.


1
2
3
4
5
6
 public ItemTutArmor(String name, CreativeTabs tab, ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn) {
  super(materialIn, renderIndexIn, equipmentSlotIn);
  setUnlocalizedName(name);
  setRegistryName(name);
  setCreativeTab(tab);
 }

We also need to extend our class to ItemArmor. Once you have done that, let's go ahead and create our ArmorMaterial. Our Armor Material is going to go into our MaterialHandler. We need to create a constant that will hold our armor material for us.


1
public static final ArmorMaterial NAME_OF_MATERIAL = EnumHelper.addArmorMaterial("<materialName>", "<textureName>", <durability>, new int[]{<headArmorPiecesAmount>, <chestArmorPiecesAmount>, <legsArmorPiecesAmount>, <feetArmorPiecesAmount>}, <enchantability>, <sound>, <toughtness>);

This is the format that we will go by for our material. Replace the corresponding name with whatever values that you want there. For me I am gonna go with the following:


1
public static final ArmorMaterial TUTORIAL_ARMOR = EnumHelper.addArmorMaterial("tutorial_armor", "tut:tutorial_armor", 1500, new int[]{3, 5, 4, 2}, 10, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 8F);

The name is the registry name, I have already went over this. The texture name is the name of the armor model texture. It is in the format of texture_name_layer_0 or texture_name_layer_1. As mentioned earlier, there is two different models. layer_0 is the layer that includes the helmet, chest, and boots. layer_1 is the layer with the pants. Next, the durability is how many times the armor can be hit before breaking. The integer array with the 4 different integers is how many halves of armor will be filled in the GUI, at the armor bar. The enchantability is the same as the tool enchantability. The sound is the sound that is played when you put on the armor. Lastly, the toughness is how tough it is, obviously. I don't know much about this but when I do, I will be sure to update.

Next is to create the armor textures. Make the textures. I will be borrowing from my mod, Mara: The Ultimate Nightmare (be sure to check it out. Link at the end of the tutorial!). We need to put the armor model textures in the folder textures/models/armor. Save your textures in the correct locations (the item textures in the item texture location). Register the armor and it's rendering and you finally have armor.

MAKE SURE YOU PUT YOUR ARMORHANDLER INIT, REGISTER, AND REGISTERRENDERS IN YOUR PROXIES!!!

The following is my result:



=====================================Armor Properties=====================================

If you would like to add potion effects to your armor, then here is how to:

Go into your Armor class and put in the onArmorTick method.


1
2
3
4
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
  
}

Within this we need to call on the player method addPotionEffect and pass in a new instance of PotionEffect. We then need to pass in an argument that is the potion effect (you can get the effect from MobEffects class). We also need to pass in the duration (in ticks) and the amplifier (whether it is I, II, III, etc).


1
player.addPotionEffect(new PotionEffect(MobEffects.HEALTH_BOOST, 100, 2));

I am adding a health boost when the armor is worn.


Congratulations, you just successfully made armor.

Saturday, February 4, 2017

Paint.NET Textures

I said I would do it, and here I am doing it now: Paint.NET Textures Tutorial!

What we need are two things: the vanilla minecraft assets folder, and Paint.NET (obviously). So let's go and get the assets folder first. We need to go to our ".gradle" folder in our User Directory. If you go to your User Directory > .gradle > caches > minecraft > net > minecraft > minecraft > 1.11.2 then there should be a JAR there with the appropriate name of minecraft-1.11.2.jar. If we right click that and go to 7-Zip > Open Archive then there should be a bunch of files and folders there waiting for us to extract them. Now, don't click extract because what we want is the assets folder. Open up your workspace directory, being the main mod folder, and drag and drop the assets folder into your main mod folder. Now close out of your 7-Zip.

Next, we gotta go to getpaint.net. There you should see the download on the top right-hand side of the page. Down a little ways should be a download button, in the form of an image. Once clicked, you should see a download link at the top right-hand section of the page. Click, download, run, and follow the on screen prompts. Once it is done installing (may take a few minutes), then open up Paint.NET.

Now once in Paint.NET, you're gonna want to click Open and navigate to the assets folder in your main mod class, and navigate to textures > blocks > find your texture. Let's use the diamond_ore.png texture.

Let's play with the hue and saturation. Go to Adjustments > Hue / Saturation.... Change the hue until it fits your liking.

TIP: YOU MIGHT WANT TO ZOOM IN ON THE IMAGE BY HOLDING CONTROL AND SCROLL UP BEFORE ADJUSTING ANYTHING

I'm gonna make my texture a reddish color. Mine are at 180 for hue, and 139 for saturation, but it is your texture so make it however you wish to make it.

Let's do CTRL+SHIFT+S and save it to our mod folder > src > main > resources > assets > tut > textures > blocks.

If you don't have textures.blocks created, then create it.

We need to save it with the name that we specified in our JSON file, back in the Blocks tutorial. Ours is tut_block, so let's save it as tut_block.png.

Here is my finished result:


Let's make an item texture. Go back into Paint.NET and open up a texture from assets > minecraft > textures > items. Let's use the diamond.png texture.

Go to adjustments > Hue / Saturation... and play with the settings until it fits your likings. I'm going to keep mine where it is from the block texture settings, giving it, too, a reddish color. CONTROL + SHIFT + S and save it to src > main > resources > assets > tut > textures > items. If you don't have an items folder then create one. We also have to save this with the name that we specified in our JSON file that we created for our item, created back in the Items tutorial Here is my finished product for the item texture:


Now go back to the project and run the game and you should have the textures loaded in.

Thursday, February 2, 2017

Ore Gen

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!


In this tutorial, we will be looking at how ore generation works. We will be generating our block/ore that we created back in the blocks tutorial. Let's start by creating a package called "com.<yourname>.tut.world". In here we will create a class called "WorldGenOre". We will implement IWorldGenerator and add the unimplemented method, generate. In this method we will have a switch method, that switches through the different dimensions.


1
2
3
4
5
 public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
  switch(world.provider.getDimension()){
  
  }
 }

We get the dimension type through world.provider.getDimension(). This is an integer that is given to each dimension as a unique ID. Nether is -1, Overworld is 0, and End is 1. So we need to specify what happens in each of these cases.

We want to create a method for each of these dimensions, genSurface, genNether, and genEnd.

Within each of these, let's start with genSurface, we want to call a method, that we will make, called addOreSpawn.


1
2
3
private void genSurface(World world, Random random, int chunkX, int chunkZ){
 addOreSpawn(BlockHandler.tutBlock.getDefaultState(), world, random, chunkX, chunkZ, 16, 16, 50, 20, 10, 100, BlockMatcher.forBlock(Blocks.STONE));
}

It takes in 12 arguments: block to spawn, the world, random, chunkX, chunkZ, maxX, maxZ, the chance of it spawning, minimum Y spawn, max Y spawn, and block to generate in.

Block to spawn is the block that we are generating, obviously.

The World is self explanatory, and so is random.

ChunkX is the chunk on the X axis that is being generated. It is often a 16 X 256 X 16 cube of cubes. 256 is the highest Y value a block can be placed in the world. 16 is the max size of the chunk on the X and Z axis.

MaxX and MaxZ are the max size of the chunk that the ore can be generated in. The maths goes like this:

16 + rand.nextInt(16)

So technically, the max X spawn can be generated anywhere along the X axis in a chunk between 16 and 32. The same goes for the Z spawn.

MaxVeinSize is the max number of blocks that will be spawned in a vein.

Chance is the chance that the block will be spawned. It iterates through a for loop and the lower the number, the rarer, because it goes through the entire chunk and generates that many times in the chunk. If you put 1, it will only generate 1 vein in a chunk.

MinY and MaxY are are the Y spawn coords for the vein. We work out a random number between the two parameters.

BlocksToSpawnIn is the block that the ore will be found in. We will choose STONE for this.

Let's create the addOreSpawn method and implement our for loop and generate our ores.

1
2
3
4
5
6
7
8
9
 private void addOreSpawn(IBlockState block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chance, int minY, int maxY, Predicate<IBlockState> blockToSpawnIn){
  int diffMinMaxY = maxY - minY;
  for(int x = 0; x < chance; x++){
   int posX = blockXPos + random.nextInt(maxX);
   int posY = minY + random.nextInt(diffMinMaxY);
   int posZ = blockZPos + random.nextInt(maxZ);
   (new WorldGenMinable(block, maxVeinSize, blockToSpawnIn)).generate(world, random, new BlockPos(posX, posY, posZ));
  }
 }

First, we get the range of the min and max Y values. Then we iterate through our chance, and iterate through it. Next we created a posX, posY, and posZ. The posX is a random number between the chunk boundary and a random number of the other chunk boundary, being 16 + rand(16). The same applies for the Z axis. The posY is a random number between the min Y and a random number of the difference of the min and max Y. Then we instantiate a new WorldGenMinable which is how we generate our ore in the world. We give it the arguments of the block state, max vein size, and the block to spawn in. We then call the WorldGenMinable.generate method, and give it the arguments world, random, and a new BlockPos, given the posX, posY, and posZ values.

Our blockToSpawnIn is a predicate of a block state. I don't know too much about it, so I can't discuss it too much.

We get the block state of the block we want to generate because some blocks have different state. For example: redstone. It has lit and unlit blockstates It generates the default blockstate, being unlit, so that it can change between lit and unlit within the world.

Now we need to register our world generator. Go into your CommonProxy and register the World Generator we created.


1
GameRegistry.registerWorldGenerator(new WorldGenOre(), 0);

The 0 is the weight of the generator. We will make it 0 for simplicity, so it is loaded first every time, after the vanilla generator.

Once you have gotten it registered, go ahead and run the game and CREATE A NEW WORLD EVERY TIME YOU MAKE A CHANGE TO WORLD GENERATION!!!!!!



Crafting and Smelting Recipes

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!

In this tutorial we are going to be looking at how crafting and smelting works in forge. Let's start by creating a class called CraftingHandler in our "handlers" package. In here we will have a method called init (returns a void, static).  In this we will refer to GameRegistry.addRecipe. This method takes in two parameters: the crafted item, and the ingredients. Below is how we will be writing the line of code:


1
GameRegistry.addRecipe(new ItemStack(<youritem>, <amount>), "", "", "", '', <ingredient_1>, '', <ingredient_2>, '', <ingredient_3>);

Replace <youritem> with the item you want to output, let's make the pickaxe we made. So replace <youritem> with our pickaxe.

Next, replace <amount> with the amount that you want to output. Most output only 1, so in this case we are going to put 1, because, I mean, like, who needs to get multiple swords out of one recipe? Uh...nobody!

Now is the tricky part, the actual recipe. The 3 strings are going to go through a pattern recognition. Each of them represent a row on the crafting table, the first string being the top row, the second string being the middle row, and, you guessed it, the third string for the bottom row. Each of them MUST have 3 characters. If you want a blank space, you just put a space.

The third part of the method is telling the game what each character represents. You can have as many as you want, as long as it has at least one. It takes in a char, which is a character surrounded by single-quotes, followed by the ingredient you want, and so on and so forth.

Let's plug in the missing links, shall we?


1
GameRegistry.addRecipe(new ItemStack(ItemHandler.tutPickaxe, 1), "XXX", " C ", " C ", 'X', ItemHandler.tutItem, 'C', Items.STICK);

As you can see, I am only using the middle slots of the middle and bottom row, leaving the edges blank using a space. The end result is this:


Next we gotta put it in the postInit of our CommonProxy. Call the init within our postInit of CommonProxy and you should be good to test it. Make the other recipes for the rest of the tool set, too.

============================================Smelting==========================================

Smelting is very similar. Let's create a handler for it called SmeltingHandler. In here we will also create an init method. This init method will have our smelting recipes in it, obviously.

To add a smelting recipe, we need to call on addSmelting from the GameRegistry class. This takes in three arguments: input, output, and xp. The input takes in an Item or a Block. Let's add our item and make it smelt into another item, which we will then use for crafting.

Let's create the item in our ItemHandler and call it carbite. This will then initialize to a new ItemCarbite class, with the same parameters as our tutItem. Create the class, extend it to ModItem and create the constructor. Now to create the the JSON files. Just copy and paste our tutItem JSON files and change all the naming to carbite. Create the texture and model files and we should be good to go, and make sure you register and render it, too.

The following line of code is how we will create the smelting recipe:


1
GameRegistry.addSmelting(ItemHandler.tutItem, new ItemStack(ItemHandler.carbite), 1.0F);

We are passing through our tutItem as the input, and the newly created carbite item, as the output. The last parameter is how much experience you will get from it. 0.7F is iron, 1.0F is gold and diamond. We are giving this a lot of XP.

Next is to call it in our CommonProxy.postInit, and run the game. We should now have a smelting recipe.

Next we gotta change our crafting recipes to take in the carbite we made.

The end result should be this:


Don't forget to name your items!!

Tools

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!


Now we get into the more complicated stuff. Tools are beginner to intermediate in minecraft modding. Let's get started.

Firstly, create five new Items in your ItemHandler. Call them, tutPickaxe, tutSword, tutAxe, tutSpade, and tutHoe. We will initalize them like this:


1
2
3
4
5
tutPickaxe = new ItemTutPickaxe("tut_pickaxe", MaterialHandler.TUTORIAL, CreativeTabHandler.tabTools);
tutSword = new ItemTutSword("tut_sword", MaterialHandler.TUTORIAL, CreativeTabHandler.tabCombat);
tutSpade = new ItemTutSpade("tut_spade", MaterialHandler.TUTORIAL, CreativeTabHandler.tabTools);
tutHoe = new ItemTutHoe("tut_hoe", MaterialHandler.TUTORIAL, CreativeTabHandler.tabTools);
tutAxe = new ItemTutAxe("tut_axe", MaterialHandler.TUTORIAL, CreativeTabHandler.tabTools);

Create the classes necessary for fixing these errors, but make their super classes ItemPickaxe, ItemSword, ItemSpade, ItemHoe, ItemAxe, respectively. Add the constructors and add the first parameter for the constructors String name, and the last parameter takes in a creative tab instance. We need to add the registry names for each of these so let's set them in the constructors:


1
2
setUnlocalizedName(name);
setRegistryName(name);
setCreativeTab(tab);

Put these two lines of code in each of the constructors. Next, we must create the MaterialHandler class that we will use to handle all of our tool and armor materials. We will create, in there, a static ToolMaterial called TUTORIAL. We will initalize it using the following code:


1
public static ToolMaterial TUTORIAL = EnumHelper.addToolMaterial("tutorial", 3, 2500, 5F, 5F, 20);

EnumHelper is how we add constants to the list of tool materials. We give it an unlocalizedName, harvest level, durability, damage float, efficiency float, and an enchantability.

The harvest level is the level in which our tools harvest at, diamond being 3.

The durability is how many uses this tool material has. It is how many times you can click with it before it breaks.

The efficiency is how fast the tool mines blocks. Diamond is 8F.

The damage float is how many hearts of damage it does to entities. Diamond is 3F,

The enchantability is how well it is enchanted. Gold is 20, and that is very high.

Next we have to register the items and render them. So let's create the item models necessary for them. Copy from diamond tools in Referenced Libraries > forgeSrc > assets > minecraft > models > item.

Create the five files, named after your registry name, and paste in the JSON code form each of their respective diamond cousins' files.

Also, make some textures. Rename "items/diamond_<tool>" to "tut:items/tut_<tool>".

Don't forget to go to our creative tabs handler and set the tab icons for each of the tabs.then set each of the tools to their respective tabs.

With some recent updates, we have to make a change to our ItemTutAxe class. In the super() call, we need to set an efficiency and damage floats. We can achieve this by calling on our material's efficiency and damage floats.


1
super(material, material.getDamageVsEntity(), material.getEfficiencyOnProperMaterial());

This allows us to pass through our material's damage and efficiency without having to hard code it in.

Let's run the game and test out our newly created tool set!




Looks like we gotta add some names. Let's go into our "en_US.lang" file and add them.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
tile.tut_block.name=Tutorial Ore
item.tut_item.name=Tutorial Item
item.tut_sword.name=Tutorial Sword
item.tut_pickaxe.name=Tutorial Pickaxe
item.tut_axe.name=Tutorial Axe
item.tut_hoe.name=Tutorial Hoe
item.tut_spade.name=Tutorial Shovel
itemGroup.tab_blocks=Mod Blocks
itemGroup.tab_items=Mod Items
itemGroup.tab_tools=Mod Tools
itemGroup.tab_combat=Mod Combat

Now if we run the game, they should be fully functioning and named. Now if only we could craft them! *hint himt*

Creative Tabs and en_US.lang

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!


In this tutorial, we will be looking at putting all of our items and blocks into their own creative tabs. Creative tabs do not have a separate registries, it's just using it in your mod that makes it appear. CreativeTabs is an abstract class, and for a good reason, too. If you don't know what an abstract class is, it is basically a class that cannot be instantiated. This way, you actually set the properties by calling the methods within the initialization. You'll see what I mean in a moment.

Let's start off by creating a class in our handlers package, called CreativeTabHandler. This is where we are going to put all of our Creative Tabs. We need a static field of the type CreativeTabs with a name in the form of tab<yourtabname>. Of course, you can always name this whatever, but it's good practice to give a convention to your fields. The first creative tab we will make will store all of our blocks. We will call this tabBlocks.

This will initiate to a new CreativeTabs with a given name, set as a parameter, but instead of ending it off, we need to treat it like a method, and add the unimplemented method, being getTabIconItem.

1
2
3
4
5
6
 public static CreativeTabs tabBlocks = new CreativeTabs("tut_blocks"){

  public ItemStack getTabIconItem() {
   return null;
  }
 };

getTabIconItem is how we set the tab icon and what block or item it should display. We give it the name "tut_blocks". We need to give this tab a tab icon. We will make it our block, created in the blocks tutorial.

1
return new ItemStack(Item.getItemFromBlock(BlockHandler.tutBlock));

It returns a new ItemStack, I don't know why but I am guessing because it is handled easier than just an item, but I personally see no reason to return an ItemStack. We need to convert our block to an item, so we get the ItemBlock from our block.

Next is actually using it, so go on over to your BlockHandler class and change the creative tab argument to our newly created tab.


1
tutBlock = new BlockTutBlock(Material.ROCK, "tut_block", CreativeTabHandler.tabBlocks, 5F, 15F, 3, "pickaxe");

This will allow us to place our block in the creative tab we created. If we run the game, it should be there for us, as shown below.


===========================================Bonus=============================================

Let's make a couple more, shall we? Make three more tabs, one for items, one for tools, and one for weapons. Make the item tab have the tab icon of our tut item. For now, just leave the tab icons for the last two null, and don't use them until the tools tutorial.

We need to give everything names, like, proper names, that are readable. So we shall go into our resources folder and create a package called "assets.tut.lang". This is where we will put a file rightly called "en_US.lang". Make this file and in it we will name all of our components.

The convention of a .lang file is this:

Blocks: tile.<unlocalizedName>.name=Your Block Name
Items: item.<unlocalizedName>.name=Your Item Name
Creative Tabs: itemGroup.<unlocalizedName>=Your Tab Name

Here is what mine looks like:


1
2
3
tile.tut_block.name=Tutorial Ore
item.tut_item.name=Tutorial Item
itemGroup.tut_blocks=Mod Blocks

Run the game and you should be good to go!

Blocks

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!

In this tutorial we will be looking at setting up a block for ourselves. We will be creating an ore for our tutItem. Let's start by creating a new class in our handlers package, called BlockHandler. In this we will have all the same methods as our ItemHandler:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 public static void init(){
 }
 
 public static void register(){
 }
 
 public static void registerRenders(){
 }
 
 public static void registerRender(){
 }

In our registerRender() method, we need to add the parameter Block block. This will allow us to create an item from our block and then render it in our inventory as an item.

1
2
 public static void registerRender(Block block){
 }

Within this method we will add two lines of code:


1
2
Item item = Item.getItemFromBlock(block);
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));

This is gonna create an item from our block then render the block in the inventory. It works exactly like the item registerRender() method.

Next we will want to create a block and an item block. So go ahead and add those two fields.


1
2
public static Block tutBlock;
public static ItemBlock ibTutBlock;

We need to create an ItemBlock so that we can convert the block from a block to an item for rendering in the inventory. In our init() method, we will initialize our block and itemblock.


1
2
3
tutBlock = new BlockTutBlock(Material.ROCK, "tut_block", CreativeTabs.BUILDING_BLOCKS, 5F, 15F, 3, "pickaxe");
  
ibTutBlock = (ItemBlock) new ItemBlock(tutBlock);

Let me break down what kind of set up we are doing here for the block initialization.

==========================================Explanation==========================================

Material.ROCK is our block material. Block Materials are very unique cause they determine how they are mined and what effects they have in the world. For example: PORTAL is a block material that has no collision and when collided, it transports the player to another dimension. CACTUS hurts the player, etc.

"tut_block" is our name, being the registry name, and the unlocalized name.

MAKE SURE YOU DO NOT CAMELCASE!!!!!!

CreativeTabs.BUILDING_BLOCKS is what creative tab our block will be found in. You can choose a variety of different creative tabs. Eventually we will create our own ;) *hint hint*

5F is the hardness. Diamond Ore is around this floating point, so our block is very hard.

15F is the resistance to explosions. 15F is a very resistant block. The higher the number, the more resistant. You can play around with this float until it meets your likings.

3 is the harvest level that is needed minimum to be mined. 3 is diamond tier, 2 is iron, 1 is gold and stone, and 0 is wood.

"pickaxe" is the type of tool needed to mine this block. You can choose from "axe" to "shovel" but we are choosing "pickaxe" for obvious reasons.

Our ItemBlock init takes in a block, which is our newly created block. This will create an ItemBlock from it, as you can tell. We have to cast it to an ItemBlock so that we can register it as an item block later on.

=============================================================================================

Next step is to create a class for our Block, just as we called it in our code, BlockTutBlock. Put it in a new package called "com.<yourname>.tut.blocks". We will extend it to a new class called ModBlock. In this, we will create two different constructors, one with a harvest level, and one without.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
 public ModBlock(Material mat, String name, CreativeTabs tab, float hardness, float resistance, int harvest, String tool) {
  super(mat);
  setUnlocalizedName(name);
  setRegistryName(name);
  setCreativeTab(tab);
  setHardness(hardness);
  setResistance(resistance);
  setHarvestLevel(tool, harvest);
 }
 
 public ModBlock(Material mat, String name, CreativeTabs tab, float hardness, float resistance) {
  super(mat);
  setUnlocalizedName(name);
  setRegistryName(name);
  setCreativeTab(tab);
  setHardness(hardness);
  setResistance(resistance);
 }

These set the basics for our block and more depending on the constructor you're using.

Back into our BlockTutBlock class, we will add the constructor needed to complete our initialization.


1
2
3
 public BlockTutBlock(Material mat, String name, CreativeTabs tab, float hardness, float resistance, int harvest, String tool) {
  super(mat, name, tab, hardness, resistance, harvest, tool);
 }

This will set the material, name, tab, hardness, resistance, harvest level, and harvest tool, of our block automatically. It looks much cleaner than manually adding them in every class.

Next is registering and rendering the block. We need to register the block and item block at the same time. We need to register the item block with the same registry name as the block so that they are registered as the same thing, otherwise it won't work. We are using "item.getRegistryName()" in our registerRender, which is set by registering the item block with the same registry name as our block.


1
2
3
4
5
6
7
8
 public static void register(){
  GameRegistry.register(tutBlock);
  GameRegistry.register(ibTutBlock, tutBlock.getRegistryName());
 }
 
 public static void registerRenders(){
  registerRender(tutBlock);
 }

The second parameter of the register method is the name set for that object.

We are ready to get into models, blockstates, and texturing. In our "assets.tut" package, we need to create a package called "blockstates". We need to go find the blockstates file for "diamond_ore.json", in Referenced Libraries > forgeSrc > assets > minecraft > blockstates. Look for "diamond_ore.json" and copy the code within it. We will create an Untitled Text File for our new blockstates JSON file. Name it after your block's registry name, in this case it is "tut_block". Rename the model reference to "tut:tut_block".

1
2
3
4
5
{
    "variants": {
        "normal": { "model": "tut:tut_block" }
    }
}

Blockstates is the state of the block model. Some blocks use a blockstates JSON file that specifies what model to use depending on which way it is facing. For example: furnaces use a blockstate that states that depending on which way the player is facing, it will rotate the model so that a specific side is facing towards the player.

Next we need to create the block model in our "assets.tut.models.block". This is where we will specify what the block looks like and what texture to use. We will steal from "assets.minecraft.models.block.diamond_ore.json". Change the texture name to your texture location.

1
2
3
4
5
6
{
    "parent": "block/cube_all",
    "textures": {
        "all": "tut:blocks/tut_block"
    }
}

This is using the parent of "block/cube_all" which is a generic block model. "'textures':{" points towards the texture that will be rendered. When we get into multi-textured blocks, we will discuss this more but just know that "all" specifies ALL the sides of the block.

Next is the item block model. Let's steal from "assets.minecraft.models.item.diamond_ore.json" as well.


1
2
3
{
    "parent": "tut:block/tut_block"
}

This model specifies that we want to render the model just like the block model, but in our inventory.

Now create your texture and place it in "assets.tut.textures.blocks". We need to call the init, registry, and registerRenders methods in our proxies.

ClientProxy:


1
2
3
4
 public void init() {
  ItemHandler.registerRenders();
  BlockHandler.registerRenders();
 }

CommonProxy:

1
2
3
4
5
6
7
 public void preInit() {
  ItemHandler.init();
  ItemHandler.register();
  
  BlockHandler.init();
  BlockHandler.register();
 }

Now we can run the game and test out our newly created block.


=======================================Block Properties=================================


Dropping an Item:
To drop an item from the block we will need to go into our block class and override a method from the Block class called "getItemDropped()".

TIP: You can use CTRL+SPACE to view a list of methods to override from the superclass!!!

We need to return an item. So in our method we need to return ItemHandler.tut_item.

1
2
3
 public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  return ItemHandler.tutItem;
 }

This will make the block drop our item that we created earlier.

Quantity Dropped
We will need to override a method that will allow us to specify a specific amount of items dropped. This method is called quantityDropped(). It is of the type int, so it will need to return an integer. Return whatever number you wanna return. I am gonna be doing a random number between 1 and 5, so here is my code:

1
2
3
 public int quantityDropped(IBlockState state, int fortune, Random random) {
  return random.nextInt(5) + 1;
 }

"return random.nextInt(5)" generates a random number between 0 and 4, So we must add "+ 1" to our code so that it generates  number between 1 and 5.



Multiple Items Dropped
If you want to have your block drop multiple items, you must create a variable to hold the random number. We will call it "chance". We will make it be a random number between 0 and 1. We will also check if the number is a certain number and make it return the item we want it to drop.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  int chance = rand.nextInt(2);
  if(chance == 0){
   return ItemHandler.tutItem;
  }
  if(chance == 1){
   return Items.DIAMOND;
  }
  
  return ItemHandler.tutItem;
 }

The end result is this: