MC Modding
Please register and join the community!

[1.8.1] Block

View previous topic View next topic Go down

[1.8.1] Block

Post by Strengthowns on Wed Jun 15, 2011 5:48 am

Block

Spoiler:
BlockNamehere
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockNamehere extends Block
{

    public BlockNamehere(int i, int j)
    {
        super(i, j, Material.ground);      
    }
    public int idDropped(int i, Random random)
    {
      return mod_Namehere.Namehere.blockID;
    }
    public int quantityDropped(Random random)
    {
            return 3;
    }
}

mod_Namehere
Code:
package net.minecraft.src;

public class mod_Namehere extends BaseMod
{
  public static Block Namehere = new BlockNamehere(190, 0).setHardness(1.0F).setResistance(6000.0F).setLightValue(1.0F).setBlockName("Namehere");
 
  public String Version()
  {
      return "1.8.1";
  }
 
  public mod_Namehere()
  {
      ModLoader.RegisterBlock(Namehere);
      Namehere.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Namehere.png");
      ModLoader.AddName(Namehere, "Namehere");
      ModLoader.AddRecipe(new ItemStack(Namehere, 1), new Object[] {
      "###", "###", "###", Character.valueOf('#'), Item.redstone
      });
  }
}

Help: BlockNamehere

- Firstly, if you want to use some functions for your block, then have a look in "Block.java".

1. The line with this:
Code:
super(i, j, Material.ground);
. All you need to focus on is the "Material.ground" part. It can be any of the following:
Code:
//FOR MORE STATS ON THESE MATERIALS, LOOK AT THE BOTTOM OF "Material.java".

Material air; //You probably shouldn't use this one.
Material grass; //Pretty much the same as ground.
Material ground; //The block can be harvested when broken using this one.
Material wood; //It can be set on fire.
Material rock; // It can only be harvested with a pickaxe.
Material iron; // Can only be harvested with an iron pick or better.
Material water; //You probably shouldn't use this one.
Material lava; //You probably shouldn't use this one.
Material leaves; //It can burn.
Material plants; //You probably shouldn't use this one.
Material vine; //It can burn.
Material sponge; //You probably shouldn't use this one.
Material cloth; //It can burn.
Material fire; //You probably shouldn't use this one.
Material sand; //You probably shouldn't use this one.
Material circuits; //You probably shouldn't use this one.
Material glass; //You probably shouldn't use this one.
Material tnt; //You probably shouldn't use this one.
Material unused; //You probably shouldn't use this one.
Material ice; //You probably shouldn't use this one.
Material snow; //You probably shouldn't use this one.
Material craftedSnow; //You probably shouldn't use this one.
Material cactus; //You probably shouldn't use this one.
Material clay; //You probably shouldn't use this one.
Material pumpkin; //You probably shouldn't use this one.
Material portal; //You probably shouldn't use this one.
Material cakeMaterial; //You probably shouldn't use this one.
Material web; //You probably shouldn't use this one. Means it isn't solid.
Material piston; //You probably shouldn't use this one.

The main ones you need should use are the ground, rock and iron ones.

2. At this part:
Code:
return mod_Namehere.Namehere.blockID;
. If you leave it as it is now, it will drop the block you are making. If you want it to drop an item that is already part of the game, make it something like this:
Code:
return Item.redstone.shiftedIndex;
. For a block:
Code:
return Block.dirt.blockID;

3. For the bit like this:
Code:
return 3;
. You can make it drop more than one just by changing the "3" to whatever you want.

4. Navigate to this sort of path: "MCP\src\minecraft\net\minecraft\src" and save a copy of your file in there with the ".java" extension.

Help: mod_Namehere

1. This bit:
Code:
new BlockNamehere(190,
The 190 is the "ID" of your block. Block ID's can only go up to 255! Change it to an ID that isn't above 255 and isn't taken already by a block in the game.

2.
Code:
.setHardness(1.0F)
Is how hard it is to mine. For reference, dirt is 0.5F and stone is 1.5F.

3.
Code:
.setResistance(6000.0F)
Is how resistant to TNT the block is. For reference, all of the ores are 5.0F and obsidian is 2000.0F.

4.
Code:
.setLightValue(1.0F)
Is how much light you want it to give off (NOTE: The highest it can go is 1.0F!). For reference, torches are 0.9375F and redstone torches are 0.5F.

5.
Code:
.setBlockName("Namehere")
Is the name that it will look for in your code as the "code name".

6. At this part:
Code:
return "1.8.1";
in the version method, you can make that whatever you want in-between the " marks. It will show up in the modloader error log so people know what version it's made for.

7.
Code:
ModLoader.RegisterBlock(Namehere);
Is telling modloader to well, register the block.

8.
Code:
Namehere.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Namehere.png");
Is where your texture is found and what it is called. Change the "/Namehere.png" to what it's called. If you wanted to be able to find it in a folder of the minecraft.jar, make it something like this: "/My Folder!/Namehere.png".

9.
Code:
ModLoader.AddName(Namehere, "Nameingamehere");
Is what it is called in-game. Make the first "Namehere" what you called the block in the ".setBlockName("Namehere")" part. The second "Namehere" is what it's called in-game.

10. To explain the "ModLoader.AddRecipe" part. The "Namehere" word is what you get from crafting it, and the 1 is how many of it you get. Each set of "###" bits are 3 spaces across in the crafting grid. Then it's saying that "If the character is the # symbol, make it equal to redstone for when crafting".

[size="4"]SMP Block[/size]

Spoiler:
BlockNamehere
Code:

mod_Namehere
Code:

Help: BlockNamehere

1.
Help: mod_Namehere

1.
avatar
Strengthowns
Admin

Posts : 79
Join date : 2011-06-14
Location : Right here!

View user profile http://www.mcmodding.4umer.com

Back to top Go down

Re: [1.8.1] Block

Post by TheCodeNewbie on Tue Oct 25, 2011 1:18 pm

I posted this in the mc forums but no one replied so yeah, I'm getting this error when I try to recompile my block files:
Code:

== MCP v4.4 ==
> Recompiling client...
"C:\Program Files (x86)\Java\jdk1.7.0\bin\javac.exe" -g -source 1.6 -target 1.6
-classpath "lib/;lib/*;jars/bin/minecraft.jar;jars/bin/jinput.jar;jars/bin/lwjgl
.jar;jars/bin/lwjgl_util.jar" -sourcepath src/minecraft -d bin/minecraft src/min
ecraft\net\minecraft\client\*.java src/minecraft\net\minecraft\isom\*.java src/m
inecraft\net\minecraft\src\*.java  conf/patches/*.java failed.
Return code : 1

== ERRORS FOUND ==

warning: [options] bootstrap class path not set in conjunction with -source 1.6
src\minecraft\net\minecraft\src\Blockburner.java:8: error: invalid method declar
ation; return type required
public Blockburner(int i, int j)
^

src\minecraft\net\minecraft\src\mod_burner.java:12: error: <identifier> expected

public mod_burner)
^

2 errors
1 warning
==================

> Done in 2.31 seconds
> Recompiling server...
!! Can not find server sources !!
Press any key to continue . . .
Any help?

EDIT: I fixed the second error, it just need an opening bracket.... derp. Would still appreciate any help on the first error =D

TheCodeNewbie
Member

Posts : 6
Join date : 2011-10-25

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by Strengthowns on Wed Oct 26, 2011 1:29 am

Post this in the "Help" section.
avatar
Strengthowns
Admin

Posts : 79
Join date : 2011-06-14
Location : Right here!

View user profile http://www.mcmodding.4umer.com

Back to top Go down

Re: [1.8.1] Block

Post by bottz2 on Fri Oct 28, 2011 2:20 am

hey how do i make like a workbench or a chest

bottz2
Member

Posts : 14
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by mastereric on Fri Oct 28, 2011 2:42 pm

bottz2 wrote:hey how do i make like a workbench or a chest
Copy-paste code from the workbench/chest's class file
avatar
mastereric
Member

Posts : 30
Join date : 2011-10-26

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by bottz2 on Sat Oct 29, 2011 2:12 am

its hard to understand though

bottz2
Member

Posts : 14
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by noctisbeta on Thu Nov 03, 2011 11:36 pm

How do I make a block I made drop an item I made. I watched some tutorials and it says I have to type in
return mod_namehere.itemnamehere.shiftedIndex;
But I get an error saying that my itemname cannot be resolved or is not a field.
PLEASE HELP!

noctisbeta
Member

Posts : 4
Join date : 2011-11-03

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by ikke009 on Fri Nov 04, 2011 9:48 am

of course the mod_namehere needs to be changed to the filename where you registered the item, and itemnamehere needs to be changed to the name of the item.
avatar
ikke009
Member

Posts : 65
Join date : 2011-10-24
Age : 22
Location : The netherlands

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by noctisbeta on Fri Nov 04, 2011 3:31 pm

That's ok. I got it working, thanks! Now does anyone know what a "nullpointeexecption" is? A pro said it's the fault of my crashes and I don't know what it is or how to fix it. I have it in 3 files so, I really don't know what to do :S

noctisbeta
Member

Posts : 4
Join date : 2011-11-03

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by robinb96 on Fri Nov 25, 2011 11:15 pm

Please update Tut to 1.0.0
Thanks Very Happy

robinb96
Member

Posts : 3
Join date : 2011-11-25

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by jesshankin22 on Sat Nov 26, 2011 1:00 am

just for the time being, while this is not updated, the new code in MCP for blocks is...:
Code:
package net.minecraft.src;

package net.minecraft.src;

public class mod_Namehere extends BaseMod
{
  public static Block Namehere = new BlockNamehere (190, 0).setHardness(1.0F).setResistance(100.0F).setLightValue(0.0F).setBlockName("Namehere ");
 
  public String getVersion()
  {
      return "1.0.0";
  }
  public void load()
  {
  }
 
 
  public mod_Namehere ()
  {
      ModLoader.RegisterBlock(Namehere );
      Namhere .blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Namehere .png");
      ModLoader.AddName(Namehere , "Namehere ");
      ModLoader.AddRecipe(new ItemStack(Namehere, 1), new Object[] {
      "##", "##", Character.valueOf('#'), Block.dirt
      });
  }
}
and...
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockNamehere extends Block
{

    public BlockNamehere(int i, int j)
    {
        super(i, j, Material.ground);     
    }
    public int idDropped(int i, Random random)
    {
      return mod_Namhere.Namehere.shiftedIndex;
    }
    public int quantityDropped(Random random)
    {
            return 1;
    }
}

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by robinb96 on Sat Nov 26, 2011 1:14 pm

I get this error when I recompile can someone fix it?
Code:
== ERRORS FOUND ==

src/minecraft/net/minecraft/src/BlockGreenore.java:3: class, interface, or enum expected
package net.minecraft.src;
^

1 error
==================
This are my files:
BlockGreenore.java
Spoiler:
Code:
package net.minecraft.src;

package net.minecraft.src;

public class mod_Greenore extends BaseMod
{
  public static Block Greenore = new BlockGreenore (190, 0).setHardness(1.0F).setResistance(100.0F).setLightValue(0.0F).setBlockName("Greenore");
 
  public String getVersion()
  {
      return "1.0.0";
  }
  public void load()
  {
  }
 
 
  public mod_Greenore ()
  {
      ModLoader.RegisterBlock(Greenore);
      Greenore.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Greenore.png");
      ModLoader.AddName(Greenore, "Greenore");
      ModLoader.AddRecipe(new ItemStack(Greenore, 1), new Object[] {
      "##", "##", Character.valueOf('#'), Block.dirt
      });
  }
}
and mod_Greenore.java
Spoiler:
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockGreenore extends Block
{

    public BlockGreenore(int i, int j)
    {
        super(i, j, Material.ground);   
    }
    public int idDropped(int i, Random random)
    {
      return mod_Greenore.Greenore.shiftedIndex;
    }
    public int quantityDropped(Random random)
    {
            return 1;
    }
}

robinb96
Member

Posts : 3
Join date : 2011-11-25

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by jesshankin22 on Sat Nov 26, 2011 10:05 pm

oh whoops sorry I didn't post the right code... I must have gone over it twice, it should look like this...
Code:
package net.minecraft.src;

import java.util.Random;

public class Blockrereore extends Block
{

    public Blockrereore(int i, int j)
    {
        super(i, j, Material.ground);     
    }
    public int idDropped(int i, Random random)
    {
      return mod_RERE.rereore.blockID;
    }
    public int quantityDropped(Random random)
    {
            return 1;
    }
}
so just delete your code and replace all the rereores with your name and all the mod names with your name.... sorry about that

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by robinb96 on Sun Nov 27, 2011 1:06 am

I still get this error
Spoiler:
Code:
== ERRORS FOUND ==

src/minecraft/net/minecraft/src/BlockGreenore.java:3: class, interface, or enum expected
package net.minecraft.src;
^

1 error
==================

robinb96
Member

Posts : 3
Join date : 2011-11-25

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by xX_Lirianer_Xx on Sun Nov 27, 2011 5:20 am

You wrote "package net.minecraft.src;" twice.
PD: You got the files names wrong if they are the ones you wrote above each code, they should be the other way round.

xX_Lirianer_Xx
Member

Posts : 2
Join date : 2011-11-14

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by Ranga179 on Sun Nov 27, 2011 11:36 am

i think smp blocks are the same just you don't need the ModLoader.addName function in the code

Ranga179
Member

Posts : 9
Join date : 2011-10-19
Age : 20

View user profile

Back to top Go down

Re: [1.8.1] Block

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


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