[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
+2
Jambokid
Ziddia
6 posters
Page 1 of 1
[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
This tutorial will teach you how to create a new ore, emerald, and add it to the game. This tutorial holds true with adding new blocks as well. First off, create a new file called mod_Emeralds.java and start it off with the standard
Now, for a ModLoader mod, it is essential that your mod extends BaseMod (or, for any basic ModLoader mod anyway). It is also incredibly important that you add the mod_ prefix to your class. As a note, you will notcie that it is not mod_EmeraldOre, but mod_Emeralds. This is because you can add emerald items, emerald ore, emerald block, emerald tools, emerald armor, emerald recipes, and everything to do with emeralds in this one class.
Next you want to add this bit:
All this does is set the name your classes will use (not the in game name so dont worry!), sets its TNT resistance, sets its hardness (difficulty to break), and its ID. That's all we need for this, heres what our code looks like now:
So now, we need to add it into the game. The game doesn't yet register it! You register all your ModLoader functions under this heading:
Register the block;
Create on Override for textures (if you wish);
and Add an InGameName for your ore.
To do this, we do the following:
All this does is make the game recognize the emeraldOre, overrides the /terrain.png directory for it's sprite, and replaces it with the emeraldore.png file in the tutorials folder, and adds its ingame name as Emerald Ore. So, after this, our class looks like this:
Now, to finish it off, we add:
To the end, to show what version of MC it is for. Our code now looks like this:
Now, save your mod_Emeralds.java file and create a new file called BlockEmeraldOre.java. Open BlockEmeraldOre for editing. This is what you want in BlockEmeraldOre:
mod_Emeralds calls on this once, so it is a necessary file. All this tells us is the material it is made of. If you save this and recompile, you should get no errors at all, except maybe java syntax errors. To obfuscate the code and make it into class files, go into /conf/ and add the lines mod_Emeralds and BlockEmeraldOre to client_obsfucation. Have fun with your new block!
Note: If you want it to return your emerald item, like an ore would, just change your BlockEmeraldOre.java to read like this:
This will fail because you have no emeraldItem - read on to learn how to make an item.
- Code:
package net.minecraft.src;
public class mod_Emeralds extends BaseMod {
Now, for a ModLoader mod, it is essential that your mod extends BaseMod (or, for any basic ModLoader mod anyway). It is also incredibly important that you add the mod_ prefix to your class. As a note, you will notcie that it is not mod_EmeraldOre, but mod_Emeralds. This is because you can add emerald items, emerald ore, emerald block, emerald tools, emerald armor, emerald recipes, and everything to do with emeralds in this one class.
Next you want to add this bit:
- Code:
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
All this does is set the name your classes will use (not the in game name so dont worry!), sets its TNT resistance, sets its hardness (difficulty to break), and its ID. That's all we need for this, heres what our code looks like now:
- Code:
package net.minecraft.src;
public class mod_Emeralds extends BaseMod
{
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
So now, we need to add it into the game. The game doesn't yet register it! You register all your ModLoader functions under this heading:
- Code:
public mod_Emeralds()
{
Register the block;
Create on Override for textures (if you wish);
and Add an InGameName for your ore.
To do this, we do the following:
- Code:
ModLoader.RegisterBlock(emeraldOre);
emeraldOre.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/tutorials/emeraldore.png");
ModLoader.AddName(emeraldOre, "Emerald Ore");
All this does is make the game recognize the emeraldOre, overrides the /terrain.png directory for it's sprite, and replaces it with the emeraldore.png file in the tutorials folder, and adds its ingame name as Emerald Ore. So, after this, our class looks like this:
- Code:
package net.minecraft.src;
public class mod_Emeralds extends BaseMod
{
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
public mod_Emeralds()
{
ModLoader.RegisterBlock(emeraldOre);
emeraldOre.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/tutorials/emeraldore.png");
ModLoader.AddName(emeraldOre, "Emerald Ore");
Now, to finish it off, we add:
- Code:
public String Version()
{
return "1.4_01";
}
}
To the end, to show what version of MC it is for. Our code now looks like this:
- Code:
package net.minecraft.src;
public class mod_Emeralds extends BaseMod
{
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
public mod_Emeralds()
{
ModLoader.RegisterBlock(emeraldOre);
emeraldOre.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/tutorials/emeraldore.png");
ModLoader.AddName(emeraldOre, "Emerald Ore");
public String Version()
{
return "1.4_01";
}
}
Now, save your mod_Emeralds.java file and create a new file called BlockEmeraldOre.java. Open BlockEmeraldOre for editing. This is what you want in BlockEmeraldOre:
- Code:
package net.minecraft.src;
public class BlockEmeraldOre extends Block
{
protected BlockEmeraldOre(int i, int j)
{
super(i, j, Material.iron);
}
}
mod_Emeralds calls on this once, so it is a necessary file. All this tells us is the material it is made of. If you save this and recompile, you should get no errors at all, except maybe java syntax errors. To obfuscate the code and make it into class files, go into /conf/ and add the lines mod_Emeralds and BlockEmeraldOre to client_obsfucation. Have fun with your new block!
Note: If you want it to return your emerald item, like an ore would, just change your BlockEmeraldOre.java to read like this:
- Code:
package net.minecraft.src;
import java.util.Random;
public class BlockEmeraldOre extends Block
{
protected BlockEmeraldOre(int i, int j)
{
super(i, j, Material.iron);
}
public int idDropped(int i, Random random)
{
return mod_Emeralds.emeraldItem.shiftedIndex;
}
}
This will fail because you have no emeraldItem - read on to learn how to make an item.
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
I get this error at the code where you can code what drops from a block.
Here are my files :
BlockLightDustOre.java
mod_LightDirt.java
This is the error :
Help would be appreciated
Here are my files :
BlockLightDustOre.java
- Code:
package net.minecraft.src;
import java.util.Random;
public class BlockLightDustOre extends Block
{
public BlockLightDustOre(int i, int j)
{
super(i, j, Material.iron);
}
public int idDropped(int i, Random random)
{
return mod_LightDirt.lightdust;
}
}
mod_LightDirt.java
- Code:
package net.minecraft.src;
public class mod_LightDirt extends BaseMod
{
public static final Block lightdirt = new BlockLightDirt(97, 0).setHardness(0.6F).setResistance(1.0F).setLightValue(1.0F).setStepSound(Block.soundGravelFootstep).setBlockName("lightdirt");
public static final Block lightdustore = new BlockLightDustOre(98, 0).setHardness(3.0F).setResistance(5.0F).setBlockName("lightdustore");
public static final Item lightdust = new Item(3000).setItemName("lightdust");
public mod_LightDirt()
{
ModLoader.RegisterBlock(lightdirt);
ModLoader.RegisterBlock(lightdustore);
lightdirt.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/lightdirt.png");
lightdustore.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/lightdustore.png");
lightdust.iconIndex = ModLoader.addOverride("/gui/items.png", "lightdust.png");
ModLoader.AddName(lightdirt, "Light Dirt");
ModLoader.AddName(lightdustore, "Light Dust Ore");
ModLoader.AddName(lightdust, "Light Dust");
ModLoader.AddRecipe(new ItemStack(lightdirt, 1), new Object[] {
"XXX", "XYX", Character.valueOf('X'), Block.dirt, Character.valueOf('Y'), lightdust
});
ModLoader.AddRecipe(new ItemStack(lightdust, 1), new Object[] {
"X", Character.valueOf('X'), lightdustore
});
}
public String Version()
{
return "1.5_01";
}
}
This is the error :
- Code:
*** Minecraft Coder Pack Version 2.12 ***
MCP 2.12 running in C:\Users\ColinJnr\Desktop\MCP
Compiling Minecraft
sources\minecraft\net\minecraft\src\BlockLightDustOre.java:14: incompatible type
s
found : net.minecraft.src.Block
required: int
return mod_LightDirt.lightdust;
^
1 error
Compiling Minecraft Server
Help would be appreciated
Last edited by Jambokid on Thu Apr 28, 2011 3:32 pm; edited 4 times in total
Jambokid- Recruit
- Posts : 7
Join date : 2011-04-28
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Your BlockLightDustOre.java still has everything named as mod_Emeralds and BlockEmeraldOre... that's probably part of the problem
Meglazero- Iron Miner
- Posts : 51
Join date : 2011-04-22
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Lol, sorry. I did have everything changed from Emerald, I've edited it, I don't know what was I doing when I posted it , It is still the same error
Jambokid- Recruit
- Posts : 7
Join date : 2011-04-28
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
The code Zid has in his tutorial for returning an item is:
Seems like you're missing the .shiftedIndex at the end of that line in your code... that may be the problem?
- Code:
return mod_Emeralds.emeraldItem.shiftedIndex;
Seems like you're missing the .shiftedIndex at the end of that line in your code... that may be the problem?
Meglazero- Iron Miner
- Posts : 51
Join date : 2011-04-22
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Sorry, I got it to work , very simple mistake. I was using mod_LightDirt.lightdustore which is already the block I'm trying to make a drop for. It is now mod_LightDirt.lightdust.shiftedIndex; Sorry
Last edited by Jambokid on Thu Apr 28, 2011 3:39 pm; edited 3 times in total
Jambokid- Recruit
- Posts : 7
Join date : 2011-04-28
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
lightdustore definitely does NOT need shiftedIndex if it is a block.
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
it should be .blockID
Methuselah96- ZidMC Coder
- Posts : 159
Join date : 2011-04-22
Age : 28
Location : Philadelphia, Pennsylvania, United States
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Please refrain from asking questions here by the way.
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Can someone help me im making ores from the tutorial and it shows me this error:
Can someone please can help me!!!
BTW i mod for minecraft 1.5_01
- Code:
*** Minecraft Coder Pack Version 2.12 ***
MCP 2.12 running in C:\MCP
Compiling Minecraft
sources\minecraft\net\minecraft\src\mod_Emeralds.java:13: illegal start of expre
ssion
public String Version()
^
sources\minecraft\net\minecraft\src\mod_Emeralds.java:13: ';' expected
public String Version()
^
sources\minecraft\net\minecraft\src\mod_Emeralds.java:18: reached end of file wh
ile parsing
}
*** minecraft_server.jar was not found, skipping
=== MCP 2.12 recompile script finished ===
Press any key to continue . . .
Can someone please can help me!!!
BTW i mod for minecraft 1.5_01
ShadowNightPro- Crafter
- Posts : 23
Join date : 2011-05-01
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Please post the code. I have a feeling you're missing a closing curly brace "}" at the end of your Version() function.
Kyle_Katarn- Iron Miner
- Posts : 35
Join date : 2011-04-26
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Here's the code:
For mod_Emeralds.java
And from the BlockEmeraldOre.java:
For mod_Emeralds.java
- Code:
package net.minecraft.src;
public class mod_Emeralds extends BaseMod
{
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
public mod_Emeralds()
{
ModLoader.RegisterBlock(emeraldOre);
emeraldOre.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/emeraldore.png");
ModLoader.AddName(emeraldOre, "Emerald Ore");
public String Version()
{
return "1.5_01";
}
}
And from the BlockEmeraldOre.java:
- Code:
package net.minecraft.src;
public class BlockEmeraldOre extends Block
{
protected BlockEmeraldOre(int i, int j)
{
super(i, j, Material.iron);
}
}
ShadowNightPro- Crafter
- Posts : 23
Join date : 2011-05-01
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
in the mod_Emeralds function, before the Version function, you're missing a closing curly brace. So just insert a '}' before the line:
public String Version()
public String Version()
Kyle_Katarn- Iron Miner
- Posts : 35
Join date : 2011-04-26
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
If i put } before the line it gives me these 2 errors
- Code:
*** Minecraft Coder Pack Version 2.12 ***
MCP 2.12 running in C:\MCP
Compiling Minecraft
sources\minecraft\net\minecraft\src\mod_Emeralds.java:3: net.minecraft.src.mod_E
meralds is not abstract and does not override abstract method Version() in net.m
inecraft.src.BaseMod
public class mod_Emeralds extends BaseMod
^
sources\minecraft\net\minecraft\src\mod_Emeralds.java:15: return outside method
return "1.5_01";
^
2 errors
*** minecraft_server.jar was not found, skipping
=== MCP 2.12 recompile script finished ===
Press any key to continue . . .
ShadowNightPro- Crafter
- Posts : 23
Join date : 2011-05-01
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Just to be clear, your mod_Emeralds.java file should look like this:
- Code:
package net.minecraft.src;
public class mod_Emeralds extends BaseMod
{
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
public mod_Emeralds()
{
ModLoader.RegisterBlock(emeraldOre);
emeraldOre.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/emeraldore.png");
ModLoader.AddName(emeraldOre, "Emerald Ore");
}
public String Version()
{
return "1.5_01";
}
}
Kyle_Katarn- Iron Miner
- Posts : 35
Join date : 2011-04-26
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Thanks you are the best!
ShadowNightPro- Crafter
- Posts : 23
Join date : 2011-05-01
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Can someone help me with item droping from a ore
I have this error:
And my BlockEmeraldOre.java is this:
Please help me!
I have this error:
- Code:
*** Minecraft Coder Pack Version 2.12 ***
MCP 2.12 running in C:\MCP
Compiling Minecraft
sources\minecraft\net\minecraft\src\BlockEmeraldOre.java:11: cannot find symbol
symbol : class Random
location: class net.minecraft.src.BlockEmeraldOre
public int idDropped(int i, Random random)
^
1 error
*** minecraft_server.jar was not found, skipping
=== MCP 2.12 recompile script finished ===
Press any key to continue . . .
And my BlockEmeraldOre.java is this:
- Code:
package net.minecraft.src;
public class BlockEmeraldOre extends Block
{
protected BlockEmeraldOre(int i, int j)
{
super(i, j, Material.iron);
}
public int idDropped(int i, Random random)
{
{
return mod_Emeralds.emeraldItem.shiftedIndex;
}
}
}
Please help me!
ShadowNightPro- Crafter
- Posts : 23
Join date : 2011-05-01
Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
Please don't ask in tutorials we have a questions section for that.
And to fix that you need to put this line below your package:
import java.util.Random;
So, that's resolved... I'm gonna have to lock to keep down spam.
And to fix that you need to put this line below your package:
import java.util.Random;
So, that's resolved... I'm gonna have to lock to keep down spam.
Similar topics
» [Beginner] Creating a new Item [22/4/11] [1.4_01] [2.11]
» [Beginner] Creating a new Tool Set [22/4/11] [1.4_01] [2.11]
» [Beginner] Creating a new Recipe [22/4/11] [1.4_01] [2.11]
» Official ModLoader Tutorials: Creating a new Block and Item
» [Beginner to Advanced] [List] List of blocks, items functions [updated 1/5/2011] [1.5_01] [2.12--]
» [Beginner] Creating a new Tool Set [22/4/11] [1.4_01] [2.11]
» [Beginner] Creating a new Recipe [22/4/11] [1.4_01] [2.11]
» Official ModLoader Tutorials: Creating a new Block and Item
» [Beginner to Advanced] [List] List of blocks, items functions [updated 1/5/2011] [1.5_01] [2.12--]
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|