ZidMC
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

+2
Jambokid
Ziddia
6 posters

Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Ziddia Fri Apr 22, 2011 10:13 am

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
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()
{
Or whatever your mod's class is. Now, what you still need to do is:
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.

Ziddia
Admin
Admin

Posts : 168
Join date : 2011-04-22

https://zidmc.forumotion.com

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Jambokid Thu Apr 28, 2011 1:12 am

I get this error at the code where you can code what drops from a block.

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 Smile


Last edited by Jambokid on Thu Apr 28, 2011 3:32 pm; edited 4 times in total
Jambokid
Jambokid
Recruit

Posts : 7
Join date : 2011-04-28

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Meglazero Thu Apr 28, 2011 1:19 am

Your BlockLightDustOre.java still has everything named as mod_Emeralds and BlockEmeraldOre... that's probably part of the problem Very Happy

Meglazero
Iron Miner

Posts : 51
Join date : 2011-04-22

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Jambokid Thu Apr 28, 2011 6:41 am

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 Sleep, It is still the same error confused
Jambokid
Jambokid
Recruit

Posts : 7
Join date : 2011-04-28

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Meglazero Thu Apr 28, 2011 8:26 am

The code Zid has in his tutorial for returning an item is:

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

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Jambokid Thu Apr 28, 2011 8:44 am

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
Jambokid
Recruit

Posts : 7
Join date : 2011-04-28

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Ziddia Thu Apr 28, 2011 3:18 pm

lightdustore definitely does NOT need shiftedIndex if it is a block.

Ziddia
Admin
Admin

Posts : 168
Join date : 2011-04-22

https://zidmc.forumotion.com

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Methuselah96 Thu Apr 28, 2011 4:38 pm

it should be .blockID
Methuselah96
Methuselah96
ZidMC Coder
ZidMC Coder

Posts : 159
Join date : 2011-04-22
Age : 28
Location : Philadelphia, Pennsylvania, United States

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Ziddia Thu Apr 28, 2011 4:41 pm

Please refrain from asking questions here by the way.

Ziddia
Admin
Admin

Posts : 168
Join date : 2011-04-22

https://zidmc.forumotion.com

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by ShadowNightPro Sun May 01, 2011 2:10 am

Can someone help me im making ores from the tutorial and it shows me this error:

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

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Kyle_Katarn Sun May 01, 2011 2:52 am

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

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by ShadowNightPro Sun May 01, 2011 3:03 am

Here's the code:
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

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Kyle_Katarn Sun May 01, 2011 3:18 am

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()

Kyle_Katarn
Iron Miner

Posts : 35
Join date : 2011-04-26

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by ShadowNightPro Sun May 01, 2011 3:25 am

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

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Kyle_Katarn Sun May 01, 2011 3:29 am

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

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by ShadowNightPro Sun May 01, 2011 3:37 am

Thanks you are the best! Very Happy

ShadowNightPro
Crafter

Posts : 23
Join date : 2011-05-01

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by ShadowNightPro Sun May 01, 2011 4:40 am

Can someone help me with item droping from a ore
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

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Ziddia Sun May 01, 2011 5:52 am

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.

Ziddia
Admin
Admin

Posts : 168
Join date : 2011-04-22

https://zidmc.forumotion.com

Back to top Go down

[Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11] Empty Re: [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum