Isolating aspects of mob AI: Spider's ability to climb. (Weird rotation)

Started by StellaeLux on

Topic category: Help with MCreator software

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Isolating aspects of mob AI: Spider's ability to climb. (Weird rotation)
Wed, 10/30/2019 - 15:32 (edited)

So I was trying to isolate the climbing behaviour that spiders have from other aspects of the spider's behaviour:

Inside of the custom mob element code:

Importing:

import net.minecraft.pathfinding.PathNavigate;
import net.minecraft.pathfinding.PathNavigateClimber;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.entity.monster.EntitySpider;

Inside:

public static class EntityCustom extends EntityMob { }

Paste: 

private static final DataParameter<Byte> CLIMBING = EntityDataManager.<Byte>createKey(EntitySpider.class, DataSerializers.BYTE);

		protected PathNavigate createNavigator(World worldIn)
    {
        return new PathNavigateClimber(this, worldIn);
    }

    protected void entityInit()
    {
        super.entityInit();
        this.dataManager.register(CLIMBING, Byte.valueOf((byte)0));
    }

    public void onUpdate()
    {
        super.onUpdate();

        if (!this.world.isRemote)
        {
            this.setBesideClimbableBlock(this.collidedHorizontally);
        }
    }

    public boolean isBesideClimbableBlock()
    {
        return (((Byte)this.dataManager.get(CLIMBING)).byteValue() & 1) != 0;
    }

    public void setBesideClimbableBlock(boolean climbing)
    {
        byte b0 = ((Byte)this.dataManager.get(CLIMBING)).byteValue();

        if (climbing)
        {
            b0 = (byte)(b0 | 1);
        }
        else
        {
            b0 = (byte)(b0 & -2);
        }

        this.dataManager.set(CLIMBING, Byte.valueOf(b0));
    }

    public boolean isOnLadder()
    {
        return this.isBesideClimbableBlock();
    }

Which will allow your custom entity to be able to climb (without inheriting other aspects of the EntitySpider class), which would be an ideal "can climb" true/false checkbox for people creating a custom mob.. However, there is a tiny issue with pathfinding; Occasionally whenever the mob stand exactly between 4 blocks on the ground it will start to rotate at its current position, until a walking AI task triggers.

Does anyone know what could cause this issue?

Edited by StellaeLux on Wed, 10/30/2019 - 15:32
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You are right. I placed…
Wed, 10/30/2019 - 20:49

You are right. I placed spiders and cave spiders down and the cave spiders also started spinning in circles. Strangely enough, normal spiders wouldn't do so, where as cave-spiders spin just as often as my mob.

Removing:

protected PathNavigate createNavigator(World worldIn)
    {
        return new PathNavigateClimber(this, worldIn);
    }

disables the spinning but also disables climbing.

I hope they improved pathfinding for 1.14. Thanks for the help!

Here: Build: 1.14.4-28.1.72…
Wed, 10/30/2019 - 21:20

Here:

Build: 1.14.4-28.1.72 - Mon Oct 28 21:13:22 GMT 2019
	wynprice999:
		Fixed vanilla bug in entity navigation to stop entities spinning
		(MC-94054) (#6091)