Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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.

  • Author
11 hours ago, Animefan8888 said:

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.

Ok, thanks.

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.