(Forge) 实例化扩展 ItemAxe 的新 class 不起作用
(Forge) Instantiating a new class that extends ItemAxe doesn’t work
我正在创建 Minecraft 1.12.2 mod(锻造 1.12.2-
14.23.1.2555),我创建了一个扩展 ItemAxe 的新 class。当我将新的 class 实例化为变量时,变量 returns 为空。因此,当项目被注册时,将抛出 NullPointerException。在我尝试将 ItemAxe 的扩展名更改为 ItemPickaxe 之后,我归结为这个。 运行 代码,有效。改回 ItemAxe,运行 代码,没有用。我做的ItemAxe class 的源代码和我做的ItemPickaxe class 完全一样,当然只是ItemAxe class 里的Pickaxe 换成了Ax。我知道我没有使用最新版本的 Forge for 1.12.2,但我使用的是这个版本,因为它在涉及 运行 来自 IDE 的代码时对我来说效果更好。有任何解决这个问题的方法吗?我知道这是一个已知错误...
来源:
// CustomAxe.java
public class CustomAxe extends ItemAxe {
public CustomAxe(ToolMaterial material, String name) {
super(material);
this.setRegistryName(name);
this.setUnlocalizedName(name);
this.setCreativeTab(CreativeTabs.TOOLS);
}
}
// Main.java
public static Item austroneAxe;
public static ToolMaterial austrone;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
austrone = EnumHelper.addToolMaterial(“austrone”, 4, 2007, 12.0F, 66.0F, 30);
austroneAxe = new CustomAxe(austrone, “austrone_axe”);
}
// CommonProxy.java
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(Main.austroneAxe); // Exception thrown here
}
在进一步研究问题后,我解决了问题。
默认的 super
构造函数不适用于 ItemAxe。因此,您必须使用辅助构造函数,其中您必须提供一个 ToolMaterial、一个用于攻击伤害的浮点数和一个用于攻击速度的浮点数。就我而言,以下代码行对我有用:
super(material, material.getAttackDamage,1.0F);
我正在创建 Minecraft 1.12.2 mod(锻造 1.12.2- 14.23.1.2555),我创建了一个扩展 ItemAxe 的新 class。当我将新的 class 实例化为变量时,变量 returns 为空。因此,当项目被注册时,将抛出 NullPointerException。在我尝试将 ItemAxe 的扩展名更改为 ItemPickaxe 之后,我归结为这个。 运行 代码,有效。改回 ItemAxe,运行 代码,没有用。我做的ItemAxe class 的源代码和我做的ItemPickaxe class 完全一样,当然只是ItemAxe class 里的Pickaxe 换成了Ax。我知道我没有使用最新版本的 Forge for 1.12.2,但我使用的是这个版本,因为它在涉及 运行 来自 IDE 的代码时对我来说效果更好。有任何解决这个问题的方法吗?我知道这是一个已知错误...
来源:
// CustomAxe.java
public class CustomAxe extends ItemAxe {
public CustomAxe(ToolMaterial material, String name) {
super(material);
this.setRegistryName(name);
this.setUnlocalizedName(name);
this.setCreativeTab(CreativeTabs.TOOLS);
}
}
// Main.java
public static Item austroneAxe;
public static ToolMaterial austrone;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
austrone = EnumHelper.addToolMaterial(“austrone”, 4, 2007, 12.0F, 66.0F, 30);
austroneAxe = new CustomAxe(austrone, “austrone_axe”);
}
// CommonProxy.java
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(Main.austroneAxe); // Exception thrown here
}
在进一步研究问题后,我解决了问题。
默认的 super
构造函数不适用于 ItemAxe。因此,您必须使用辅助构造函数,其中您必须提供一个 ToolMaterial、一个用于攻击伤害的浮点数和一个用于攻击速度的浮点数。就我而言,以下代码行对我有用:
super(material, material.getAttackDamage,1.0F);