Jump to content

[1.16.5] Game crashes because of MeleeAttackGoal#tick


ISenseHostility

Recommended Posts

Here is a clip to explain: https://streamable.com/5xjofu

Basically, when I walk out of range, I get a NullPointerException at LookController#setLookAt when it's being called from MeleeAttackGoal#tick.

Here is the log: https://privatebin.net/?05d1c1f8826d8bb2#79SvshoEzUji3NxL2oqTR2fi3CVzq66JPfps4HV1xTDb

Here is the class of the entity in question:

package com.isensehostility.entity_testing.entities;

import net.minecraft.entity.*;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.goal.*;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;

import javax.annotation.Nullable;

public class GobletEntity extends CreatureEntity {

    public GobletEntity(EntityType<? extends CreatureEntity> type, World worldIn) {
        super(type, worldIn);
    }

    @Override
    protected void registerGoals() {
        super.registerGoals();
        this.goalSelector.addGoal(0, new SwimGoal(this));
        this.goalSelector.addGoal(7, new WaterAvoidingRandomWalkingGoal(this, 1.0d));
        this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.3D, true));
        this.goalSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true));
    }

    public static AttributeModifierMap.MutableAttribute setAttributes() {
        return MobEntity.createMobAttributes()
                .add(Attributes.MAX_HEALTH, 1.0D)
                .add(Attributes.MOVEMENT_SPEED, 0.25D)
                .add(Attributes.ATTACK_DAMAGE, 2.0D);
    }

}

I'm not sure what is causing the error, or how to fix it.

Any help is appreciated.

Link to comment
Share on other sites

8 hours ago, ISenseHostility said:

Here is the class of the entity in question

Well, you should definitely add the NearestAttackableTargetGoal to the targetSelector and not the goalSelector, but I am not sure that will fix problem.

  • Like 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.