Jump to content

Recommended Posts

Posted

I'm new to Forge, but I thought injecting some AI into Villagers would be relatively simple— just create a class that extends Goal, and use targetSelector (or goalSelector).addGoal inside an EntityJoinWorldEvent listener. But during testing, I discovered that all running and available goals are always empty for Villagers. Below is the test code— running near an established Village just returns empty lists.

@SubscribeEvent
public void test(EntityEvent event) {
    if (event.getEntity() instanceof Villager) {
        Villager villager = (Villager) event.getEntity();
        if (villager.goalSelector != null) {
            LOGGER.info("available goals: {}",
                    villager.goalSelector.getAvailableGoals()
                            .stream()
                            .map(goal -> new Object[]{goal.getGoal(), goal.getFlags(), goal.getPriority()})
                            .toList()
            );
            LOGGER.info("current goals: {}",
                    villager.goalSelector.getRunningGoals()
                            .map(goal -> new Object[]{goal.getGoal(), goal.getFlags(), goal.getPriority()})
                            .toList()
            );
        }
        if (villager.targetSelector != null) {
            LOGGER.info("available target goals: {}",
                    villager.targetSelector.getAvailableGoals()
                            .stream()
                            .map(goal -> new Object[]{goal.getGoal(), goal.getFlags(), goal.getPriority()})
                            .toList()
            );

            LOGGER.info("current target goals: {}",
                    villager.targetSelector.getRunningGoals()
                            .map(goal -> new Object[]{goal.getGoal(), goal.getFlags(), goal.getPriority()})
                            .toList()
            );
        }
    }
}

Why is this the case, and how will it affect Goals that I add myself?

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.