Dragonfly AI avoid void

This commit is contained in:
paulevsGitch 2020-10-17 08:55:21 +03:00
parent ad2215514f
commit d8ec7ed6b9
3 changed files with 16 additions and 4 deletions

View file

@ -154,13 +154,27 @@ public class EntityDragonfly extends AnimalEntity implements Flutterer {
Vec3d rotation = EntityDragonfly.this.getRotationVec(0.0F); Vec3d rotation = EntityDragonfly.this.getRotationVec(0.0F);
Vec3d airPos = TargetFinder.findAirTarget(EntityDragonfly.this, 8, 7, rotation, 1.5707964F, 2, 1); Vec3d airPos = TargetFinder.findAirTarget(EntityDragonfly.this, 8, 7, rotation, 1.5707964F, 2, 1);
if (airPos != null) { if (airPos != null) {
if (h > 5) { if (isInVoid(airPos)) {
for (int i = 0; i < 8; i++) {
airPos = TargetFinder.findAirTarget(EntityDragonfly.this, 16, 7, rotation, MHelper.PI2, 2, 1);
if (!isInVoid(airPos)) {
return airPos;
}
}
return null;
}
if (h > 5 && airPos.getY() >= EntityDragonfly.this.getBlockPos().getY()) {
airPos = new Vec3d(airPos.x, airPos.y - h * 0.5, airPos.z); airPos = new Vec3d(airPos.x, airPos.y - h * 0.5, airPos.z);
} }
return airPos; return airPos;
} }
return TargetFinder.findGroundTarget(EntityDragonfly.this, 8, 4, -2, rotation, 1.5707963705062866D); return TargetFinder.findGroundTarget(EntityDragonfly.this, 8, 4, -2, rotation, 1.5707963705062866D);
} }
private boolean isInVoid(Vec3d pos) {
int h = BlocksHelper.downRay(EntityDragonfly.this.world, new BlockPos(pos), 128);
return h > 100;
}
} }
@Override @Override

View file

@ -13,7 +13,6 @@ import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.gen.ChunkRandom; import net.minecraft.world.gen.ChunkRandom;
import net.minecraft.world.gen.StructureAccessor; import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.ChunkGenerator;
import ru.betterend.registry.FeatureRegistry; import ru.betterend.registry.FeatureRegistry;
@Mixin(Biome.class) @Mixin(Biome.class)

View file

@ -18,7 +18,6 @@ import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldAccess;
import ru.betterend.blocks.BlockBlueVine; import ru.betterend.blocks.BlockBlueVine;
import ru.betterend.blocks.basis.BlockDoublePlant; import ru.betterend.blocks.basis.BlockDoublePlant;
import ru.betterend.blocks.basis.BlockGlowingFur; import ru.betterend.blocks.basis.BlockGlowingFur;