From dd71999fd5d7e631d4c0302043d30cbb9564ae9e Mon Sep 17 00:00:00 2001 From: FatherToast Date: Thu, 23 Jun 2022 09:55:21 -0500 Subject: [PATCH] AI helper + related AT entries --- .../common/entity/ai/AIHelper.java | 35 +++++++++++++++++++ .../entity/creeper/JumpingCreeperEntity.java | 3 +- .../resources/META-INF/accesstransformer.cfg | 4 +++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/fathertoast/specialmobs/common/entity/ai/AIHelper.java diff --git a/src/main/java/fathertoast/specialmobs/common/entity/ai/AIHelper.java b/src/main/java/fathertoast/specialmobs/common/entity/ai/AIHelper.java new file mode 100644 index 0000000..3322dcb --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/entity/ai/AIHelper.java @@ -0,0 +1,35 @@ +package fathertoast.specialmobs.common.entity.ai; + +import net.minecraft.entity.ai.goal.Goal; +import net.minecraft.entity.ai.goal.GoalSelector; +import net.minecraft.entity.ai.goal.PrioritizedGoal; + +import java.util.ArrayList; + +/** + * Provides helper methods for adjusting pre-defined AI goals. + */ +public final class AIHelper { + + /** Inserts an AI goal at the specified priority. Existing goals have their priority adjusted accordingly. */ + public static void insertGoal( GoalSelector ai, int priority, Goal goal ) { + for( PrioritizedGoal task : new ArrayList<>( ai.availableGoals ) ) { + if( task.getPriority() >= priority ) task.priority++; + } + ai.addGoal( priority, goal ); + } + + /** Removes all goals with the specified priority. */ + public static void removeGoals( GoalSelector ai, int priority ) { + for( PrioritizedGoal task : new ArrayList<>( ai.availableGoals ) ) { + if( task.getPriority() == priority ) ai.removeGoal( task.getGoal() ); + } + } + + /** Removes all goals of the specified type. */ + public static void removeGoals( GoalSelector ai, Class goalType ) { + for( PrioritizedGoal task : new ArrayList<>( ai.availableGoals ) ) { + if( task.getGoal().getClass().equals( goalType ) ) ai.removeGoal( task.getGoal() ); + } + } +} \ No newline at end of file diff --git a/src/main/java/fathertoast/specialmobs/common/entity/creeper/JumpingCreeperEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/creeper/JumpingCreeperEntity.java index f8e1e1e..bd8865d 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/creeper/JumpingCreeperEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/creeper/JumpingCreeperEntity.java @@ -2,6 +2,7 @@ package fathertoast.specialmobs.common.entity.creeper; import fathertoast.specialmobs.common.bestiary.BestiaryInfo; import fathertoast.specialmobs.common.bestiary.SpecialMob; +import fathertoast.specialmobs.common.entity.ai.AIHelper; import fathertoast.specialmobs.common.entity.ai.SpecialLeapAtTargetGoal; import fathertoast.specialmobs.common.util.AttributeHelper; import fathertoast.specialmobs.common.util.References; @@ -62,7 +63,7 @@ public class JumpingCreeperEntity extends _SpecialCreeperEntity { /** Override to change this entity's AI goals. */ @Override protected void registerVariantGoals() { - goalSelector.addGoal( 3, new SpecialLeapAtTargetGoal( + AIHelper.insertGoal( goalSelector, 4, new SpecialLeapAtTargetGoal( this, 10, 6.0F, 10.0F, 1.3F, 2.0F ) ); } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 3f62acb..1eb5140 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -5,6 +5,10 @@ public net.minecraft.entity.EntityType field_233593_bg_ # immuneTo public net.minecraft.entity.ai.attributes.AttributeModifierMap$MutableAttribute field_233811_a_ # builder +# AI Goals +public net.minecraft.entity.ai.goal.GoalSelector field_220892_d #availableGoals +public-f net.minecraft.entity.ai.goal.PrioritizedGoal field_220775_b #priority + # Creepers protected net.minecraft.entity.monster.CreeperEntity field_184714_b # DATA_IS_POWERED protected net.minecraft.entity.monster.CreeperEntity field_184715_c # DATA_IS_IGNITED