添加作物时NullPointerException Minecraft MCP Forge 1.6?

时间:2014-05-09 16:42:31

标签: java minecraft minecraft-forge

我正在使用Minecraft MCP Forge 1.6制作一个Minecraft mod(不确定是否将其放入游戏部分)并且当我加载游戏时我得到NullPointerException

这是代码:
主要:http://pastebin.com/w8i0p46d

package net.minecraft.MFM;

import net.minecraft.MSM.eventmanager;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeedFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@Mod(modid = morefoodmod.modid, name = "More Food Mod", version = "0.1")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class morefoodmod {
    public static final String modid = "morefoodmod";
    @Instance("morefoodmod")
    public static morefoodmod instance = new morefoodmod();

    // public static CommonProxy proxy;

    @Init
    public void initMain(FMLInitializationEvent e) {
        // NetworkRegistry.instance().registerGuiHandler(this, new guiHandler());
    }
    public static CreativeTabs mfmTab;
    public static Block BlockStrawberry;
    public static Item ItemHealingApple;
    public static Item ItemRegenApple;
    public static Item ItemStrawberry;

    eventmanager eventmanager = new eventmanager();

    @EventHandler
    public void load(FMLInitializationEvent e) {
        mfmTab = new CreativeTabs("mfmTab") {
             @SideOnly(Side.CLIENT)
             public Item getTabItemIconIndex() {
                 return Item.fishCooked;
             }
        };
        LanguageRegistry.instance().addStringLocalization(mfmTab.getTranslatedTabLabel(), "More Food Mod");
        ItemHealingApple = new HealingApple(5371, 4, 2F, false).setPotionEffect(Potion.regeneration.id, 1, 255, 1.0F).setUnlocalizedName("itemHealingApple");
        ItemRegenApple = new RegenApple(8029, 4, 2F, false).setPotionEffect(Potion.regeneration.id, 300, 1, 1F).setUnlocalizedName("itemRegenApple");
        // Exception thrown on the following statement.
        ItemStrawberry = new ItemSeedFood(7231, 3, 0.5F, BlockStrawberry.blockID, Block.tilledField.blockID).setUnlocalizedName("itemStrawberry").setTextureName(modid + ":" + "itemStrawberry").setCreativeTab(CreativeTabs.tabFood);
        BlockStrawberry = new Strawberry(1018).setUnlocalizedName("blockStrawberry");
        GameRegistry.addRecipe(new ItemStack(ItemHealingApple, 1), new Object[]{"GPG", "DAD", "GPG", 'G', Item.ingotGold, 'D', Item.diamond, 'A', Item.appleRed, 'P', new ItemStack(Item.potion, 1, 8261)});
        GameRegistry.addRecipe(new ItemStack(ItemRegenApple, 1),new Object[]{"GPG", "DAD", "GPG", 'G', Item.ingotGold, 'D', Item.diamond, 'A', Item.appleRed, 'P', new ItemStack(Item.potion, 1, 8193)});

        registerBlock(BlockStrawberry, "StrawberryGrow");
        registerItem(ItemStrawberry, "Strawberry");
        registerItem(ItemHealingApple, "Healing Apple");
        registerItem(ItemRegenApple ,"Regeneration Apple");
    }
    public void registerItem(Item item, String name){
        GameRegistry.registerItem(item, item.getUnlocalizedName());
        LanguageRegistry.addName(item, name);
    }
    public void registerBlock(Block block, String name){
        GameRegistry.registerBlock(block, block.getUnlocalizedName());
        LanguageRegistry.addName(block, name);
    }
}

草莓:http://pastebin.com/7qC4DkNt

package net.minecraft.MFM;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;

public class Strawberry extends BlockCrops {
    @SideOnly(Side.CLIENT)
    private Icon[] iconArray;

    protected Strawberry(int par1) {
        super(par1);
    }

    @SideOnly(Side.CLIENT)
    public Icon getIcon(int side, int metadata) {
        if(metadata > 7) {
            if(metadata == 6)
                    metadata = 5;
            return iconArray[metadata >> 1];
        }
        return iconArray[3];
    }
    public int getSeedItem() {
            return morefoodmod.ItemStrawberry.itemID;
    }
    public int getCropItem() {
            return morefoodmod.ItemStrawberry.itemID;
    }
    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister iconRegister) {
        this.iconArray = new Icon[4];

        for(int i = 0; i < this.iconArray.length; i++)
            this.iconArray[i] = iconRegister.registerIcon(morefoodmod.modid + ":" + "itemStrawberry_" + (i+1));
    }

}

1 个答案:

答案 0 :(得分:1)

您在实际初始化之前使用的是对象:

ItemStrawberry = new ItemSeedFood(7231, 3, 0.5F, BlockStrawberry.blockID, Block.tilledField.blockID).setUnlocalizedName("itemStrawberry").setTextureName(modid + ":" + "itemStrawberry").setCreativeTab(CreativeTabs.tabFood);
BlockStrawberry = new Strawberry(1018).setUnlocalizedName("blockStrawberry");

BlockStrawBerry应初始化为ItemStrawberry