Jump to content

Recommended Posts

Posted

Hey sorry for my bad english, i am german. So i am coding a mod where I craft a custom block but when i put the last item in the crafting gui minecraft crashes with a null pointer exception (when you need the crash report just post it)

 

here is  my main class:

 

 

//Variablen

public static final String MODID = "kohlewerk";

   

 

 

 

public static final int GUIMASCHC = 0;

 

List<String> authors = Arrays.asList("Jan");

 

Block blockmaschc = new BlockMaschC();

ItemStack maschc = new ItemStack(blockmaschc);

 

@Instance

public static KohleWerk instance;

 

 

 

@EventHandler

public void preInit(FMLPreInitializationEvent event){

 

 

ModMetadata ModData = event.getModMetadata();

modinfo(ModData);

        GameRegistry.addShapedRecipe(maschc, "XXX",

                                    "XYX",

                                            "ZZZ", 'X', new ItemStack(Blocks.cobblestone), 'Y', new ItemStack(Items.diamond), 'Z', new ItemStack(Items.coal));

 

 

 

}

 

@EventHandler

public void Init(FMLInitializationEvent event){

 

 

GameRegistry.registerBlock(blockmaschc, "maschc");

Item itemfromblock = Item.getItemFromBlock(blockmaschc);

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemfromblock, 3, new ModelResourceLocation("kohlewerk:maschc", "inventory"));

 

 

//GuiHandler

 

NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());

 

//TileEntitys

 

GameRegistry.registerTileEntity(TileEntityMaschC.class, "TileEntityMaschC");

 

 

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event){

 

}

 

public void modinfo(ModMetadata data){

//Modinfos setzten

 

data.autogenerated = false;

data.name = EnumChatFormatting.BLUE +  "" + EnumChatFormatting.BOLD  + "Kohle Werk";

data.authorList = authors;

data.description = "Dieser Mod fügt ein Kohlewerk hinzu mit dem man Erze vervielvältigen kann.";

data.credits = "HyCraftHD";

data.logoFile = "assets/kohlewerk/textures/logo/logo.png";

data.version= "0.1";

}

 

 

public void CraftingOfen(){

 

 

}

 

}

 

I hope you can help me

thanks in advance <3

Jan

 

 

 

Posted

So my code is now this:

 

@Mod(modid = KohleWerk.MODID)

public class KohleWerk {

   

//Variablen

public static final String MODID = "kohlewerk";

   

public static Item koks = new ItemKoks();

 

 

public static final int GUIMASCHC = 0;

 

List<String> authors = Arrays.asList("Jan");

 

Block blockmaschc = new BlockMaschC();

ItemStack maschc = new ItemStack(blockmaschc);

 

@Instance

public static KohleWerk instance;

 

 

 

@EventHandler

public void preInit(FMLPreInitializationEvent event){

 

GameRegistry.registerBlock(blockmaschc, "maschc");

Item itemfromblock = Item.getItemFromBlock(blockmaschc);

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemfromblock, 3, new ModelResourceLocation("kohlewerk:maschc", "inventory"));

 

 

 

GameRegistry.registerItem(koks, "koks");

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(koks, 0, new ModelResourceLocation("kohlewerk:koks", "inventory"));

 

 

//GuiHandler

 

NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());

 

//TileEntitys

 

GameRegistry.registerTileEntity(TileEntityMaschC.class, "TileEntityMaschC");

 

 

ModMetadata ModData =  event.getModMetadata();

modinfo(ModData);

 

 

 

}

 

@EventHandler

public void Init(FMLInitializationEvent event){

 

        GameRegistry.addShapedRecipe(maschc, "XXX",

                                    "XYX",

                                            "ZZZ", 'X', Blocks.cobblestone, 'Y',Items.diamond, 'Z', Items.coal);

 

 

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event){

 

}

 

public void modinfo(ModMetadata data){

//Modinfos setzten

 

data.autogenerated = false;

data.name = EnumChatFormatting.BLUE +  "" + EnumChatFormatting.BOLD  + "Kohle Werk";

data.authorList = authors;

data.description = "Dieser Mod fügt ein Kohlewerk hinzu mit dem man Erze vervielvältigen kann.";

data.credits = "HyCraftHD";

data.logoFile = "assets/kohlewerk/textures/logo/logo.png";

data.version= "0.1";

}

 

 

public void CraftingOfen(){

 

 

}

 

}

 

 

but it still crashes when i craft

 

Posted

After reading what you have done, there is a lot of clean up to do.

 

ItemStack maschc = new ItemStack(blockmaschc);

No.

 

Block blockmaschc = new BlockMaschC();

Should be public static

 

   public void CraftingOfen(){
      
      
   }

?

 

public void modinfo(ModMetadata data){
      //Modinfos setzten
      
      data.autogenerated = false;
      data.name = EnumChatFormatting.BLUE +  "" + EnumChatFormatting.BOLD  + "Kohle Werk";
      data.authorList = authors;
      data.description = "Dieser Mod fügt ein Kohlewerk hinzu mit dem man Erze vervielvältigen kann.";
      data.credits = "HyCraftHD";
      data.logoFile = "assets/kohlewerk/textures/logo/logo.png";
      data.version= "0.1";
   }

Not sure why you do this in a method if you can fill the mcmod.info (I think that was its name)

 

To come to your problem. Replace the reference to the maschc with a new ItemStack(blockmaschc). If that doenst helps post your log and if u changed the code post it also. and please us tags

 

 

Posted

First of all thank you but is still doesnt work so now here`s my main class

@Mod(modid = KohleWerk.MODID)
public class KohleWerk {
    
//Variablen
public static final String MODID = "kohlewerk";
    
public static Item koks = new ItemKoks();


public static final int GUIMASCHC = 0;

List<String> authors = Arrays.asList("Jan");

public static Block blockmaschc = new BlockMaschC();


@Instance
public static KohleWerk instance;

  

@EventHandler
public void preInit(FMLPreInitializationEvent event){


	GameRegistry.addShapedRecipe(new ItemStack(KohleWerk.blockmaschc), "XXX",
                                                                           "XYX",
                                                                           "ZZZ", 'X', Blocks.cobblestone, 'Y',Items.diamond, 'Z', Items.coal);





	//GuiHandler

	NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());

	//TileEntitys

	GameRegistry.registerTileEntity(TileEntityMaschC.class, "TileEntityMaschC");


	ModMetadata ModData =  event.getModMetadata();
	modinfo(ModData);



}

@EventHandler
public void Init(FMLInitializationEvent event){
	GameRegistry.registerBlock(blockmaschc, "maschc");
	Item itemfromblock = Item.getItemFromBlock(blockmaschc);

	GameRegistry.registerItem(koks, "koks");
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(koks, 0, new ModelResourceLocation("kohlewerk:koks", "inventory"));



	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemfromblock, 3, new ModelResourceLocation("kohlewerk:maschc", "inventory"));
        

}

@EventHandler
public void postInit(FMLPostInitializationEvent event){

}
   
public void modinfo(ModMetadata data){
	//Modinfos setzten

	data.autogenerated = false;
	data.name = EnumChatFormatting.BLUE +  "" + EnumChatFormatting.BOLD  + "Kohle Werk";
	data.authorList = authors;
	data.description = "Dieser Mod fügt ein Kohlewerk hinzu mit dem man Erze vervielvältigen kann.";
	data.credits = "HyCraftHD";
	data.logoFile = "assets/kohlewerk/textures/logo/logo.png";
	data.version= "0.1";
}



}

i set the mod data in methods becuase i don`t like the mcmod.info file

 

so here`s my crashreport

 

  Reveal hidden contents

 

 

Posted

Seems like there is a problem with ur json's, but that sohuldnt create a crash.. The problem isnt because u are crafting the item it seems like there is something wrong with rendering it..

I am not good at that, if u are lucky TheGreyGhost will take a look and find ur error :b

 

For now. Show ur json's , since minecraft seems to miss them.

 

Also DONT DO THIS

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemfromblock, 3, new ModelResourceLocation("kohlewerk:maschc", "inventory"));

U need to do that inside ur proxy, because if u compile the mod and run it on a server it will throw you a ClassNotFound exception.

Rendering stuff is Client ONLY so u need to register the renderer inside ur proxy.

 

Posted

 

Here are my json files

blockstates

{
    "variants": {
        "normal": { "model": "kohlewerk:maschc" }
    }
}

models.item

{
    "parent": "kohlewerk:block/maschc",
    "display": {
        "thirdperson": {
            "rotation": [ 10, -45, 170 ],
            "translation": [ 0, 1.5, -2.75 ],
            "scale": [ 0.375, 0.375, 0.375 ]
        }
    }
}

models.block

{
    "parent": "block/cube",
    "textures": {
    
    
        "particle": "kohlewerk:blocks/maschc_top",
        "up": "kohlewerk:blocks/maschc_top",
        "down": "kohlewerk:blocks/maschc_side",
        "north": "kohlewerk:blocks/maschc_front",
        "south": "kohlewerk:blocks/maschc_side",
        "west": "kohlewerk:blocks/maschc_side",
        "east": "kohlewerk:blocks/maschc_side"
    
    }
}

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.