Jump to content

1.16.5 How to register entity ai?


henzo800

Recommended Posts

Hi again, I'm trying to create a custom living entity but I keep running into this issue that causes a crash due to a ticking entity.

Crash:

[12:31:15] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraft.crash.ReportedException: Ticking entity
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:855) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:787) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.tickServer(IntegratedServer.java:78) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:642) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:232) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_282] {}
Caused by: java.lang.NullPointerException
	at net.minecraft.entity.LivingEntity.travel(LivingEntity.java:1905) ~[forge:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.aiStep(LivingEntity.java:2449) ~[forge:?] {re:classloading}
	at net.minecraft.entity.MobEntity.aiStep(MobEntity.java:488) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.AgeableEntity.aiStep(AgeableEntity.java:115) ~[forge:?] {re:classloading}
	at net.minecraft.entity.passive.AnimalEntity.aiStep(AnimalEntity.java:51) ~[forge:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.tick(LivingEntity.java:2158) ~[forge:?] {re:classloading}
	at net.minecraft.entity.MobEntity.tick(MobEntity.java:300) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tickNonPassenger(ServerWorld.java:611) ~[forge:?] {re:classloading}
	at net.minecraft.world.World.guardEntityTick(World.java:554) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:404) ~[forge:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:851) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	... 5 more
AL lib: (EE) alc_cleanup: 1 device not closed

 It seems to be that I have not defined an ai/brain but I have no idea how to do this. I cant seem to see any event to do this in the library. 

Any help would be greatly appreciated.

Link to comment
Share on other sites

Ok, so I seem to have registered goals for the entity but I still have the problem that whenever I spawn it the game crashes. Here is my entity class so far.

public class TestEntity extends CowEntity {

	public static final String REG = "simple_entity";
	public static final EntityType<TestEntity> TYPE = //Entity type builder
	public static final AttributeModifierMap MAP = //Entity Attribute builder
	
	public TestEntity(EntityType<? extends CowEntity> p_i48567_1_, World p_i48567_2_) {
		super(p_i48567_1_, p_i48567_2_);
		Main.LOGGER.debug("STAR - Entity Constructed");
		this.setNoGravity(false);
	}
  
	@Override
	protected void registerGoals() {
		super.registerGoals();
		Main.LOGGER.debug("STAR - Entity Goals");
		this.goalSelector.addGoal(0, new TemptGoal(this, 1.25D, Ingredient.of(Items.WHEAT), false));
	}
}	

Any ideas why this error is still occurring.

Link to comment
Share on other sites

I used diesieben07 suggestion and got it all working.

I have included my completed entity for anyone who needs it.

Entity Class:

public class TestEntity extends CowEntity {

	public static final String REG = "simple_entity";

	public TestEntity(EntityType<? extends CowEntity> p_i48567_1_, World p_i48567_2_) {
		super(p_i48567_1_, p_i48567_2_);
		STAR.LOGGER.debug("STAR - Entity Constructed");
	}
	
	public static AttributeModifierMap.MutableAttribute createAttributes() {
	      return MobEntity.createMobAttributes().add(Attributes.MAX_HEALTH, 0.5D)
	    		  .add(Attributes.MOVEMENT_SPEED, (double)0.2F)
	    		  .add(Attributes.FOLLOW_RANGE, 20.0)
	    		  .add(Attributes.ATTACK_DAMAGE, 20.0);
	}
	
	@Override
	protected void registerGoals() {
		STAR.LOGGER.debug("STAR - Entity Goals");
		this.goalSelector.addGoal(0, new TemptGoal(this, 1.25D, Ingredient.of(Items.WHEAT), false));
	}
	
}	

Entity register:

public class EntityRegister {
	public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, STAR.MODID);

	public static final RegistryObject<EntityType<TestEntity>> TESTENTITY = ENTITIES.register(TestEntity.REG, () -> EntityType.Builder.<TestEntity>of(TestEntity::new, EntityClassification.MISC)
			.sized(0.98F, 0.7F)
			.clientTrackingRange(8)
			.build(TestEntity.REG));
 }

Thanks for all your help.

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.



×
×
  • Create New...

Important Information

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