Jump to content

Recommended Posts

Posted

I am trying to remove the AvoidEntity goals for a creeper to make it not run away from ocelots. This is my code:

 

@Mod.EventBusSubscriber(modid = CreeperMod.MODID)
public class EntityChangeEvent {

    @SubscribeEvent
    public static void onSpawn(EntityJoinWorldEvent event) {
        if (event.getEntity() instanceof CreeperEntity) changeAI((CreeperEntity) event.getEntity(), event);
    }
	
	private static void changeAI(CreeperEntity entity) {
        if (entity.world != null && !entity.world.isRemote) {
            CreeperMod.LOGGER.info(entity.goalSelector.getRunningGoals().count());
            entity.goalSelector.getRunningGoals().forEach((action) -> {
                CreeperMod.LOGGER.info(action.getGoal());
                if (action.getGoal() instanceof AvoidEntityGoal) {
                    entity.goalSelector.removeGoal(action.getGoal());
                    CreeperMod.LOGGER.info("removed");
                }
            });
        }
    }

But it looks like the AvoidEntity goals are not running when the creeper is spawned. How would I remove those goals. Thanks

Posted
3 hours ago, TheBigCraftGuy said:

changeAI((CreeperEntity) event.getEntity(), event);

This doesn't even compile.

3 hours ago, TheBigCraftGuy said:

But it looks like the AvoidEntity goals are not running when the creeper is spawned. How would I remove those goals. Thanks

The goal is only running when there is an OcelotEntity or a CatEntity nearby. You have to use Reflection to get the Goal out of the GoalSelector.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

This is my code so far but it doesn't seem to work

private static void changeAI(CreeperEntity entity) {
        if (entity.world != null && !entity.world.isRemote) {
            Set<PrioritizedGoal> goals = ObfuscationReflectionHelper.getPrivateValue(GoalSelector.class, entity.goalSelector, "goals");
            ChangeMod.LOGGER.info(goals);
            for (PrioritizedGoal goal: goals) {
                if (goal.getGoal() instanceof AvoidEntityGoal) {
                    entity.goalSelector.removeGoal(goal);
                    ChangeMod.LOGGER.info(goal.getGoal().toString());
                }
            }
            goals = ObfuscationReflectionHelper.getPrivateValue(GoalSelector.class, entity.goalSelector, "goals");
            ChangeMod.LOGGER.info(goals);
        }
    }

But the creepers still avoid them and the goals are the same length

Posted (edited)
3 hours ago, TheBigCraftGuy said:

entity.goalSelector.removeGoal(goal);

It should be goal.getGoal()

 

Also you cannot iterate and remove an entry. You will get a ConcurrentModificationException. Use an iterator.

Edited by Animefan8888

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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



×
×
  • Create New...

Important Information

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