forked from LtxProgrammer/Changed-Minecraft-Mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tame check for target selector test.
- Loading branch information
1 parent
d99fbc9
commit 8be5132
Showing
4 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/net/ltxprogrammer/changed/entity/TamableLatexEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
package net.ltxprogrammer.changed.entity; | ||
|
||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.OwnableEntity; | ||
import net.minecraft.world.entity.TamableAnimal; | ||
import net.minecraft.world.entity.animal.Wolf; | ||
import net.minecraft.world.entity.animal.horse.AbstractHorse; | ||
import net.minecraft.world.entity.monster.Creeper; | ||
import net.minecraft.world.entity.monster.Ghast; | ||
import net.minecraft.world.entity.player.Player; | ||
|
||
public interface TamableLatexEntity extends OwnableEntity { | ||
boolean isFollowingOwner(); | ||
void setFollowOwner(boolean value); | ||
|
||
default boolean isTame() { | ||
return this.getOwner() != null; | ||
} | ||
|
||
default boolean wantsToAttack(LivingEntity target, LivingEntity owner) { | ||
if (!(target instanceof Creeper) && !(target instanceof Ghast)) { | ||
if (target instanceof TamableLatexEntity tamable) { | ||
return !tamable.isTame() || tamable.getOwner() != owner; | ||
} else if (target instanceof Player && owner instanceof Player && !((Player)owner).canHarmPlayer((Player)target)) { | ||
return false; | ||
} else if (target instanceof AbstractHorse && ((AbstractHorse)target).isTamed()) { | ||
return false; | ||
} else { | ||
return !(target instanceof TamableAnimal) || !((TamableAnimal)target).isTame(); | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/net/ltxprogrammer/changed/entity/ai/LatexOwnerHurtByTargetGoal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package net.ltxprogrammer.changed.entity.ai; | ||
|
||
import net.ltxprogrammer.changed.entity.ChangedEntity; | ||
import net.ltxprogrammer.changed.entity.TamableLatexEntity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.TamableAnimal; | ||
import net.minecraft.world.entity.ai.goal.target.TargetGoal; | ||
import net.minecraft.world.entity.ai.targeting.TargetingConditions; | ||
|
||
import java.util.EnumSet; | ||
|
||
public class LatexOwnerHurtByTargetGoal<T extends ChangedEntity & TamableLatexEntity> extends TargetGoal { | ||
private final T tameAnimal; | ||
private LivingEntity ownerLastHurtBy; | ||
private int timestamp; | ||
|
||
public LatexOwnerHurtByTargetGoal(T p_26107_) { | ||
super(p_26107_, false); | ||
this.tameAnimal = p_26107_; | ||
this.setFlags(EnumSet.of(Flag.TARGET)); | ||
} | ||
|
||
public boolean canUse() { | ||
if (this.tameAnimal.isTame()) { | ||
if (!(this.tameAnimal.getOwner() instanceof LivingEntity livingentity)) { | ||
return false; | ||
} else { | ||
this.ownerLastHurtBy = livingentity.getLastHurtByMob(); | ||
int i = livingentity.getLastHurtByMobTimestamp(); | ||
return i != this.timestamp && this.canAttack(this.ownerLastHurtBy, TargetingConditions.DEFAULT) && this.tameAnimal.wantsToAttack(this.ownerLastHurtBy, livingentity); | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public void start() { | ||
this.mob.setTarget(this.ownerLastHurtBy); | ||
if (this.tameAnimal.getOwner() instanceof LivingEntity livingentity) { | ||
this.timestamp = livingentity.getLastHurtByMobTimestamp(); | ||
} | ||
|
||
super.start(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/net/ltxprogrammer/changed/entity/ai/LatexOwnerHurtTargetGoal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.ltxprogrammer.changed.entity.ai; | ||
|
||
import net.ltxprogrammer.changed.entity.ChangedEntity; | ||
import net.ltxprogrammer.changed.entity.TamableLatexEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.TamableAnimal; | ||
import net.minecraft.world.entity.ai.goal.Goal; | ||
import net.minecraft.world.entity.ai.goal.target.TargetGoal; | ||
import net.minecraft.world.entity.ai.navigation.FlyingPathNavigation; | ||
import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; | ||
import net.minecraft.world.entity.ai.navigation.PathNavigation; | ||
import net.minecraft.world.entity.ai.targeting.TargetingConditions; | ||
import net.minecraft.world.level.LevelReader; | ||
import net.minecraft.world.level.block.LeavesBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.pathfinder.BlockPathTypes; | ||
import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; | ||
|
||
import java.util.EnumSet; | ||
|
||
public class LatexOwnerHurtTargetGoal<T extends ChangedEntity & TamableLatexEntity> extends TargetGoal { | ||
private final T tameAnimal; | ||
private LivingEntity ownerLastHurt; | ||
private int timestamp; | ||
|
||
public LatexOwnerHurtTargetGoal(T p_26114_) { | ||
super(p_26114_, false); | ||
this.tameAnimal = p_26114_; | ||
this.setFlags(EnumSet.of(Flag.TARGET)); | ||
} | ||
|
||
public boolean canUse() { | ||
if (this.tameAnimal.isTame()) { | ||
if (!(this.tameAnimal.getOwner() instanceof LivingEntity livingentity)) { | ||
return false; | ||
} else { | ||
this.ownerLastHurt = livingentity.getLastHurtMob(); | ||
int i = livingentity.getLastHurtMobTimestamp(); | ||
return i != this.timestamp && this.canAttack(this.ownerLastHurt, TargetingConditions.DEFAULT) && this.tameAnimal.wantsToAttack(this.ownerLastHurt, livingentity); | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public void start() { | ||
this.mob.setTarget(this.ownerLastHurt); | ||
if (this.tameAnimal.getOwner() instanceof LivingEntity livingentity) { | ||
this.timestamp = livingentity.getLastHurtMobTimestamp(); | ||
} | ||
|
||
super.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters