Posted May 19, 20214 yr I'm adding a new enemy to the game. But when I spawn it, it doesn't attack the player, even though I added the corresponding target selector. I borrowoed most of it from the ZombieEntity class. Here is the class: public class AngrySubEntity extends MonsterEntity { public AngrySubEntity(EntityType<? extends AngrySubEntity> type, World worldIn) { super(type, worldIn); this.goalSelector.addGoal(8, new LookAtGoal(this, PlayerEntity.class, 8.0F)); this.goalSelector.addGoal(8, new LookRandomlyGoal(this)); this.goalSelector.addGoal(7, new WaterAvoidingRandomWalkingGoal(this, 1.0D)); this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true)); } public static AttributeModifierMap.MutableAttribute createAttributes() { return MonsterEntity.func_234295_eP_() .createMutableAttribute(Attributes.FOLLOW_RANGE, 35.0D) .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.23F) .createMutableAttribute(Attributes.ATTACK_DAMAGE, 3.0D) .createMutableAttribute(Attributes.ARMOR, 2.0D); } protected int getExperiencePoints(PlayerEntity player) { return 0; } public boolean attackEntityFrom(DamageSource source, float amount) { if (!super.attackEntityFrom(source, amount)) { return false; } else return this.world instanceof ServerWorld; } protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return SoundEvents.ENTITY_ZOMBIE_HURT; } protected SoundEvent getStepSound() { return SoundEvents.ENTITY_ZOMBIE_STEP; } protected void playStepSound(BlockPos pos, BlockState blockIn) { this.playSound(this.getStepSound(), 0.15F, 1.0F); } }
May 19, 20214 yr You should register your goals in #registerGoals instead of your constructor. I'm not sure, but i think you should have an attack goal too (In zombie it is ZombieAttackGoal). If it still doesn't work, please post more code (or a github link). Hope i can help
May 19, 20214 yr Author 45 minutes ago, Silverminer said: You should register your goals in #registerGoals instead of your constructor. I'm not sure, but i think you should have an attack goal too (In zombie it is ZombieAttackGoal). If it still doesn't work, please post more code (or a github link). Hope i can help Thank you, now with those changes added, my entity now follows the player, like it tries to attack, but doesn't actually attack. @Override protected void registerGoals() { super.registerGoals(); this.goalSelector.addGoal(8, new LookAtGoal(this, PlayerEntity.class, 8.0F)); this.goalSelector.addGoal(8, new LookRandomlyGoal(this)); this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.0D, true)); this.goalSelector.addGoal(7, new WaterAvoidingRandomWalkingGoal(this, 1.0D)); this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true)); }
May 20, 20214 yr I've search a bit around and found this: https://gitlab.com/modding-legacy/lava-monster/-/blob/1.16.x/src/main/java/com/legacy/lava_monster/entity/LavaMonsterEntity.java It looks like they do what you want to do. Hope this helps. Do you have an implementation of #aiStep? Check if you call the super method. May i can help more when i see more code
May 20, 20214 yr 16 hours ago, Kiryu144 said: Thank you, now with those changes added, my entity now follows the player, like it tries to attack, but doesn't actually attack. 24 minutes ago, Silverminer said: I've search a bit around and found this: https://gitlab.com/modding-legacy/lava-monster/-/blob/1.16.x/src/main/java/com/legacy/lava_monster/entity/LavaMonsterEntity.java There are also a lot of vanilla examples that you could look at, e.g. ZombieEntity
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.