[CREATING MODS] Block Manipulation
4 posters
Page 1 of 1
[CREATING MODS] Block Manipulation
Adding properties to your block
There are 2 ways to add properties to your block, one is by adding to the final of the variable;
Example of indirect property:
the second way to add variables is to add to the codes directly at the block's file.
Example of direct property:
I prefer the second way, because its dynamic and easy to use. Notch and a lot of others modders use the indirect way, which make smaller files with the same result. If you knew java already or already modded a lot, you can put your properties easily together so you can access every quickly.
Example of usage to our block:
Now, if your a new modder, you probably wondering a few stuff about properties probably because you dont know which properties to use, but most importantly, what the hell they means?
Block Properties List
[This may not apply to java, this is a simplified way to refer to procedures and functions)
Properties change how blocks looks like or works. This is a row of procedures (functions with no resulting variable) you can use in your block (or in the declaration) to make some basic changes.
setHardness
setHardness(float f);
example: setHardness(1F);, setHardness(0.5F);, setHardness(-1F);
Hardness is a float value which let you configurate the time it takes to "mine" or "destroy" your block.
If you want specify the time in seconds, you should do:
setHardness( (float) ( number * 1.5 ) )
number = the seconds it takes to destroy the block
If you dont understand why there's (float) in the code, read this spoiler:
In java, we need to specify what kind of number we are using.
When we dealing with float or double values, they have to be specific or else java would confuse both (because they're pretty similar variable kinds).
Correct usage would be:
float me1 = 2.4;
me1 = 1.35F;
me1 = me1+3F;
etc
double me2 = 3;
me2 = 1.35D;
me2 = me2+3F;
etc
The F and D means Float and Double, you can also put it in the start of the number.
float me1 = 2.4;
me1 = (float) 1.35;
This can be used to translate variables. (turn doubles into float and floats into double)
float me1 = 1.3;
double final = (double) me1;
If you don't specify, you'll probably be unable to compile it (In minecraft case, recompile).
Example: if your hardness is 2, it will takes 3 seconds to gather the block
if your hardness is 10 (obsidian reference), it will takes 15 seconds to gather the block
Writing a value equal to -1F and your result will be an unbreakable block. (Example: bedrock)
Writing a value equal to 0F and your result will be an instant breaking block. (Example: "sapling")
setResistance
setResistance(float f);
example: setResistance(10F);, setResistance(2F);,setResistance(0F);
This resistance is Blast Resistance, change how explosion works with your block.
Minecraft Wiki - Blast Resistance Check for more info about explosion and block resistance.
setLightValue
setLightValue(float f);
example: setLightValue(1);, setLightValue(0.9375);, setLightValue(0);
Values highter than 1 will crash minecraft.
This light value is used for blocks that emit light. They'r between 0 and 1 as a float value and then are multiplied by 15 later, this multiplied value is used at minecraft wiki - Wiki Note: data values are the 0 to 1 values, Light level are 0 to 15 values.
setLightOpacity
setLightOpacity(int i);
example: setLightOpacity(0);, setLightOpacity(3);, setLightOpacity(1);
Blocks stops 100% of light in minecraft, this means the light cant move through non-opaque blocks.
if LightOpacity of a block is higher than 0, light will be able to moves through it and being visible in the other sides, like glass. HIGLY IMPORTANT: THATS AN INTEGER VALUE! (non-fractional value)
If that doesnt explain enough, here is: Minecraft Wiki - Non-Opaque Blocks
setStepSound
setStepSound(StepSound stepsound);
Pretty self-explanatory. This is minecraft function for making sounds when a player moves over the block OR attempt to destroy it.
Here's a full list of what you can use: *There is a way to extend this list by modding and creating others songs.*
example: setTickOnLoad(true);, setTickOnLoad(false);
This is for making a block ticks, it mean it will randomly runs the function updateTick() (if specified in the block class), we are going to learn more about it later.
Examples:
This is used on Grass block, so grass can turn nearby dirt into grass or become dirt.
This is used on SAPLINGS, so it can slowly generate trees.
This is used on LEAVES, so it can check if theres any log near and if not, destroy itself.
This is used on REDSTONE TORCHES, so switches, burns and update to fix errors (which are the key for random-redstone-devices).
setBlockBounds
setBlockBounds(float f, float f1, float f2, float f3, float f4, float f5)
This function sets the block size, it needs 2 3D points (x,y,z).
Block size affects how it will interacts with player (Physics) and how it going to look (Render), simplifying, With this function you can make your block graphically and physically different than others.
Using this function you can only make box/rectangles shapes.
Its important to remmember:
Use Restrictions:
- > Prefer to use when your material isn't "ground","rock" or "wood" to prevent suffocating glitches (you can suffocate yourself by touching the block). I suggest material "glass", its dynamic and have no restrictions.
This function modify rendering of a block.
You need to add this to your block: (between the first "{" and the last "}")
This will make your block act like glass. If you ever used a texture that made a block like dirt/stone/sand transparent and saw all the dungeons and stuff, that is what happens if your block isn't opaque and you make it renders differently.
Simplistically, It makes others blocks around it appears.
BTW, if you still have no idea how to add this piece of code to your block, scroll down to "Adding Functions to our block"
Examples of uses:
disableNeighborNotifyOnMetadataChange
disableNeighborNotifyOnMetadataChange();
This function dont need parameters, its used for blocks that changes the damage value (Meta Data) too frequently and these changes dont need to be interpreted as new blocks being placed. Most of blocks like redstone circuits needs to change the meta data constantly and all other blocks around would check itselfs condition of placements (example: When cactus checks itselfs, it drops if theres blocks in its sides)
Adding new functions to your block
Now we learned "procedures", function that we call (we tell them to happens), now we're missing real "functions", with that i mean functions we dont control when they come, its when someone rightclick the block, when its destroyed by explosion or any kind of information requeriment of our block. Before we get an insane list, we have to learn how to put these functions to our block.
Lets say this is our block:
package net.minecraft.src;
import java.util.Random;
public class BlockDifferent extends Block
{
public BlockDifferent(int i, int j, Material material)
{
super(i, j, material);
}
}
Now lets add a funcion called "public ThisIsMine(int value)":
package net.minecraft.src;
import java.util.Random;
public class BlockDifferent extends Block
{
public BlockDifferent(int i, int j, Material material)
{
super(i, j, material);
}
public ThisIsMine(int value)
{
//Codes goes here
}
}
We add the 'name' of the function with its parameters (int value) and permissions (public) values and open with the "{" (I dont know whats the name of that), and end with "}" in another line.
Now for the list of functions =D
renderAsNormalBlock
public boolean renderAsNormalBlock()
This functions asks the block class if its going to be rendered like a normal block, as the name suggests.. This value have to be set to false if your block use "getRenderType" or "SetBlockBounds" functions that modify the way the block is rendered.
Example of use:
public boolean renderAsNormalBlock()
{
return false;
}
Default: true (Boolean)
(If you don't put this function in your block, it will be the default.)
getRenderType
public int getRenderType()
Another info-function. This gives you the ability of making different kind of rendering types for your block.
Dont forget this makes blocks renders differently, you need to add these functions to prevent glitches:
public boolean renderAsNormalBlock()
{
return false;
}
public boolean isOpaqueCube()
{
return false;
}
Example of use:
{
return 3;
}
Default: 0 (Integer)
~ Using numbers that doesnt exists or arent on this image list may crash minecraft.
List of effects to your block USING 1.7.3:
There are 2 ways to add properties to your block, one is by adding to the final of the variable;
Example of indirect property:
- Code:
(new BlockMyBlock(189, 49, Material.glass)).setHardness(0.5F).setStepSound(soundGlassFootstep).setBlockName("CustomBlock");
the second way to add variables is to add to the codes directly at the block's file.
Example of direct property:
- Code:
package net.minecraft.src;
import java.util.Random;
public class BlockMyBlock extends Block
{
public BlockMyBlock(int i, int j, Material material)
{
super(189, 49, Material.glass);
setHardness(0.5F);
setStepSound(soundGlassFootstep);
setBlockName("CustomBlock");
}
}
I prefer the second way, because its dynamic and easy to use. Notch and a lot of others modders use the indirect way, which make smaller files with the same result. If you knew java already or already modded a lot, you can put your properties easily together so you can access every quickly.
Example of usage to our block:
- Code:
package net.minecraft.src;
import java.util.Random;
public class BlockDifferent extends Block
{
public BlockDifferent(int i, int j, Material material)
{
super(i, j, material);
setHardness(0.1F);
setResistance(5F);
}
}
Now, if your a new modder, you probably wondering a few stuff about properties probably because you dont know which properties to use, but most importantly, what the hell they means?
Block Properties List
[This may not apply to java, this is a simplified way to refer to procedures and functions)
Properties change how blocks looks like or works. This is a row of procedures (functions with no resulting variable) you can use in your block (or in the declaration) to make some basic changes.
setHardness
setHardness(float f);
example: setHardness(1F);, setHardness(0.5F);, setHardness(-1F);
Hardness is a float value which let you configurate the time it takes to "mine" or "destroy" your block.
If you want specify the time in seconds, you should do:
setHardness( (float) ( number * 1.5 ) )
number = the seconds it takes to destroy the block
If you dont understand why there's (float) in the code, read this spoiler:
In java, we need to specify what kind of number we are using.
When we dealing with float or double values, they have to be specific or else java would confuse both (because they're pretty similar variable kinds).
Correct usage would be:
float me1 = 2.4;
me1 = 1.35F;
me1 = me1+3F;
etc
double me2 = 3;
me2 = 1.35D;
me2 = me2+3F;
etc
The F and D means Float and Double, you can also put it in the start of the number.
float me1 = 2.4;
me1 = (float) 1.35;
This can be used to translate variables. (turn doubles into float and floats into double)
float me1 = 1.3;
double final = (double) me1;
If you don't specify, you'll probably be unable to compile it (In minecraft case, recompile).
Example: if your hardness is 2, it will takes 3 seconds to gather the block
if your hardness is 10 (obsidian reference), it will takes 15 seconds to gather the block
Writing a value equal to -1F and your result will be an unbreakable block. (Example: bedrock)
Writing a value equal to 0F and your result will be an instant breaking block. (Example: "sapling")
setResistance
setResistance(float f);
example: setResistance(10F);, setResistance(2F);,setResistance(0F);
This resistance is Blast Resistance, change how explosion works with your block.
Minecraft Wiki - Blast Resistance Check for more info about explosion and block resistance.
setLightValue
setLightValue(float f);
example: setLightValue(1);, setLightValue(0.9375);, setLightValue(0);
Values highter than 1 will crash minecraft.
This light value is used for blocks that emit light. They'r between 0 and 1 as a float value and then are multiplied by 15 later, this multiplied value is used at minecraft wiki - Wiki Note: data values are the 0 to 1 values, Light level are 0 to 15 values.
setLightOpacity
setLightOpacity(int i);
example: setLightOpacity(0);, setLightOpacity(3);, setLightOpacity(1);
Blocks stops 100% of light in minecraft, this means the light cant move through non-opaque blocks.
if LightOpacity of a block is higher than 0, light will be able to moves through it and being visible in the other sides, like glass. HIGLY IMPORTANT: THATS AN INTEGER VALUE! (non-fractional value)
If that doesnt explain enough, here is: Minecraft Wiki - Non-Opaque Blocks
setStepSound
setStepSound(StepSound stepsound);
Pretty self-explanatory. This is minecraft function for making sounds when a player moves over the block OR attempt to destroy it.
Here's a full list of what you can use: *There is a way to extend this list by modding and creating others songs.*
- Code:
setStepSound(soundPowderFootstep);
setStepSound(soundWoodFootstep);
setStepSound(soundGravelFootstep);
setStepSound(soundGrassFootstep);
setStepSound(soundStoneFootstep);
setStepSound(soundMetalFootstep);
setStepSound(soundGlassFootstep);
setStepSound(soundClothFootstep);
setStepSound(soundSandFootstep);
setTickOnLoad
setTickOnLoad(boolean flag);
example: setTickOnLoad(true);, setTickOnLoad(false);
This is for making a block ticks, it mean it will randomly runs the function updateTick() (if specified in the block class), we are going to learn more about it later.
Examples:
This is used on Grass block, so grass can turn nearby dirt into grass or become dirt.
This is used on SAPLINGS, so it can slowly generate trees.
This is used on LEAVES, so it can check if theres any log near and if not, destroy itself.
This is used on REDSTONE TORCHES, so switches, burns and update to fix errors (which are the key for random-redstone-devices).
setBlockBounds
setBlockBounds(float f, float f1, float f2, float f3, float f4, float f5)
This function sets the block size, it needs 2 3D points (x,y,z).
Block size affects how it will interacts with player (Physics) and how it going to look (Render), simplifying, With this function you can make your block graphically and physically different than others.
Using this function you can only make box/rectangles shapes.
Its important to remmember:
Use Restrictions:
- > Prefer to use when your material isn't "ground","rock" or "wood" to prevent suffocating glitches (you can suffocate yourself by touching the block). I suggest material "glass", its dynamic and have no restrictions.
This function modify rendering of a block.
You need to add this to your block: (between the first "{" and the last "}")
- Code:
public boolean isOpaqueCube()
{
return false;
}
This will make your block act like glass. If you ever used a texture that made a block like dirt/stone/sand transparent and saw all the dungeons and stuff, that is what happens if your block isn't opaque and you make it renders differently.
Simplistically, It makes others blocks around it appears.
BTW, if you still have no idea how to add this piece of code to your block, scroll down to "Adding Functions to our block"
Examples of uses:
- Code:
public BlockDifferent(int i, int j, Material material)
{
super(i, j, material);
setBlockBounds(0.25F, 0.25F, 0.25F, 0.75F, 0.75F, 0.75F);
}
disableNeighborNotifyOnMetadataChange
disableNeighborNotifyOnMetadataChange();
This function dont need parameters, its used for blocks that changes the damage value (Meta Data) too frequently and these changes dont need to be interpreted as new blocks being placed. Most of blocks like redstone circuits needs to change the meta data constantly and all other blocks around would check itselfs condition of placements (example: When cactus checks itselfs, it drops if theres blocks in its sides)
Adding new functions to your block
Now we learned "procedures", function that we call (we tell them to happens), now we're missing real "functions", with that i mean functions we dont control when they come, its when someone rightclick the block, when its destroyed by explosion or any kind of information requeriment of our block. Before we get an insane list, we have to learn how to put these functions to our block.
Lets say this is our block:
package net.minecraft.src;
import java.util.Random;
public class BlockDifferent extends Block
{
public BlockDifferent(int i, int j, Material material)
{
super(i, j, material);
}
}
Now lets add a funcion called "public ThisIsMine(int value)":
package net.minecraft.src;
import java.util.Random;
public class BlockDifferent extends Block
{
public BlockDifferent(int i, int j, Material material)
{
super(i, j, material);
}
public ThisIsMine(int value)
{
//Codes goes here
}
}
We add the 'name' of the function with its parameters (int value) and permissions (public) values and open with the "{" (I dont know whats the name of that), and end with "}" in another line.
Now for the list of functions =D
renderAsNormalBlock
public boolean renderAsNormalBlock()
This functions asks the block class if its going to be rendered like a normal block, as the name suggests.. This value have to be set to false if your block use "getRenderType" or "SetBlockBounds" functions that modify the way the block is rendered.
Example of use:
public boolean renderAsNormalBlock()
{
return false;
}
Default: true (Boolean)
(If you don't put this function in your block, it will be the default.)
getRenderType
public int getRenderType()
Another info-function. This gives you the ability of making different kind of rendering types for your block.
Dont forget this makes blocks renders differently, you need to add these functions to prevent glitches:
public boolean renderAsNormalBlock()
{
return false;
}
public boolean isOpaqueCube()
{
return false;
}
Example of use:
{
return 3;
}
Default: 0 (Integer)
~ Using numbers that doesnt exists or arent on this image list may crash minecraft.
List of effects to your block USING 1.7.3:
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [CREATING MODS] Block Manipulation
Wow! Thanks for contributing to the forum! Don't forget to use code tags.
Re: [CREATING MODS] Block Manipulation
Also a little text formating goes a long way!!!
I seem to remeber seeing this exact tut somewhere. where was it?
I seem to remeber seeing this exact tut somewhere. where was it?
Re: [CREATING MODS] Block Manipulation
the undecided t wrote:Also a little text formating goes a long way!!!
I seem to remeber seeing this exact tut somewhere. where was it?
it was on the mc forums
i just like it and som1 asked for it so i posted it on here!
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [CREATING MODS] Block Manipulation
a little text formating would go a long way aas in dividing the different modifiers into sections or something like that.
Re: [CREATING MODS] Block Manipulation
@austin56101, Please try to use your own tutorials. If not, then give clear credit to the name of the person and a link.
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [CREATING MODS] Block Manipulation
i just thought that this forum is awesome and i wanted to contribute
will u be adding a video section?
will u be adding a video section?
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [CREATING MODS] Block Manipulation
ok since i started a new channel
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [CREATING MODS] Block Manipulation
Ok, I'll add video tutorials sections in the modding categories.
Re: [CREATING MODS] Block Manipulation
Can you add actions to items?
mixinghoney- Member
- Posts : 1
Join date : 2011-10-25
Re: [CREATING MODS] Block Manipulation
Yea this just gives the shapes to them
Check out his tut on adv blocks
Check out his tut on adv blocks
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Similar topics
» creating a new type of tool
» (UNANSWERED)How to use other mods codes
» (UNANSWERED)How to use other mods codes
» [1.8.1 Mod Making] Creating a new torch!
» Creating your first java program!
» (UNANSWERED)How to use other mods codes
» (UNANSWERED)How to use other mods codes
» [1.8.1 Mod Making] Creating a new torch!
» Creating your first java program!
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum