The Meaning of Life, the Universe, and Everything.
Location:
Somewhere deep in code.
Join Date:
12/11/2011
Posts:
354
Location:
Earth
Minecraft:
OliverGriffin
Member Details
I have made obsidian tools for my mod cDiamond (Common Diamond) that are the only tools that can mine cDiamond Ore. However the pickaxe may be the best one yet but every time it is used on the wrong material (e.g. gravel) the game crashes. I do believe this also happens with the other tools in different ways (e.g. shovel on stone) but i have no idea how to fix it. Any help Please? here is all the coding i have made. it would be most appreciated if any other bugs noticed were pointed out as well.
Class file mod_cDiamond:
package net.minecraft.src;
import java.util.Random;
public class mod_cDiamond extends BaseMod {
//Constructor
public mod_cDiamond() {
//Registered Blocks
ModLoader.RegisterBlock(cDiamond);
//Added Names
ModLoader.AddName(cDiamond, "cDiamond Ore");
ModLoader.AddName(dRod, "Diamond Rod");
ModLoader.AddName(oPick, "Obsidian Pickaxe");
ModLoader.AddName(oAxe, "Obsidian Axe");
ModLoader.AddName(oSpade, "Obsidian Spade");
ModLoader.AddName(oHoe, "Obsidian Hoe");
ModLoader.AddName(oSword, "Obsidian Sword");
//Added Overrides
cDiamond.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/cDiamond/cDiamond.png");
dRod.iconIndex = ModLoader.addOverride("/gui/items.png", "/cDiamond/dRod.png");
oPick.iconIndex = ModLoader.addOverride("/gui/items.png", "/cDiamond/oPick.png");
oAxe.iconIndex = ModLoader.addOverride("/gui/items.png", "/cDiamond/oAxe.png");
oSpade.iconIndex = ModLoader.addOverride("/gui/items.png", "/cDiamond/oSpade.png");
oHoe.iconIndex = ModLoader.addOverride("/gui/items.png", "/cDiamond/oHoe.png");
oSword.iconIndex = ModLoader.addOverride("/gui/items.png", "/cDiamond/oSword.png");
//Crafting Recipes
ModLoader.AddRecipe(new ItemStack(cDiamond, 1), new Object[] {
"XXX", "X#X", "XXX", Character.valueOf('X'), Block.cobblestone, Character.valueOf('#'), Item.diamond
});
ModLoader.AddRecipe(new ItemStack(dRod, 4), new Object[] {
"X", "X", Character.valueOf('X'), Item.diamond,
});
ModLoader.AddRecipe(new ItemStack(oPick, 1), new Object[] {
"XXX", " | ", " | ", Character.valueOf('X'), Block.obsidian, Character.valueOf('|'), mod_cDiamond.dRod,
});
ModLoader.AddRecipe(new ItemStack(oAxe, 1), new Object[] {
"XX ", "X| ", " | ", Character.valueOf('X'), Block.obsidian, Character.valueOf('|'), mod_cDiamond.dRod,
});
ModLoader.AddRecipe(new ItemStack(oAxe, 1), new Object[] {
" XX", " |X", " | ", Character.valueOf('X'), Block.obsidian, Character.valueOf('|'), mod_cDiamond.dRod,
});
ModLoader.AddRecipe(new ItemStack(oSpade, 1), new Object[] {
" X ", " | ", " | ", Character.valueOf('X'), Block.obsidian, Character.valueOf('|'), mod_cDiamond.dRod,
});
ModLoader.AddRecipe(new ItemStack(oHoe, 1), new Object[] {
"XX ", " | ", " | ", Character.valueOf('X'), Block.obsidian, Character.valueOf('|'), mod_cDiamond.dRod,
});
ModLoader.AddRecipe(new ItemStack(oHoe, 1), new Object[] {
" XX", " | ", " | ", Character.valueOf('X'), Block.obsidian, Character.valueOf('|'), mod_cDiamond.dRod,
});
ModLoader.AddRecipe(new ItemStack(oSword, 1), new Object[] {
" X ", " X ", " | ", Character.valueOf('X'), Block.obsidian, Character.valueOf('|'), mod_cDiamond.dRod,
});
//Furnace Recipes
ModLoader.AddSmelting(cDiamond.blockID, new ItemStack (Block.oreDiamond, 1));
ModLoader.AddSmelting(Block.oreDiamond.blockID, new ItemStack (Block.blockDiamond, 5));
//Other Initializers
world = ModLoader.getMinecraftInstance().theWorld;
}
//Block Generation
public void GenerateSurface(World world, Random random, int i, int j) {
for(int a = 0; a < 20; a++) {
int posX = i + random.nextInt(16);
int posY = random.nextInt(128);
int posZ = j + random.nextInt(16);
(new WorldGenMinable(cDiamond.blockID, 12)).generate(world, random, posX, posY, posZ);
}
}
//Stated Blocks
public static final Block cDiamond;
//Stated Items
public static final Item dRod;
public static final Item oPick;
public static final Item oAxe;
public static final Item oSpade;
public static final Item oHoe;
public static final Item oSword;
static {
//Initialized Blocks
cDiamond = new BlockcDiamond(161, 0).setHardness(1f).setResistance(50f).setStepSound(Block.soundMetalFootstep).setLightValue(0.5f).setBlockName("cDiamond");
//Initialized Items
dRod = new Item(420).setItemName("dRod");
oPick = new ItemPickaxe(421, EnumToolMaterial.OBSIDIAN).setItemName("oPick");
oAxe = new ItemAxe(422, EnumToolMaterial.OBSIDIAN).setItemName("oAxe");
oSpade = new ItemSpade(423, EnumToolMaterial.OBSIDIAN).setItemName("oSpade");
oHoe = new ItemHoe(424, EnumToolMaterial.OBSIDIAN).setItemName("oHoe");
oSword = new ItemSword(425, EnumToolMaterial.OBSIDIAN).setItemName("oSword");
}
//Other Object
World world;
//Version
public String Version() {
return "1.0.0";
}
//Unimplemented Methods
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
}
Class file BlockcDiamond:
package net.minecraft.src;
import java.util.Random;
public class BlockcDiamond extends Block
{
public BlockcDiamond(int i, int j)
{
super(i, j, Material.rock);
}
public int idDropped(int i, Random random, int j)
{
if(blockID == mod_cDiamond.cDiamond.blockID);
{
return Item.diamond.shiftedIndex;
}
}}
Class file EnumToolMaterial:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode fieldsfirst
package net.minecraft.src;
public enum EnumToolMaterial
{
WOOD("WOOD", 0, 0, 59, 2.0F, 0, 15),
STONE("STONE", 1, 1, 131, 4F, 1, 5),
IRON("IRON", 2, 2, 250, 6F, 2, 14),
EMERALD("EMERALD", 3, 3, 1561, 8F, 3, 10),
GOLD("GOLD", 4, 0, 32, 12F, 0, 22),
OBSIDIAN("OBSIDIAN", 5, 5, 2000, 90, 12, 10);
/*
public static final EnumToolMaterial WOOD;
public static final EnumToolMaterial STONE;
public static final EnumToolMaterial IRON;
public static final EnumToolMaterial EMERALD;
public static final EnumToolMaterial GOLD;
*/
private final int harvestLevel;
private final int maxUses;
private final float efficiencyOnProperMaterial;
private final int damageVsEntity;
private final int enchantability;
private static final EnumToolMaterial allToolMaterials[]; /* synthetic field */
/*
public static final EnumToolMaterial[] values()
{
return (EnumToolMaterial[])allToolMaterials.clone();
}
public static EnumToolMaterial valueOf(String s)
{
return (EnumToolMaterial)Enum.valueOf(net.minecraft.src.EnumToolMaterial.class, s);
}
*/
private EnumToolMaterial(String s, int i, int j, int k, float f, int l, int i1)
{
// super(s, i);
harvestLevel = j;
maxUses = k;
efficiencyOnProperMaterial = f;
damageVsEntity = l;
enchantability = i1;
}
public int getMaxUses()
{
return maxUses;
}
public float getEfficiencyOnProperMaterial()
{
return efficiencyOnProperMaterial;
}
public int getDamageVsEntity()
{
return damageVsEntity;
}
public int getHarvestLevel()
{
return harvestLevel;
}
public int getEnchantability()
{
return enchantability;
}
static
{
/*
WOOD = new EnumToolMaterial("WOOD", 0, 0, 59, 2.0F, 0, 15);
STONE = new EnumToolMaterial("STONE", 1, 1, 131, 4F, 1, 5);
IRON = new EnumToolMaterial("IRON", 2, 2, 250, 6F, 2, 14);
EMERALD = new EnumToolMaterial("EMERALD", 3, 3, 1561, 8F, 3, 10);
GOLD = new EnumToolMaterial("GOLD", 4, 0, 32, 12F, 0, 22);
*/
allToolMaterials = (new EnumToolMaterial[] {
WOOD, STONE, IRON, EMERALD, GOLD, OBSIDIAN
});
}
}
Class file Block:
Only changed line is:
obsidian = (new BlockObsidian(49, 37)).setHardness(1F).setResistance(2000F).setStepSound(soundStoneFootstep).setBlockName("obsidian");
And Last But Not Least (I Think Anyway)
Class file ItemPickaxe:
For anyone who bothered to read through this.
If You Fix My Problem
If anyone has any idea why i cant make armour or achievements (trying different version of ModLoader now - think it may have been outdated)Or finds any other major bugs!
And...
to anyone who steals my mod.
Oh! I almost forgot here is the error message when it crashes:
Mods loaded: 2
ModLoader 1.0.0
net.minecraft.src.mod_cDiamond null
Minecraft has crashed!
----------------------
Minecraft has stopped running because it encountered a problem.
If you wish to report this, please copy this entire text and email it to [email protected].
Please include a description of what you did when the error occured.
--- BEGIN ERROR REPORT 7a13abdd --------
Generated 10/01/12 10:26 AM
Minecraft: Minecraft 1.0.0
OS: Windows 7 (x86) version 6.1
Java: 1.7.0_02, Oracle Corporation
VM: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
LWJGL: 2.4.2
OpenGL: Intel 965/963 Graphics Media Accelerator version 2.0.0 - Build 8.14.10.1930, Intel
java.lang.NullPointerException
at net.minecraft.src.ItemTool.getStrVsBlock(ItemTool.java:34)
at net.minecraft.src.ItemPickaxe.getStrVsBlock(ItemPickaxe.java:67)
at net.minecraft.src.ItemStack.getStrVsBlock(ItemStack.java:107)
at net.minecraft.src.InventoryPlayer.getStrVsBlock(InventoryPlayer.java:294)
at net.minecraft.src.EntityPlayer.getCurrentPlayerStrVsBlock(EntityPlayer.java:553)
at net.minecraft.src.Block.blockStrength(Block.java:458)
at net.minecraft.src.PlayerControllerSP.clickBlock(PlayerControllerSP.java:82)
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1135)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1474)
at net.minecraft.client.Minecraft.func_40001_x(Minecraft.java:686)
at net.minecraft.client.Minecraft.run(Minecraft.java:627)
at java.lang.Thread.run(Unknown Source)
--- END ERROR REPORT 888e6c55 ----------
You should really create a new ENumToolMaterial,and just to add,a more easy way of doing a item/block/tool is
public static final Block myblock = new MyBlock(128,0);
As for the error,i cant see any problems after a quick look.
I was just doing what the tutorial told me to do when i was still following it. Why should i make a new EnumToolMaterial? Could it make the mod incompatible with others? How would i do that anyway?
public class EnumToolMaterialExtended extends EnumToolMaterial
public enum EnumToolMaterialExtended
{
OBSIDIAN("OBSIDIAN", 5, 5, 2000, 90F, 12, 10);
}
{
allToolMaterials = (new EnumToolMaterial[] {
OBSIDIAN
}
}
????? Or Something there abouts?
P.s. Thank You to xAuTzzHD for pointing out the F. I didn't notice that.
P.p.s. My Dad (who has a lot of experience in programming - just not in java) Says the error was that minecraft could not find the block that it was suppose to drop. Any ideas on this one?
EDIT: Ignore that coding - i tried it eclipse and it doesn't work. I also tried a heap of other things that resulted in me not saving the changes and exiting because i had completely stuffed up my mod. So back to square one of this bug... Any Ideas?
first of all, delete the crap with overriding abstract methods. they are not there just for fun. and you should delete the World to.
so, delete this:
//Other Object
World world;
//Version
public String Version() {
return "1.0.0";
}
//Unimplemented Methods
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
then change public mod_cDiamond() to public void load(), add
public String getVersion()
{
return "1.0.0";
}
and delete
world = ModLoader.getMinecraftInstance().theWorld.
this line is called when you start minecraft, but you don't have a world opened yet. so the world will always be null.
if you need the world, and there is no worldobject in the parameters, use ModLoader.getMinecraftInstance().theWorld, but not as an attribute. the world changes every time you change the world.
Errr okay...
Edit: It didn't seem to make any difference. However i did notice that it only crashes when the pickaxe was used on gravel not the other tools...
OBSIDIAN("OBSIDIAN", 5, 5, 2000, 90F, 12, 10); // like so...
Also, what the heck is this. Your trying to say if cDiamond block equals cDiamond block, drop item. Of course cDiamond block equals cDiamond block so change the code to this..
public int idDropped(int i, Random random, int j)
{
return Item.diamond.shiftedIndex;
}
}}
I'm not sure if this will fix your problem, but this will make you code tidy.
Class file mod_cDiamond:
Class file BlockcDiamond:
Class file EnumToolMaterial:
Class file Block:
Only changed line is:
And Last But Not Least (I Think Anyway)
Class file ItemPickaxe:
For anyone who bothered to read through this.
If You Fix My Problem
If anyone has any idea why i cant make armour or achievements (trying different version of ModLoader now - think it may have been outdated)Or finds any other major bugs!
And...
to anyone who steals my mod.
Oh! I almost forgot here is the error message when it crashes:
Thank You.
Link To Mod's Page: http://www.minecraftforum.net/topic/881890-100-cdiamond-mod/
Did I help? +1 my reputation!
Tool for copying and pasting commands in bulk - http://www.minecraftforum.net/forums/minecraft-discussion/redstone-discussion-and/command-blocks/2417077-tool-for-copy-pasting-similar-commands-in-bulk
Change to
You forgot the 'F' after the 4th Number of Obsidian
I was just doing what the tutorial told me to do when i was still following it. Why should i make a new EnumToolMaterial? Could it make the mod incompatible with others? How would i do that anyway?
????? Or Something there abouts?
P.s. Thank You to xAuTzzHD for pointing out the F. I didn't notice that.
P.p.s. My Dad (who has a lot of experience in programming - just not in java) Says the error was that minecraft could not find the block that it was suppose to drop. Any ideas on this one?
EDIT: Ignore that coding - i tried it eclipse and it doesn't work. I also tried a heap of other things that resulted in me not saving the changes and exiting because i had completely stuffed up my mod. So back to square one of this bug... Any Ideas?
Did I help? +1 my reputation!
Tool for copying and pasting commands in bulk - http://www.minecraftforum.net/forums/minecraft-discussion/redstone-discussion-and/command-blocks/2417077-tool-for-copy-pasting-similar-commands-in-bulk
I don't know. I didn't write that i just edited the ItemPickaxe to put this in:
That bit of coding makes it so that only and obsidian pickaxe may mine the cDiamond Ore(along with EnumToolMaterial).
Did I help? +1 my reputation!
Tool for copying and pasting commands in bulk - http://www.minecraftforum.net/forums/minecraft-discussion/redstone-discussion-and/command-blocks/2417077-tool-for-copy-pasting-similar-commands-in-bulk
Errr okay...
Edit: It didn't seem to make any difference. However i did notice that it only crashes when the pickaxe was used on gravel not the other tools...
Did I help? +1 my reputation!
Tool for copying and pasting commands in bulk - http://www.minecraftforum.net/forums/minecraft-discussion/redstone-discussion-and/command-blocks/2417077-tool-for-copy-pasting-similar-commands-in-bulk
Also, what the heck is this. Your trying to say if cDiamond block equals cDiamond block, drop item. Of course cDiamond block equals cDiamond block so change the code to this..
I'm not sure if this will fix your problem, but this will make you code tidy.