This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
Twine/src/main/java/com/thebrokenrail/twine/entity/FollowPassiveEntityGoal.java

33 lines
1.5 KiB
Java
Raw Normal View History

2020-06-14 03:04:21 +00:00
package com.thebrokenrail.twine.entity;
import com.thebrokenrail.twine.component.StageDataComponent;
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
return entity instanceof PassiveEntity || (entity instanceof PlayerEntity && stage >= 4);
});
}
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
return mob instanceof HostileEntity && (!(mob instanceof Angerable) || stage >= 4) && stage >= 2 && super.canStart();
}
}