2020-06-14 03:04:21 +00:00
|
|
|
package com.thebrokenrail.twine.entity;
|
|
|
|
|
|
|
|
import com.thebrokenrail.twine.component.StageDataComponent;
|
2020-06-15 21:31:15 +00:00
|
|
|
import com.thebrokenrail.twine.util.StageUtil;
|
2020-06-14 03:04:21 +00:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.ai.goal.FollowTargetGoal;
|
|
|
|
import net.minecraft.entity.mob.Angerable;
|
|
|
|
import net.minecraft.entity.mob.HostileEntity;
|
|
|
|
import net.minecraft.entity.mob.MobEntity;
|
|
|
|
import net.minecraft.entity.passive.PassiveEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.server.world.ServerWorld;
|
2020-06-15 20:29:28 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-06-14 03:04:21 +00:00
|
|
|
|
|
|
|
public class FollowPassiveEntityGoal extends FollowTargetGoal<LivingEntity> {
|
|
|
|
public FollowPassiveEntityGoal(MobEntity mob) {
|
|
|
|
super(mob, LivingEntity.class, 10, false, false, entity -> {
|
|
|
|
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) mob.getEntityWorld());
|
2020-06-15 20:29:28 +00:00
|
|
|
BlockPos pos = mob.getBlockPos();
|
|
|
|
int stage = component.findEffectiveStageOfChunk((ServerWorld) mob.getEntityWorld(), pos);
|
2020-06-14 03:04:21 +00:00
|
|
|
|
2020-06-15 21:31:15 +00:00
|
|
|
return entity instanceof PassiveEntity || (entity instanceof PlayerEntity && stage >= StageUtil.NEUTRAL_MOBS_ARE_HOSTILE);
|
2020-06-14 03:04:21 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canStart() {
|
|
|
|
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) mob.getEntityWorld());
|
2020-06-15 20:29:28 +00:00
|
|
|
BlockPos pos = mob.getBlockPos();
|
|
|
|
int stage = component.findEffectiveStageOfChunk((ServerWorld) mob.getEntityWorld(), pos);
|
2020-06-14 03:04:21 +00:00
|
|
|
|
2020-06-15 21:31:15 +00:00
|
|
|
return mob instanceof HostileEntity && (!(mob instanceof Angerable) || stage >= StageUtil.NEUTRAL_MOBS_ARE_HOSTILE) && stage >= StageUtil.HOSTILE_MOBS_TARGET_PASSIVE_MOBS && super.canStart();
|
2020-06-14 03:04:21 +00:00
|
|
|
}
|
|
|
|
}
|