Posted October 29, 20196 yr When i tried to Override protected void initEntityAI() the game crashes upon entering a world containing my custom entity. The Error is the following : Entity's Vehicle: ~~ERROR~~ NullPointerException: null How do i fix this?
October 30, 20196 yr Author The Crash report is added as a file below, this is the part of the class which causes the crash: @Override protected void initEntityAI() { this.entityAIEatGrass = new EntityAIEatGrass(this); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIPanic(this, 1.25D)); this.tasks.addTask(2, new EntityAIMate(this, 1.0D)); this.tasks.addTask(3, new EntityAITempt(this, 1.1D, Items.WHEAT, false)); this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D)); this.tasks.addTask(5, this.entityAIEatGrass); this.tasks.addTask(6, new EntityAIWanderAvoidWater(this, 1.0D)); this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); //this.targetTasks.addTask(1, new EntityIbex.AIHurtByAggressor(this)); //this.targetTasks.addTask(2, new EntityIbex.AITargetAggressor(this)); } crash-2019-10-30_17.42.26-server.txt
October 30, 20196 yr Author package JophiMa.myst.entity; import javax.annotation.Nullable; import JophiMa.myst.util.handlers.LootTableHandler; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.ai.EntityAIEatGrass; import net.minecraft.entity.ai.EntityAIFollowParent; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMate; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAIPanic; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAITempt; import net.minecraft.entity.ai.EntityAIWanderAvoidWater; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityPigZombie; import net.minecraft.entity.passive.EntitySheep; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.init.SoundEvents; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class EntityIbex extends EntitySheep { private float ageWidth = 0.9F; private float ageHeight = 1.4F; private int angerLevel; private EntityAIEatGrass entityAIEatGrass; public EntityIbex(World worldIn) { super(worldIn); this.setSize(0.9F, 1.4F); this.setSheared(true); } @Override public void eatGrassBonus() { if (this.isChild()) { this.addGrowth(10); } } /*@Override protected void initEntityAI() { this.entityAIEatGrass = new EntityAIEatGrass(this); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIPanic(this, 1.25D)); this.tasks.addTask(2, new EntityAIMate(this, 1.0D)); this.tasks.addTask(3, new EntityAITempt(this, 1.1D, Items.WHEAT, false)); this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D)); this.tasks.addTask(5, this.entityAIEatGrass); this.tasks.addTask(6, new EntityAIWanderAvoidWater(this, 1.0D)); this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); //this.targetTasks.addTask(1, new EntityIbex.AIHurtByAggressor(this)); //this.targetTasks.addTask(2, new EntityIbex.AITargetAggressor(this)); }*/ @Nullable @Override protected ResourceLocation getLootTable() { return LootTableHandler.ENTITIES_IBEX; } @Override public EntitySheep createChild(EntityAgeable ageable) { EntityIbex entityibex1 = new EntityIbex(this.world); entityibex1.setGrowingAge(-40); return entityibex1; } /*private void becomeAngryAt(Entity entity) { this.angerLevel = 400 + this.rand.nextInt(400); if (entity instanceof EntityLivingBase) { this.setRevengeTarget((EntityLivingBase)entity); } } public boolean isAngry() { return this.angerLevel > 0; } static class AIHurtByAggressor extends EntityAIHurtByTarget { public AIHurtByAggressor(EntityIbex entity) { super(entity, true); } protected void setEntityAttackTarget(EntityCreature creatureIn, EntityLivingBase entityLivingBaseIn) { super.setEntityAttackTarget(creatureIn, entityLivingBaseIn); if (creatureIn instanceof EntityIbex) { ((EntityIbex)creatureIn).becomeAngryAt(entityLivingBaseIn); } } } static class AITargetAggressor extends EntityAINearestAttackableTarget<EntityPlayer> { public AITargetAggressor(EntityIbex entity) { super(entity, EntityPlayer.class, true); } /** * Returns whether the EntityAIBase should begin execution. */ /*public boolean shouldExecute() { return ((EntityIbex)this.taskOwner).isAngry() && super.shouldExecute(); } }*/ } Btw the reason that it's identical is because i tried to see if exactly copying the function from the extended class would fix this issue. Sadly, it doesn't. Edited October 30, 20196 yr by diesieben07 syntax highlighting
November 2, 20196 yr Author On 10/30/2019 at 11:31 PM, diesieben07 said: if you override initEntityAI, but don't call super Do you mean super.initEntityAI() ? If i use this, it will still run tasks deleted from the overridden method. Basically, what i'm trying to do is to remove this.tasks.addTask(1, new EntityAIPanic(this, 1.25D)); And have it attack the player instead.
November 4, 20196 yr Author On 11/2/2019 at 8:56 PM, diesieben07 said: To remove a task, first call super to add all the normal tasks, then remove the tasks you dont want from EntityAITasks#taskEntries Both this.tasks.removeTask() and this.tasks.EntityAITasks.remove() don't work with a new instance of the task i want to remove. How do i (or do i need to) get the specific instances?
November 5, 20195 yr Author Using this: for (EntityAITaskEntry task : this.tasks.taskEntries) { if (task.priority == 1) { this.tasks.taskEntries.remove(task); } } causes the entity to not spawn with the following Error Message: [23:55:37] [Server thread/ERROR] [FML]: Encountered an exception while constructing entity 'jmyst:ibex' java.lang.reflect.InvocationTargetException: null at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_211] at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_211] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_211] at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_211] at net.minecraftforge.fml.common.registry.EntityEntryBuilder$ConstructorFactory.apply(EntityEntryBuilder.java:306) [EntityEntryBuilder$ConstructorFactory.class:?] at net.minecraftforge.fml.common.registry.EntityEntryBuilder$ConstructorFactory.apply(EntityEntryBuilder.java:292) [EntityEntryBuilder$ConstructorFactory.class:?] at net.minecraftforge.fml.common.registry.EntityEntry.newInstance(EntityEntry.java:68) [EntityEntry.class:?] at net.minecraft.entity.EntityList.createEntityByIDFromName(EntityList.java:244) [EntityList.class:?] at net.minecraft.item.ItemMonsterPlacer.spawnCreature(ItemMonsterPlacer.java:242) [ItemMonsterPlacer.class:?] at net.minecraft.item.ItemMonsterPlacer.onItemUse(ItemMonsterPlacer.java:98) [ItemMonsterPlacer.class:?] at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:876) [ForgeHooks.class:?] at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:200) [ItemStack.class:?] at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:507) [PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:769) [NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) [CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) [CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) [PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_211] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_211] at net.minecraft.util.Util.runTask(Util.java:53) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_211] Caused by: java.util.ConcurrentModificationException at java.util.LinkedHashMap$LinkedHashIterator.nextNode(Unknown Source) ~[?:1.8.0_211] at java.util.LinkedHashMap$LinkedKeyIterator.next(Unknown Source) ~[?:1.8.0_211]
November 5, 20195 yr You can't modify a collection while you loop over it. That's why its called a ConcurrentModificationException. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.