Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

A question of AnimalEntity


sevenki666
 Share

Recommended Posts

MC version :1.16.5 Forge version :36.2.20

I added "MeleeAttackGoal" in my entity,and then I can‘t summon this entity.what's wrong in my code?

//the entity's code

package net.fsmc.classmates.animals;

import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.goal.*;
import net.minecraft.entity.merchant.villager.AbstractVillagerEntity;
import net.minecraft.entity.monster.ZombifiedPiglinEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.IronGolemEntity;
import net.minecraft.entity.passive.TurtleEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;

import javax.annotation.Nullable;

public class n7Yjy extends AnimalEntity  {

    

    public n7Yjy(EntityType<? extends AnimalEntity> type, World worldIn) {
        super(type, worldIn);

    }
    
    public static AttributeModifierMap.@NotNull MutableAttribute registerAttributes() {
         return MobEntity.func_233666_p_()
                 .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.23000000417232513D)
                 .createMutableAttribute(Attributes.ATTACK_DAMAGE, 7.0D)
                 .createMutableAttribute(Attributes.FOLLOW_RANGE, 40.0D)
                 .createMutableAttribute(Attributes.MAX_HEALTH, 30.0D);

     }
    

    @Override
    protected void registerGoals(){
        this.goalSelector.addGoal(2, new RandomWalkingGoal(this , 1D,1));
        this.goalSelector.addGoal(3, new LookAtGoal(this,PlayerEntity.class,8.0f));
        this.goalSelector.addGoal(3,new MeleeAttackGoal(this,0.3,true));
        this.Target();
    }
    public void Target(){
        this.targetSelector.addGoal(2, (new HurtByTargetGoal(this,new Class[0])).setCallsForHelp(new Class[]{ZombifiedPiglinEntity.class}));
        this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true));
        this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, AbstractVillagerEntity.class, false));
        this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, IronGolemEntity.class, true));
        this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, TurtleEntity.class, 10, true, false, TurtleEntity.TARGET_DRY_BABY));

    }

    @Nullable
    @Override
    public AgeableEntity createChild(ServerWorld serverWorld, AgeableEntity ageableEntity) {
        return null;

    }

}

Link to comment
Share on other sites

report error:

[16:09:34] [Server thread/WARN] [minecraft/EntityType]: Exception loading entity: 
java.lang.NullPointerException: null
    at net.minecraft.entity.ai.attributes.AttributeModifierManager.getAttributeValue(AttributeModifierManager.java:67) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.LivingEntity.getAttributeValue(LivingEntity.java:1849) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.LivingEntity.getMaxHealth(LivingEntity.java:1610) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:209) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.MobEntity.<init>(MobEntity.java:108) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.entity.CreatureEntity.<init>(CreatureEntity.java:13) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.AgeableEntity.<init>(AgeableEntity.java:21) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.passive.AnimalEntity.<init>(AnimalEntity.java:37) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.fsmc.classmates.animals.n7Yjy.<init>(n7Yjy.java:24) ~[main/:?] {re:classloading}
    at net.minecraft.entity.EntityType.create(EntityType.java:448) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.EntityType.lambda$loadEntityUnchecked$1(EntityType.java:459) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_281] {}
    at net.minecraft.entity.EntityType.loadEntityUnchecked(EntityType.java:458) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.EntityType.loadEntity(EntityType.java:516) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.entity.EntityType.loadEntityAndExecute(EntityType.java:498) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.command.impl.SummonCommand.summonEntity(SummonCommand.java:50) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.command.impl.SummonCommand.lambda$register$1(SummonCommand.java:34) ~[forge-1.16.5-36.2.20_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:262) ~[brigadier-1.0.17.jar:?] {re:classloading}
    at net.minecraft.command.Commands.handleCommand(Commands.java:222) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.ServerPlayNetHandler.handleSlashCommand(ServerPlayNetHandler.java:1162) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.ServerPlayNetHandler.func_244548_c(ServerPlayNetHandler.java:1142) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.ServerPlayNetHandler.processChatMessage(ServerPlayNetHandler.java:1121) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.client.CChatMessagePacket.processPacket(CChatMessagePacket.java:40) ~[forge:?] {re:classloading}
    at net.minecraft.network.play.client.CChatMessagePacket.processPacket(CChatMessagePacket.java:8) ~[forge:?] {re:classloading}
    at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[forge:?] {re:classloading}
    at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) ~[forge:?] {re:classloading}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:139) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[forge:?] {re:classloading}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:759) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:159) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:109) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.driveOneInternal(MinecraftServer.java:742) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:736) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.util.concurrent.ThreadTaskExecutor.driveUntil(ThreadTaskExecutor.java:122) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:722) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:668) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:233) ~[forge:?] {re:classloading,pl:accesstransformer:B}
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_281] {}

Link to comment
Share on other sites

I have registered the attributes.

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)

public class AttributesSetEvent {

@SubscribeEvent

public void setup(EntityAttributeCreationEvent event) {

event.put(n7Yjy.n7Yjy,n7Yjy.registerAttributes().create());

}

}

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.