Skip to content

Commit

Permalink
Merge pull request #101 from demonlexe/96-tamed-hunter-mobs-still-att…
Browse files Browse the repository at this point in the history
…ack-owners

96 - Tamed Mobs using `EntityAIHunt` should not initiate Player hunting behavior
  • Loading branch information
ACGaming authored Jan 1, 2024
2 parents dd51d35 + 5858284 commit dc9d723
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@

import com.google.common.base.Predicate;
import drzhark.mocreatures.entity.MoCEntityAnimal;
import drzhark.mocreatures.entity.tameable.MoCEntityTameableAnimal;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.player.EntityPlayer;

public class EntityAIHunt<T extends EntityLivingBase> extends EntityAINearestAttackableTarget<T> {

private final EntityCreature hunter;
private final Class<T> targetClass;

public EntityAIHunt(EntityCreature entity, Class<T> classTarget, int chance, boolean checkSight, boolean onlyNearby, Predicate<EntityLivingBase> predicate) {
super(entity, classTarget, chance, checkSight, onlyNearby, predicate);
this.hunter = entity;
this.targetClass = classTarget;
}

public EntityAIHunt(EntityCreature entityCreature, Class<T> classTarget, boolean checkSight) {
Expand All @@ -29,6 +33,9 @@ public EntityAIHunt(EntityCreature entity, Class<T> classTarget, boolean checkSi

@Override
public boolean shouldExecute() {
return ((MoCEntityAnimal) this.hunter).getIsHunting() && super.shouldExecute();
// Conditions: Don't hunt when tamed and target entity is of class Player
boolean hunterHasOwner = ((MoCEntityTameableAnimal)this.hunter).getIsTamed();
boolean hunterTargetsPlayers = EntityPlayer.class.isAssignableFrom(this.targetClass);
return (!hunterTargetsPlayers || !hunterHasOwner) && ((MoCEntityAnimal) this.hunter).getIsHunting() && super.shouldExecute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import drzhark.mocreatures.MoCreatures;
import drzhark.mocreatures.entity.MoCEntityAquatic;
import drzhark.mocreatures.entity.ai.EntityAIHunt;
import drzhark.mocreatures.entity.ai.EntityAIWanderMoC2;
import drzhark.mocreatures.entity.item.MoCEntityEgg;
import drzhark.mocreatures.entity.passive.MoCEntityHorse;
Expand Down Expand Up @@ -44,7 +45,7 @@ protected void initEntityAI() {
this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false));
this.tasks.addTask(5, new EntityAIWanderMoC2(this, 1.0D, 30));
this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget<>(this, EntityPlayer.class, false));
this.targetTasks.addTask(3, new EntityAIHunt<>(this, EntityPlayer.class, false));
}

@Override
Expand Down

0 comments on commit dc9d723

Please sign in to comment.