Jump to content

[Solved] Disable entity ai


Flemmli97
 Share

Recommended Posts

Im trying to disable an entities ai under certain circumstances. As of now i tried to do it with potions. i do not want to do entity#setNoAI as that also disables general movement of it (means it floats in midair and stuff).

EntityLiving#tasks has a control flag but due to call order even if i set it in my potion it gets cancelled (or maybe i did it wrong). Is there any way to disable the execution of the ai from an entity?

 

This is my current potion class:

Spoiler

package com.flemmli97.runecraftory.common.potion;

import com.flemmli97.runecraftory.common.lib.LibReference;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.attributes.AbstractAttributeMap;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;

public class PotionSleep extends Potion{
	
	public PotionSleep() {
		super(true, 0);
		this.setPotionName("sleep");
		this.setRegistryName(new ResourceLocation(LibReference.MODID, "sleep"));
	}

    public void removeAttributesModifiersFromEntity(EntityLivingBase entity, AbstractAttributeMap attributeMapIn, int amplifier)
    {
		if(entity instanceof EntityLiving)
		{
			//((EntityLiving)entity).tasks.setControlFlag(1, false);
			//((EntityLiving)entity).tasks.setControlFlag(4, false);
			//((EntityLiving)entity).tasks.setControlFlag(8, false);
		}
        		//((EntityLiving)entityLivingBaseIn).setNoAI(false);        	
        super.removeAttributesModifiersFromEntity(entity, attributeMapIn, amplifier);
    }
    
    public boolean isReady(int duration, int amplifier)
    {
    	return true;
    }
    
    @Override
    public void performEffect(EntityLivingBase entity, int amplifier)
    {
		if(entity instanceof EntityLiving)
		{
			//For testing
			//((EntityLiving)entity).tasks.setControlFlag(1, true);
			//((EntityLiving)entity).tasks.setControlFlag(4, true);
			//((EntityLiving)entity).tasks.setControlFlag(2, true);
			//this should disable all entity ai
			((EntityLiving)entity).tasks.setControlFlag(8, true);
			((EntityLiving)entity).targetTasks.setControlFlag(8, true);

		}
    }

    public void applyAttributesModifiersToEntity(EntityLivingBase entity, AbstractAttributeMap attributeMapIn, int amplifier)
    {
    	//((EntityLiving)entity).tasks
			//((EntityLiving)entity).setNoAI(true);
        super.applyAttributesModifiersToEntity(entity, attributeMapIn, amplifier);
    }
}

 

 

Edited by Flemmli97
Link to comment
Share on other sites

I would create a new task, add it with priority 0, and have it use a mutex flag value of 0xFFFFFF.

 

That would prevent other tasks from running.

Edited by Draco18s

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.

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 Terms of Use.