Minecraft Forge Mod 1.7.10版本在添加新配方后不断崩溃

时间:2018-08-11 20:02:33

标签: java minecraft minecraft-forge

我目前在开发第一个手写模块时遇到一些问题。我目前正在使用Eclipse Photon作为我的IDE,在64位计算机上运行Windows 10 Home,并且具有4 GB的内存。

这是我的代码:

package com.haxium.basicmod.obsidian.armor;

import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
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.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import com.haxium.basicmod.obsidian.armor.ItemObsidianGeneric;
import com.haxium.basicmod.obsidian.armor.ItemObsidianArmor;
@Mod(modid = ObsidianArmor.MODID, version = ObsidianArmor.VERSION, name = ObsidianArmor.NAME)
public class ObsidianArmor {
    public static final String MODID = "obsidian_armor";
    public static final String VERSION = "1.7.10-Stable-1.1.0.1";
    public static final String NAME = "HaxCraft Obsidian Edition";
    //tools
    public static Item obsidian_pickaxe;
    public static Item obsidian_sword;
    public static Item obsidian_ingot;
    ToolMaterial obsidian = EnumHelper.addToolMaterial("obsidian", 3, 4500, 10.1F, 4.5F, 10);
    //armor
    public static Item obsidian_helmet;
    public static Item obsidian_chest;
    public static Item obsidian_leggings;
    public static Item obsidian_boots;
    ArmorMaterial hardened_obsidian = EnumHelper.addArmorMaterial("hardened_obsidian", 20, new int[] {3, 7, 6, 3}, 25);
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        //tools
        obsidian_pickaxe = new ItemObsidianPickaxe(obsidian, "obsidian_pickaxe");
        obsidian_sword = new ItemObsidianSword(obsidian, "obsidian_sword");
        obsidian_ingot = new ItemObsidianGeneric("obsidian_ingot");
        GameRegistry.registerItem(obsidian_ingot, "Obsidian Ingot");
        GameRegistry.registerItem(obsidian_sword, "Obsidian Sword");
        GameRegistry.registerItem(obsidian_pickaxe, "Obsidian Pickaxe");
        //Armor
        obsidian_boots =  new ItemObsidianArmor(hardened_obsidian, 3, "obsidian_boots");
        obsidian_helmet = new ItemObsidianArmor(hardened_obsidian, 0, "obsidian_helmet");
        obsidian_chest = new ItemObsidianArmor(hardened_obsidian, 1, "obsidian_chest");
        obsidian_leggings = new ItemObsidianArmor(hardened_obsidian, 2, "obsidian_leggings");
        GameRegistry.registerItem(obsidian_helmet, "Obsidian Helmet");
        GameRegistry.registerItem(obsidian_chest, "Obsidian Chestplate");
        GameRegistry.registerItem(obsidian_leggings, "Obsidian Leggings");
        GameRegistry.registerItem(obsidian_boots, "Obsidian Boots");
    }
    @EventHandler
    public void init(FMLInitializationEvent event) {
        GameRegistry.addRecipe(new ItemStack(Items.apple, 9),
                "XXX",
                "XXX",
                "XXX",
                'X', Blocks.leaves
        );
        GameRegistry.addRecipe(new ItemStack(ObsidianArmor.obsidian_ingot, 9),
                "X",
                'X', Blocks.obsidian
        );
        GameRegistry.addRecipe(new ItemStack(ObsidianArmor.obsidian_pickaxe),
                "ABC",
                "E",
                "H",
                'A', ObsidianArmor.obsidian_ingot, 'B', ObsidianArmor.obsidian_ingot, 'C', ObsidianArmor.obsidian_ingot,  'E', Items.stick, 'H', Items.stick
        );
        GameRegistry.addRecipe(new ItemStack(ObsidianArmor.obsidian_sword),
                "B",
                "E",
                "HI",
                'B', ObsidianArmor.obsidian_ingot, 'E', ObsidianArmor.obsidian_ingot, 'H', Items.stick
        );
        GameRegistry.addRecipe(new ItemStack(ObsidianArmor.obsidian_helmet),
                "ABC",
                "DF",
                'A', ObsidianArmor.obsidian_ingot, 'B', ObsidianArmor.obsidian_ingot, 'C', ObsidianArmor.obsidian_ingot, 'D', ObsidianArmor.obsidian_ingot, 'F', ObsidianArmor.obsidian_ingot
        );
        GameRegistry.addRecipe(new ItemStack(ObsidianArmor.obsidian_chest),
                "AC",
                "DEF",
                "GHI",
                'A', ObsidianArmor.obsidian_ingot, 'C', ObsidianArmor.obsidian_ingot, 'D', ObsidianArmor.obsidian_ingot, 'E', ObsidianArmor.obsidian_ingot, 'F', ObsidianArmor.obsidian_ingot, 'G', ObsidianArmor.obsidian_ingot, 'H', ObsidianArmor.obsidian_ingot, 'I', ObsidianArmor.obsidian_ingot
        );
        GameRegistry.addRecipe(new ItemStack(ObsidianArmor.obsidian_leggings),
                "ABC",
                "DF",
                "GI",
                'A', ObsidianArmor.obsidian_ingot, 'B', ObsidianArmor.obsidian_ingot, 'C', ObsidianArmor.obsidian_ingot, 'D', ObsidianArmor.obsidian_ingot, 'F', ObsidianArmor.obsidian_ingot, 'G', ObsidianArmor.obsidian_ingot, 'I', ObsidianArmor.obsidian_ingot
        );
        GameRegistry.addRecipe(new ItemStack(ObsidianArmor.obsidian_boots),
                "AC",
                "DF",
                'A', ObsidianArmor.obsidian_ingot, "C", ObsidianArmor.obsidian_ingot, 'D', ObsidianArmor.obsidian_ingot, 'F', ObsidianArmor.obsidian_ingot
        );
    }
}

关于为什么这种情况持续失败的任何建议?如果需要,我确实有崩溃日志的本地副本。

2 个答案:

答案 0 :(得分:2)

食谱中字符的形状必须为矩形。如果配方本身不是矩形,请在不需要项目的地方添加空格。例如,这:

            "ABC",
            "E",
            "H",

应该是这样:

            "ABC",
            " E ",
            " H ",

对所有食谱进行更改后,错误就会消失。

答案 1 :(得分:0)

GameRegistry.addRecipe(new ItemStack(ObsidianArmor.obsidian_sword),
            "B",
            "E",
            "HI",
            'B', ObsidianArmor.obsidian_ingot, 'E', ObsidianArmor.obsidian_ingot, 'H', Items.stick
    );

您缺少I应该是什么。

在第69行的新代码中,您缺少一些空格以使食谱方形。您应该始终填写3x3网格。或确保定义配方的数组中的每个项目都包含相等数量的项目。

 "B " // lacks a space
 "E ", // lacks a space
 "H  ", // proper amount of spaces

在那些崩溃日志中,总是找到属于您的类的类,该类将为您提供导致它的类中的行号

  

com.haxium.basicmod.obsidian.armor.ObsidianArmor.init(ObsidianArmor.java:69)

这使我们在文件ObsidianArmour.java中的第69行

以及顶部的错误

  

java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:7

告诉我们问题出在字符串上。字符太少,而不是预期的9。