use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.
the class TravelController method canBlinkTo.
private boolean canBlinkTo(@Nonnull BlockPos bc, @Nonnull World w, @Nonnull Vec3d start, @Nonnull Vec3d target) {
RayTraceResult p = w.rayTraceBlocks(start, target, !Config.travelStaffBlinkThroughClearBlocksEnabled);
if (p != null) {
if (!Config.travelStaffBlinkThroughClearBlocksEnabled) {
return false;
}
IBlockState bs = w.getBlockState(p.getBlockPos());
Block block = bs.getBlock();
if (isClear(w, bs, block, p.getBlockPos())) {
if (BlockCoord.get(p).equals(bc)) {
return true;
}
// need to step
Vector3d sv = new Vector3d(start.x, start.y, start.z);
Vector3d rayDir = new Vector3d(target.x, target.y, target.z);
rayDir.sub(sv);
rayDir.normalize();
rayDir.add(sv);
return canBlinkTo(bc, w, new Vec3d(rayDir.x, rayDir.y, rayDir.z), target);
} else {
return false;
}
}
return true;
}
use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.
the class TravelController method doBlink.
public boolean doBlink(@Nonnull ItemStack equipped, @Nonnull EnumHand hand, @Nonnull EntityPlayer player) {
if (!doesHandAllowBlink(hand)) {
return false;
}
Vector3d eye = Util.getEyePositionEio(player);
Vector3d look = Util.getLookVecEio(player);
Vector3d sample = new Vector3d(look);
sample.scale(Config.travelStaffMaxBlinkDistance);
sample.add(eye);
Vec3d eye3 = new Vec3d(eye.x, eye.y, eye.z);
Vec3d end = new Vec3d(sample.x, sample.y, sample.z);
double playerHeight = player.getYOffset();
// if you looking at you feet, and your player height to the max distance, or part there of
double lookComp = -look.y * playerHeight;
double maxDistance = Config.travelStaffMaxBlinkDistance + lookComp;
RayTraceResult p = player.world.rayTraceBlocks(eye3, end, !Config.travelStaffBlinkThroughClearBlocksEnabled);
if (p == null) {
// go as far as possible
for (double i = maxDistance; i > 1; i--) {
sample.set(look);
sample.scale(i);
sample.add(eye);
// we test against our feets location
sample.y -= playerHeight;
if (doBlinkAround(player, equipped, hand, sample, true)) {
return true;
}
}
return false;
} else {
List<RayTraceResult> res = Util.raytraceAll(player.world, eye3, end, !Config.travelStaffBlinkThroughClearBlocksEnabled);
for (RayTraceResult pos : res) {
if (pos != null) {
IBlockState hitBlock = player.world.getBlockState(pos.getBlockPos());
if (isBlackListedBlock(player, pos, hitBlock)) {
BlockPos bp = pos.getBlockPos();
maxDistance = Math.min(maxDistance, VecmathUtil.distance(eye, new Vector3d(bp.getX() + 0.5, bp.getY() + 0.5, bp.getZ() + 0.5)) - 1.5 - lookComp);
}
}
}
eye3 = new Vec3d(eye.x, eye.y, eye.z);
Vector3d targetBc = new Vector3d(p.getBlockPos());
double sampleDistance = 1.5;
BlockPos bp = p.getBlockPos();
double teleDistance = VecmathUtil.distance(eye, new Vector3d(bp.getX() + 0.5, bp.getY() + 0.5, bp.getZ() + 0.5)) + sampleDistance;
while (teleDistance < maxDistance) {
sample.set(look);
sample.scale(sampleDistance);
sample.add(targetBc);
// we test against our feets location
sample.y -= playerHeight;
if (doBlinkAround(player, equipped, hand, sample, false)) {
return true;
}
teleDistance++;
sampleDistance++;
}
sampleDistance = -0.5;
teleDistance = VecmathUtil.distance(eye, new Vector3d(bp.getX() + 0.5, bp.getY() + 0.5, bp.getZ() + 0.5)) + sampleDistance;
while (teleDistance > 1) {
sample.set(look);
sample.scale(sampleDistance);
sample.add(targetBc);
// we test against our feets location
sample.y -= playerHeight;
if (doBlinkAround(player, equipped, hand, sample, false)) {
return true;
}
sampleDistance--;
teleDistance--;
}
}
return false;
}
use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.
the class TravelController method addRatio.
private double addRatio(@Nonnull BlockPos bc) {
Vector2d sp = currentView.getScreenPoint(new Vector3d(bc.getX() + 0.5, bc.getY() + 0.5, bc.getZ() + 0.5));
Vector2d mid = new Vector2d(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
mid.scale(0.5);
double d = sp.distance(mid);
if (d != d) {
d = 0f;
}
float ratio = (float) d / Minecraft.getMinecraft().displayWidth;
candidates.put(bc, ratio);
return d;
}
use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.
the class TravelController method onRender.
@SubscribeEvent
public void onRender(@Nonnull RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getMinecraft();
Vector3d eye = Util.getEyePositionEio(mc.player);
Vector3d lookAt = Util.getLookVecEio(mc.player);
lookAt.add(eye);
Matrix4d mv = VecmathUtil.createMatrixAsLookAt(eye, lookAt, new Vector3d(0, 1, 0));
float fov = Minecraft.getMinecraft().gameSettings.fovSetting;
Matrix4d pr = VecmathUtil.createProjectionMatrixAsPerspective(fov, 0.05f, mc.gameSettings.renderDistanceChunks * 16, mc.displayWidth, mc.displayHeight);
currentView.setProjectionMatrix(pr);
currentView.setViewMatrix(mv);
currentView.setViewport(0, 0, mc.displayWidth, mc.displayHeight);
fovRad = Math.toRadians(fov);
tanFovRad = Math.tanh(fovRad);
}
use of com.enderio.core.common.vecmath.Vector3d in project EnderIO by SleepyTrousers.
the class TravelController method getDistanceSquared.
private double getDistanceSquared(@Nonnull EntityPlayer player, @Nonnull BlockPos bc) {
Vector3d eye = Util.getEyePositionEio(player);
Vector3d target = new Vector3d(bc.getX() + 0.5, bc.getY() + 0.5, bc.getZ() + 0.5);
return eye.distanceSquared(target);
}
Aggregations