Search code examples
javaminecraftminecraft-forge

Why can't I use setUnlocalizedName(String) return undefined when I use ItemSpatialMark


package itsjustlogic.logicmod;

import net.minecraft.item.Item;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;

@Mod(modid = "logic", name = "Logic's Mod", version = "1.0")
public class LogicsMod {
    
    public static Item itemSpatialMark;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        //Item/Block init and reg
        //Config handling
        itemSpatialMark = new ItemSpatialMark().setUnlocalizedName("ItemSpatialMark");
        GameRegistry.registerItem(itemSpatialMark, itemSpatialMark.getUnlocalizedName().substring(5));
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event){
        //Proxy, TileEntity, entity, GUI, and Packet Reg
    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event){
        
    }
}

Error: The method setUnlocalizedName(String) is undefined for the type ItemSpatialMark

I know this is kinda a basic question and theres probably a simple fix but I'm new to coding with forge. please help :(


Solution

  • In your ItemSpacialMark class, make sure that you're extending the net.minecraft.item.Item class like this,

     public class ItemSpacialMark extends Item { // Your code here }
    

    And, it is preferred to assign the name in setUnlocalizedName(String name) method through passing the arguments to the constructor like this,

    public ItemSpacialMark(String unlocalizedName){
           setRegistryName("reg-name");
           setUnlocalizedName(unlocalizedName);
    }  
    

    And, while calling the constructor,

    itemSpacialMark = new ItemSpacialMark("some name");