Improved following behaviour of fairies

This commit is contained in:
Sollace 2021-12-27 13:45:44 +02:00
parent 135c8933fd
commit 7ec631ddcd

View file

@ -19,6 +19,7 @@ import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.ai.goal.WanderAroundGoal; import net.minecraft.entity.ai.goal.WanderAroundGoal;
import net.minecraft.entity.ai.pathing.BirdNavigation; import net.minecraft.entity.ai.pathing.BirdNavigation;
import net.minecraft.entity.ai.pathing.EntityNavigation; import net.minecraft.entity.ai.pathing.EntityNavigation;
import net.minecraft.entity.ai.pathing.Path;
import net.minecraft.entity.ai.pathing.PathNodeType; import net.minecraft.entity.ai.pathing.PathNodeType;
import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.attribute.EntityAttributes;
@ -128,7 +129,7 @@ public class FairyEntity extends PathAwareEntity implements LightEmittingEntity,
@Override @Override
public void tick() { public void tick() {
this.onGround = true; onGround = true;
super.tick(); super.tick();
emitter.tick(); emitter.tick();
@ -261,13 +262,40 @@ public class FairyEntity extends PathAwareEntity implements LightEmittingEntity,
getLookControl().lookAt(target, 10, getMaxLookPitchChange()); getLookControl().lookAt(target, 10, getMaxLookPitchChange());
Path currentPath = getNavigation().getCurrentPath();
if (currentPath != null && target.getEyeY() < getY() - 0.5 && world.getBlockState(getBlockPos().down(3)).isAir()) {
addVelocity(0, -speed, 0);
}
double distance = getPos().squaredDistanceTo(target.getPos());
double speed = this.speed;
if (distance > 100) {
teleport(
target.getX() + world.random.nextFloat() / 2F - 0.5F,
target.getEyeY(),
target.getZ() + world.random.nextFloat() / 2F - 0.5F
);
setVelocity(target.getVelocity());
return;
} else if (distance > 40) {
speed *= 10;
} else if (distance > 25) {
speed *= 4;
} else if (distance > 8) {
speed *= 2;
}
getNavigation().setSpeed(speed);
if (--updateCountdownTicks > 0) { if (--updateCountdownTicks > 0) {
return; return;
} }
updateCountdownTicks = getTickCount(10); updateCountdownTicks = getTickCount(10);
if (getPos().squaredDistanceTo(target.getPos()) <= minDistance * minDistance) { if (distance <= minDistance * minDistance) {
BlockPos pos = FuzzyPositions.localFuzz(FairyEntity.this.world.random, 5, 5); BlockPos pos = FuzzyPositions.localFuzz(FairyEntity.this.world.random, 5, 5);
if (pos != null) { if (pos != null) {
@ -310,7 +338,7 @@ public class FairyEntity extends PathAwareEntity implements LightEmittingEntity,
@Override @Override
public void tick() { public void tick() {
if (--updateCountdownTicks > 0) { if (--updateCountdownTicks > 0 || !isStaying()) {
return; return;
} }