该方法必须覆盖或实现超方法
我想提出一个自定义的盔甲,在我的盔甲类我收到此错误:该方法必须覆盖或实现超方法
The method getArmorTexture(ItemStack, Entity, int, int) of type ArmorE must override or implement a supertype method
为什么我得到这个错误?
这里是我的代码:
防御等级:
package com.domoq.EmeraldGear.armor;
import com.domoq.EmeraldGear.EmeraldGearMod;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
public class ArmorE extends ItemArmor {
public ArmorE(ArmorMaterial part2ArmorE, int part3, int part4) {
super(part2ArmorE, part3, part4);
this.setCreativeTab(CreativeTabs.tabCombat);
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, int type) {
if (stack.getItem() == EmeraldGearMod.EmeraldHelmet || stack.getItem() == EmeraldGearMod.EmeraldChest || stack.getIconIndex() == EmeraldGearMod.EmeraldBoots) {
return "emeraldgearmod:textures/models/armor/ArmorL1.png";
} else if (stack.getItem() == EmeraldGearMod.EmeraldLegs) {
return "emeraldgearmod:textures/models/armor/ArmorL2.png";
} else return null;
}
}
主类的部分:
//Armor Material
public static ArmorMaterial ArmorE = EnumHelper.addArmorMaterial("AEmerald", 29, new int[]{3, 7, 4, 2}, 25);
//Armor Items
public static Item EmeraldHelmet = new ArmorE(ArmorE, 2, 0).setUnlocalizedName("EmeraldHelmet").setTextureName("emeraldgearmod:emerald_helmet");
public static Item EmeraldChest = new ArmorE(ArmorE, 2, 1).setUnlocalizedName("EmeraldChest").setTextureName("emeraldgearmod:emerald_chestplate");
public static Item EmeraldLegs = new ArmorE(ArmorE, 2, 2).setUnlocalizedName("EmeraldLegs").setTextureName("emeraldgearmod:emerald_leggings");
public static Item EmeraldBoots = new ArmorE(ArmorE, 2, 3).setUnlocalizedName("EmeraldBoots").setTextureName("emeraldgearmod:emerald_boots");
要重写一个方法,签名需要与super class相匹配。更换
public String getArmorTexture(ItemStack stack, Entity entity, int slot, int type) {
与
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
你在哪里找到超类方法的签名? – hexafraction 2014-09-29 23:39:10
您必须打开ItemArmor类并查看要覆盖的方法的参数类型和返回类型。复制和粘贴通常最有效,以确保它接受相同的变量。 在这种情况下,您的版本将为其'type'参数取代int而不是字符串。 – 2015-11-12 17:47:35
通常你可以参考javadocs - 链接已经死在这里,但更正后的代码仍然:) – Reimeus 2015-11-12 17:58:11
这意味着你不需要重写注解,因为你不重写或实施某种方法。因此,您应该只删除
@Override
正确 - 这对我有帮助;因为我的方法签名已经与父接口匹配(例如,如接受的答案所建议的那样)。谢谢! – Reece 2017-01-05 15:11:55
如果您使用的是Eclipse,再次尝试关闭和打开它。错误消失。
尽管这个答案被downvoted,(可悲),这是一个有效对Eclipse问题的回答太频繁。 – gdbj 2017-03-10 16:13:06
什么超类型方法是应该重写/实现?如果没有,*删除*'@ Override'。如果有,*正确*签名,使其正确匹配。 – user2864740 2014-09-29 23:23:41