The Meaning of Life, the Universe, and Everything.
Join Date:
8/16/2011
Posts:
50
Minecraft:
dev909
Member Details
For the longest time, this was very hard for me. After looking around for awhile, I could not find a single tutorial on how to make a sizable custom block, and texture it on multiple sides. Now there may actually be help and tutorials about this subject somewhere else, but I found it hard to find them. Anyway enough jabber.
NOTE: Now I'm going to assume that you already know how to make a block, item, etc. This is not a standard block tutorial, so if you got questions on how to make a basic block, then wrong thread. I also assume that you know how to make your own custom texture file, register it, and know how to use it too.
Start off by opening YOUR_BLOCK.class
You're gonna have to add 4 methods to it:
public void setBlockBoundsBasedOnState(IBlockAccess iblockaccess, int i, int j, int k) {
setBlockBounds(0.3F, 0.0F, 0.3F, 0.7F, 0.6F, 0.7F);
}
public AxisAlignedBB setCollisionBoundingBoxFromPool(World world, int i, int j, int k) {
return super.getCollisionBoundingBoxFromPool(world, i, j, k);
}
public boolean renderAsNormalBlock()
{
return false;
}
public boolean isOpaqueCube() {
return false;
}
The first method, setBlockBoundsBasedOnState, allows you to define what the blocks visual appearance and position is within said block. What I mean by that is the actual block. Think of torches. They only appear as one tall cube. If you look at it, you can see a transparent box surround it. This is its bounding box. The arguments are for your x, y, and z boundaries. The first three are your x, y, and z starting points, while the last three are your ending points. So lets have a look at my example.
(0.3F, 0.0F, 0.3F, 0.7F, 0.6F, 0.7F)
For my starting x, it starts the box at 0.3 of a normal sized cube. It then extends to the i2 arg, which in my case is 0.7. This means that I have created a line that is centered in the normal cube in the X axis. I will give an example picture at the end to hopefully better explain it. For the y axis, mine starts at 0, which is the ground, and extends to 0.7 of a block. The z axis follows suite.
The second method setCollisonBoundingBoxFromPool, sets your collision box. Notice how you can run through a torch? That's because it has either no, or very tiny collision box. This specific method (I'm 98% sure) takes your bounding box coordinates from the first method, and applies a collision box around it.
renderAsNormalblock should be set to false. This is because if it was set to true, you would not be able to render your custom block size. Your full texture would be used ( bad if you had a texture that did not fill the 16x16 pixels, as the game would render the blank spaces in your texture as transparent on the block), the collision box would be full, etc etc. That defeats the purpose of this tutorial.
Finally isOpaqueCube should be set to false. If set to true, and you had some blank spaces in your texture, then the game would set that part of the texture to transparent, and any other blocks that you would normally see through the transparent parts of your block, would not render and would create a x-ray type of vision through your block. So if you have a custom shaped block, its best to turn this to false.
If you got this far without falling asleep, QQing or rage quitting, then good news is that only textures is left!! This part I had to do some messing around but then became pretty simple once I understood it. You should add one more part to YOUR_BLOCK.class:
@Override
public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
if (side<=1){
return 80;
}
return 64 + metadata;
}
This method allows you to set a different texture for each side, as well as using metadata to select different textures ( such as wood or wool). Remove 'AndMetadata' along with its arg if you do not want to use metadata values. The method still works the same though. Each block in minecraft has a different 'side value'. Bottom is 0, top is 1, and the rest of the sides are 2-5 (I don't know each one individually, so sorry in advance). The int side variable simply gives you the side of the block. So in my example above, if side is equal or less than 1 (so both top and bottom) then set the texture index to 80. The rest of the sides return 64 for my index + metadata. Using multiple if statements would allow you to set a unique texture to each side.
And that's it!! Here's what all the above code made for me:
Notice the different texture between the sides and the top. Also you can see the normal block size bounding box on the ground.
I hope this will help some people out, I wish I could have found something like this before haha. I also wanna thank ZeuX for his help.
NOTE: Now I'm going to assume that you already know how to make a block, item, etc. This is not a standard block tutorial, so if you got questions on how to make a basic block, then wrong thread. I also assume that you know how to make your own custom texture file, register it, and know how to use it too.
Start off by opening YOUR_BLOCK.class
You're gonna have to add 4 methods to it:
The first method, setBlockBoundsBasedOnState, allows you to define what the blocks visual appearance and position is within said block. What I mean by that is the actual block. Think of torches. They only appear as one tall cube. If you look at it, you can see a transparent box surround it. This is its bounding box. The arguments are for your x, y, and z boundaries. The first three are your x, y, and z starting points, while the last three are your ending points. So lets have a look at my example.
(0.3F, 0.0F, 0.3F, 0.7F, 0.6F, 0.7F)
For my starting x, it starts the box at 0.3 of a normal sized cube. It then extends to the i2 arg, which in my case is 0.7. This means that I have created a line that is centered in the normal cube in the X axis. I will give an example picture at the end to hopefully better explain it. For the y axis, mine starts at 0, which is the ground, and extends to 0.7 of a block. The z axis follows suite.
The second method setCollisonBoundingBoxFromPool, sets your collision box. Notice how you can run through a torch? That's because it has either no, or very tiny collision box. This specific method (I'm 98% sure) takes your bounding box coordinates from the first method, and applies a collision box around it.
renderAsNormalblock should be set to false. This is because if it was set to true, you would not be able to render your custom block size. Your full texture would be used ( bad if you had a texture that did not fill the 16x16 pixels, as the game would render the blank spaces in your texture as transparent on the block), the collision box would be full, etc etc. That defeats the purpose of this tutorial.
Finally isOpaqueCube should be set to false. If set to true, and you had some blank spaces in your texture, then the game would set that part of the texture to transparent, and any other blocks that you would normally see through the transparent parts of your block, would not render and would create a x-ray type of vision through your block. So if you have a custom shaped block, its best to turn this to false.
If you got this far without falling asleep, QQing or rage quitting, then good news is that only textures is left!! This part I had to do some messing around but then became pretty simple once I understood it. You should add one more part to YOUR_BLOCK.class:
This method allows you to set a different texture for each side, as well as using metadata to select different textures ( such as wood or wool). Remove 'AndMetadata' along with its arg if you do not want to use metadata values. The method still works the same though. Each block in minecraft has a different 'side value'. Bottom is 0, top is 1, and the rest of the sides are 2-5 (I don't know each one individually, so sorry in advance). The int side variable simply gives you the side of the block. So in my example above, if side is equal or less than 1 (so both top and bottom) then set the texture index to 80. The rest of the sides return 64 for my index + metadata. Using multiple if statements would allow you to set a unique texture to each side.
And that's it!! Here's what all the above code made for me:
Notice the different texture between the sides and the top. Also you can see the normal block size bounding box on the ground.
I hope this will help some people out, I wish I could have found something like this before haha. I also wanna thank ZeuX for his help.