Posted April 18, 20205 yr 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
April 18, 20205 yr 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.
April 19, 20205 yr 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.
April 19, 20205 yr 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
April 19, 20205 yr 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 April 19, 20205 yr 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.