我最近一直在使用 IntelliJ IDEA 进行 Java 编码,尤其是 Minecraft。
我尝试扩展类 AbstractSkeletonEntity ,这是一个抽象类,具有一种最近对我来说很麻烦的特定方法:
abstract SoundEvent getStepSound();
在我自己的代码中,我尝试覆盖该方法:
public class SkeletonKnightEntity extends AbstractSkeletonEntity {
public boolean SkeletonCanSpawn = true;
public SkeletonKnightEntity(EntityType<? extends AbstractSkeletonEntity> entityType, World world) {
super(entityType, world);
}
protected SoundEvent getAmbientSound() {
return SoundEvents.ENTITY_WITHER_SKELETON_AMBIENT;
}
protected SoundEvent getHurtSound(DamageSource source) {
return SoundEvents.ENTITY_WITHER_SKELETON_HURT;
}
protected SoundEvent getDeathSound() {
return SoundEvents.ENTITY_WITHER_SKELETON_DEATH;
}
@Override
protected void playStepSound(BlockPos pos, BlockState state) {
this.playSound(this.getStepSound(), 0.15F, 1.0F);
}
@Override
protected SoundEvent getStepSound() { return SoundEvents.ENTITY_WITHER_SKELETON_STEP;}
//^ here is the error
@Override
public void attack(LivingEntity target, float pullProgress) {
}
@Override
public void tickMovement() {
super.tickMovement();
}
public static DefaultAttributeContainer.Builder createSKnightAttributes(){
return HostileEntity.createHostileAttributes()
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25D)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 30)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 1)
;
}
@Override
protected void initGoals() {
this.goalSelector.add(3, new FleeEntityGoal(this, WolfEntity.class, 6.0F, 1.0D, 1.2D));
this.goalSelector.add(5, new WanderAroundFarGoal(this, 1.0D));
this.goalSelector.add(6, new LookAtEntityGoal(this, PlayerEntity.class, 8.0F));
this.goalSelector.add(6, new LookAroundGoal(this));
this.targetSelector.add(1, new RevengeGoal(this, new Class[0]));
this.targetSelector.add(2, new FollowTargetGoal(this, PlayerEntity.class, true));
this.targetSelector.add(3, new FollowTargetGoal(this, IronGolemEntity.class, true));
this.targetSelector.add(3, new FollowTargetGoal(this, TurtleEntity.class, 10, true, false, TurtleEntity.BABY_TURTLE_ON_LAND_FILTER));
}
protected void dropEquipment(DamageSource source, int lootingMultiplier, boolean allowDrops) {
super.dropEquipment(source, lootingMultiplier, allowDrops);
Entity entity = source.getAttacker();
if (entity instanceof CreeperEntity) {
CreeperEntity creeperEntity = (CreeperEntity)entity;
if (creeperEntity.shouldDropHead()) {
creeperEntity.onHeadDropped();
this.dropItem(Items.SKELETON_SKULL);
}
}
}
}
IDE 告诉我要让代码工作,我必须声明 SkeletonKnightEntity 抽象或实现我已经做过的抽象方法 getStepSound()。当我尝试覆盖 getStepSound() 方法时,它告诉我它没有覆盖超类中的任何内容。有谁知道是什么原因造成的?