Jump to content

[1.7.2] [Solved] How to load/register an Item?


SackCastellon

Recommended Posts

I know the code to load/register a Basic Item on 1.6.4 and prior was:

 

Item Loader:

package SackCastellon.craftablehorsearmor.library.loader;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class ItemLoader {

public static Item Stirrup;

public static void load() {

	Stirrup = new SKCItem(1000).setUnlocalizedName("Stirrup").setCreativeTab(CreativeTabs.tabMisc).setTextureName( "CraftableHorseArmor:Stirrup");
}
}

 

Main Class:

package SackCastellon.craftablehorsearmor;

import java.io.File;

import SackCastellon.core.helper.LogHelper;
import SackCastellon.craftablehorsearmor.loader.ItemLoader;
import SackCastellon.craftablehorsearmor.proxy.CommonProxy;
import SackCastellon.craftablehorsearmor.reference.Reference;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(modid=Reference.MODID, name=Reference.NAME, version=Reference.VERSION, dependencies=Reference.DEPENDENCIES)
public class CraftableHorseArmor {	

    @Instance(Reference.MODID)
    public static CraftableHorseArmor instance;

    @SidedProxy(clientSide=Reference.CLPROXY, serverSide=Reference.CMPROXY)
    public static CommonProxy proxy;
   
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {}
   
    @EventHandler
    public void load(FMLInitializationEvent event) {
    	
// Items
    	
    	LogHelper.info(Reference.MODID, "Loading items.");
    	
	try {

    	ItemLoader.load();
    	
		LogHelper.info(Reference.MODID, "Items succesfully loaded.");

	} catch(Exception e) {

		LogHelper.severe(Reference.MODID, "Could not load items.");
	} 
    }
   
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {}

}

 

But how in 1.7.2 there aren't ID because the items are based on strings this code doesn't work.

 

So i tried to write a new code based on vanilla minecraft code, like this:

 

package SackCastellon.craftablehorsearmor.loader;

import SackCastellon.craftablehorsearmor.reference.Reference;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class ItemLoader {

public static final Item Stirrup = (Item)Item.field_150901_e.getObject("stirrup");

public static void load() {

	Item.field_150901_e.func_148756_a(500, "stirrup", (new Item()).setUnlocalizedName("Stirrup").setCreativeTab(CreativeTabs.tabMisc).setTextureName("CraftableHorseArmor:Stirrup"));
}
}

 

But still doesn't work..

 

Somebody know how to load/register a Item now?

 

Thanks for helping  :)

 

 

SOLUTION:

 

Just move the ItemLoader.load() from the load method to the preInit method in the Main Class

 

package SackCastellon.craftablehorsearmor;

import java.io.File;

import SackCastellon.core.helper.LogHelper;
import SackCastellon.craftablehorsearmor.loader.ItemLoader;
import SackCastellon.craftablehorsearmor.proxy.CommonProxy;
import SackCastellon.craftablehorsearmor.reference.Reference;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(modid=Reference.MODID, name=Reference.NAME, version=Reference.VERSION, dependencies=Reference.DEPENDENCIES)
public class CraftableHorseArmor {	

    @Instance(Reference.MODID)
    public static CraftableHorseArmor instance;

    @SidedProxy(clientSide=Reference.CLPROXY, serverSide=Reference.CMPROXY)
    public static CommonProxy proxy;
   
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {

// Items
    	
    	LogHelper.info(Reference.MODID, "Loading items.");
    	
	try {

    	ItemLoader.load();
    	
		LogHelper.info(Reference.MODID, "Items succesfully loaded.");

	} catch(Exception e) {

		LogHelper.severe(Reference.MODID, "Could not load items.");
	} 
}
   
    @EventHandler
    public void load(FMLInitializationEvent event) {}
   
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {}

}

Link to comment
Share on other sites

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.