From 7a543c13a2008f1be8294f924fdea3b8437f27b9 Mon Sep 17 00:00:00 2001 From: ptran779 Date: Sat, 5 Apr 2025 18:30:12 -0500 Subject: [PATCH] change alertHostleGoal: instead of 18 classes enum hardcode, change to 1 unified goal with general enermy class. This allow much greater mod compat for any hostile mod type and cleaner ai goal list. --- forge 1.20.1/gradlew | 0 .../entity/AbstractHumanCompanionEntity.java | 17 +++++++-------- .../humancompanions/entity/CompanionData.java | 21 ------------------- 3 files changed, 7 insertions(+), 31 deletions(-) mode change 100644 => 100755 forge 1.20.1/gradlew diff --git a/forge 1.20.1/gradlew b/forge 1.20.1/gradlew old mode 100644 new mode 100755 diff --git a/forge 1.20.1/src/main/java/com/github/justinwon777/humancompanions/entity/AbstractHumanCompanionEntity.java b/forge 1.20.1/src/main/java/com/github/justinwon777/humancompanions/entity/AbstractHumanCompanionEntity.java index 1071774..df1999f 100644 --- a/forge 1.20.1/src/main/java/com/github/justinwon777/humancompanions/entity/AbstractHumanCompanionEntity.java +++ b/forge 1.20.1/src/main/java/com/github/justinwon777/humancompanions/entity/AbstractHumanCompanionEntity.java @@ -28,6 +28,7 @@ import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; import net.minecraft.world.entity.monster.Creeper; +import net.minecraft.world.entity.monster.Enemy; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.*; import net.minecraft.world.item.enchantment.EnchantmentHelper; @@ -83,7 +84,6 @@ public class AbstractHumanCompanionEntity extends TamableAnimal { public SimpleContainer inventory = new SimpleContainer(27); public EquipmentSlot[] armorTypes = new EquipmentSlot[]{EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.CHEST, EquipmentSlot.HEAD}; - public List alertMobGoals = new ArrayList<>(); public List huntMobGoals = new ArrayList<>(); public PatrolGoal patrolGoal; public MoveBackToPatrolGoal moveBackGoal; @@ -94,6 +94,7 @@ public class AbstractHumanCompanionEntity extends TamableAnimal { private final Map foodRequirements = new HashMap<>(Map.of("", 0)); private String food1 = ""; private String food2 = ""; + private final NearestAttackableTargetGoal alertHostleGoal; // Store the goal public AbstractHumanCompanionEntity(EntityType entityType, Level level) { super(entityType, level); @@ -101,12 +102,12 @@ public AbstractHumanCompanionEntity(EntityType entityTy // this.setCanPickUpLoot(true); ((GroundPathNavigation)this.getNavigation()).setCanOpenDoors(true); this.getNavigation().setCanFloat(true); - for (int i = 0; i < CompanionData.alertMobs.length; i++) { - alertMobGoals.add(new NearestAttackableTargetGoal(this, CompanionData.alertMobs[i], false)); - } for (int i = 0; i < CompanionData.huntMobs.length; i++) { huntMobGoals.add(new NearestAttackableTargetGoal(this, CompanionData.huntMobs[i], false)); } + alertHostleGoal = new NearestAttackableTargetGoal<>(this, LivingEntity.class, true, + entity -> entity instanceof Enemy + ); } @Override @@ -757,15 +758,11 @@ public void setFollowing(boolean following) { } public void addAlertGoals() { - for (NearestAttackableTargetGoal alertMobGoal : alertMobGoals) { - this.targetSelector.addGoal(4, alertMobGoal); - } + this.targetSelector.addGoal(4, alertHostleGoal); } public void removeAlertGoals() { - for (NearestAttackableTargetGoal alertMobGoal : alertMobGoals) { - this.targetSelector.removeGoal(alertMobGoal); - } + this.targetSelector.removeGoal(alertHostleGoal); } public void addHuntingGoals() { diff --git a/forge 1.20.1/src/main/java/com/github/justinwon777/humancompanions/entity/CompanionData.java b/forge 1.20.1/src/main/java/com/github/justinwon777/humancompanions/entity/CompanionData.java index 7ded61a..8980311 100644 --- a/forge 1.20.1/src/main/java/com/github/justinwon777/humancompanions/entity/CompanionData.java +++ b/forge 1.20.1/src/main/java/com/github/justinwon777/humancompanions/entity/CompanionData.java @@ -92,27 +92,6 @@ public class CompanionData { Component.literal("I want something else now."), }; - public static Class[] alertMobs = new Class[]{ - Blaze.class, - EnderMan.class, - Endermite.class, - Ghast.class, - Giant.class, - Guardian.class, - Hoglin.class, - MagmaCube.class, - Phantom.class, - Shulker.class, - Silverfish.class, - Slime.class, - Spider.class, - Vex.class, - AbstractSkeleton.class, - Zoglin.class, - Zombie.class, - Raider.class - }; - public static Class[] huntMobs = new Class[]{ Chicken.class, Cow.class,