Jump to content

Recommended Posts

Posted

after following a few guides I have created a new block however when I craft it I get a crash, the crash report seems to point to the blocks meta data but I have no idea why.

 

Spawning the block in works fine, but has no texture when holding.

 

My Custom Block:

 

package statslevelmod;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemTool;

public class BarkWall extends Block{

public BarkWall(String unlocalizedName, Material material, float hardness, float resistance) {
        super(material);
        this.setUnlocalizedName(unlocalizedName);
        this.setCreativeTab(CreativeTabs.tabBlock);
        this.setHardness(hardness);
        this.setResistance(resistance);
        this.setHarvestLevel("axe", 0);
        this.setLightOpacity(14);
        
    }

public BarkWall(String unlocalizedName, float hardness, float resistance) {

        this(unlocalizedName, Material.wood, hardness, resistance);
    }

    public BarkWall(String unlocalizedName) {
    	
        this(unlocalizedName, .6f, 3f);
    }
}

 

 

My Main Class (where I register)

 

package statslevelmod;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;

@Mod(modid = Level.MODID, name = Level.MODNAME, version = Level.VERSION)
public class Level {

    public static final String MODID = "statslevelmod";
    public static final String MODNAME = "Level";
    public static final String VERSION = "1.0.1";
    
    public static final Random rnumber = new Random();
    public static final ToolMaterial material = ToolMaterial.WOOD;
    
public static Set emptyset = new HashSet();
    public static Item sharpstick = new SharpStick();
    public static Item bark = new Bark();
    public static Item woodenrake = new WoodenRake();
    public static Item tensileweed = new TensileWeed();
    public static Item stringstrand = new StringStrand();
    public static Item weakropestrand = new WeakRopeStrand();
    public static Item weakrope = new WeakRope();
    
    public static Block barkwall;
    
    
    @EventHandler
    public void preInit (FMLPreInitializationEvent event) {
    	
    	System.out.println("Loading " + MODNAME + "!");
    	System.out.println("Version " + VERSION + "!");
    	
    	MinecraftForge.EVENT_BUS.register(new LevelEventHandler());
    	MinecraftForge.EVENT_BUS.register(new LevelGUI(Minecraft.getMinecraft()));
    	
    	registerRecipes();
    	createBlocks();
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event) {
    	
    	if (event.getSide() == Side.CLIENT) {
    		regTexture(sharpstick);
    		regTexture(bark);
    		regTexture(woodenrake);
    		regTexture(tensileweed);
    		regTexture(stringstrand);
    		regTexture(weakropestrand);
    		regTexture(weakrope);
    	}
    }
    
    @EventHandler
    public void postInt (FMLPostInitializationEvent event) {
    	
    	System.out.println(MODID + " loaded successfuly!");
    }
    
    @EventHandler
public void serverLoad(FMLServerStartingEvent event) {
	event.registerServerCommand(new SkillCommand());
}
    
    public void regTexture(Item item) {
       Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
    }
    
    public void regTexture(Block block) {
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(MODID + ":" + block.getUnlocalizedName().substring(5), "inventory"));
    }
    
    public static void createBlocks() {
	GameRegistry.registerBlock(barkwall = new BarkWall("barkwall"), "barkwall");
}
    
    public void registerRecipes() {
    	
    	GameRegistry.addShapelessRecipe(new ItemStack(Level.stringstrand), Level.tensileweed);
    	GameRegistry.addShapelessRecipe(new ItemStack(Items.string), Level.stringstrand, Level.stringstrand, Level.stringstrand);
    	GameRegistry.addShapelessRecipe(new ItemStack(Level.weakropestrand), Items.string, Items.string, Items.string);
    	GameRegistry.addShapelessRecipe(new ItemStack(Level.weakrope), Level.weakropestrand, Level.weakropestrand, Level.weakropestrand);
    	GameRegistry.addShapelessRecipe(new ItemStack(Blocks.crafting_table), Level.bark, Level.bark, Level.bark, Items.string);
    	
    	GameRegistry.addRecipe(new ItemStack(Items.wooden_axe),
    	"CD ",
    	"BA ",
    	" A ",
    	'A', Items.stick, 'B', sharpstick, 'C', bark, 'D', Items.string);
    	
    	GameRegistry.addRecipe(new ItemStack(woodenrake),
    	"BCB",
    	" A ",
    	" A ",
    	'A', Items.stick, 'B', sharpstick, 'C', Items.string);
    	
    	GameRegistry.addRecipe(new ItemStack(barkwall),
    	"BAB",
    	"BBB",
    	"BAB",
    	'A', Items.string, 'B', bark);
    	
    	GameRegistry.addRecipe(new ItemStack(barkwall),
    	"BBB",
    	"ABA",
    	"BBB",
    	'A', Items.string, 'B', bark);
    }
}

 

 

blockstate > barkwall.json

 

{
    "variants": {
        "normal": { "model": "statslevelmod:barkwall" }
    }
}

 

 

models > block > barkwall.json

 

{
    "parent": "block/cube_all",
    "textures": {
        "all": "statslevelmod:blocks/barkwall"
    }
}

 

 

models > item > barkwall.json

 

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

 

 

Crash Report

http://pastebin.com/BHmvLFYJ

Posted

You've created a recipe for an

ItemStack

with a

null

Item

. This is because you've registered your recipes before instantiating and registering your blocks.

 

You should instantiate and register your items and blocks in preInit (don't instantiate them in field initialisers) and then add recipes in init.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

You've created a recipe for an

ItemStack

with a

null

Item

. This is because you've registered your recipes before instantiating and registering your blocks.

 

You should instantiate and register your items and blocks in preInit (don't instantiate them in field initialisers) and then add recipes in init.

 

Thanks! worked like a charm, does your second sentence mean that I should move my

public static Item sharpstick = new SharpStick(); etc.

into a method like I did with blocks and call that in preInit also?

 

PS: should I register the blocks in the constructor like I did in in items?

package statslevelmod;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class SharpStick extends Item {

private final String name = "sharpstick";

public SharpStick() {
	super();

	GameRegistry.registerItem(this, name);
	setCreativeTab(CreativeTabs.tabMisc);
	setUnlocalizedName(name);
	setMaxStackSize(64);
}
}

 

or is doing it in a method like in blocks is the ideal way to go? seems like what I have done with items and blocks are two different ways to do the same thing but how should I do it?

Posted

Thanks! worked like a charm, does your second sentence mean that I should move my

public static Item sharpstick = new SharpStick(); etc.

into a method like I did with blocks and call that in preInit also?

 

Yes. I'd recommend creating a separate class each for your blocks and items and using those classes to instantiate, register and store your

Block

/

Item

instances. You can see an example of what I'm talking about here.

 

PS: should I register the blocks in the constructor like I did in in items?

...

or is doing it in a method like in blocks is the ideal way to go? seems like what I have done with items and blocks are two different ways to do the same thing but how should I do it?

 

You should keep the registration out of the constructor, that way you can more easily use the same class for multiple block/item types.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I still have no texture in the crafting table or in my hand :(

 

There should be some errors in the log telling you what went wrong.

 

The Grey Ghost has a guide to troubleshooting block and item rendering here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I still have no texture in the crafting table or in my hand :(

 

There should be some errors in the log telling you what went wrong.

 

The Grey Ghost has a guide to troubleshooting block and item rendering here.

 

Thanks, had no idea you had to render it as an item AND a block, the guide I followed skipped that step :P

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.