Jump to content

[1.12] Minecraft Crashes on entering the world during testing AI


Recommended Posts

Posted

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?

Posted

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

Posted (edited)
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 by diesieben07
syntax highlighting
Posted
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.

Posted
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?

Posted

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]

Posted

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I myself am quite new to the modding scene, I started modding in February but have been in development hell a lot and have struggled to focus on one mod though I have been developing the current mod I've been working on since September and have made a lot of progress; during this time I have found a lot of helpful resources and have learnt a lot of things.    1. You can, I have had no Java experience previously and since modding have managed to be quite knowledgeable in Java.   2. Modding does not require massive teams, I and many others work alone, though having a team is certainly helpful in the modding process to get things done in a quicker and more organised way.   3. I absolutely have to recommend ModdingByKaupenjoe, he makes loads of tutorials for Minecraft from 1.16.5 and above with support for Forge, Fabric, and as of his 1.21 tutorials, Neoforge. These tutorials are really well made, covering almost every modding topic, (such as items, blocks, mobs, worldgen, etc.) and are pretty easy to follow, and Kaupenjoe always leaves the link to his GitHub repositories where you can view the code of that tutorial at your own pace as well as linking textures in the description of his videos for you to use. These forums are also quite good if you need help, though I have found that it sometimes takes a little while for a response but it is always worth the wait; from my experience the people on these forums have always been kind and helpful. There are also user-submitted tutorials that may be helpful as well.  Using GitHub to search up a certain class that you are wanting to use in your mod is also quite helpful, the video I have linked goes into more detail. I would also recommend planning out your mod before you make it to have a clearer idea of how you want your mod to be, including sketches and annotations are also a good idea for this. It has helped me make progress a lot quicker when programming as I already know how I want things to look/act.   I hope all this information helps!
    • I don't know what I did differently, but the error code changed to "Invalid signature for profile public key" so I set "enforce-secure-profile" to false since only my friend will be allowed to join anyway and then everything worked properly. Here's the logs anyway, but I hope the problem doesn't come back. https://paste.ee/p/Ri44L
    • I tried to look for similar issues here on the forum already and couldn't find a fix. Just people who didn't read the rules properly.
  • Topics

×
×
  • Create New...

Important Information

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