Search in sources :

Example 16 with Vector3d

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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Vector3d(com.enderio.core.common.vecmath.Vector3d) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d)

Example 17 with Vector3d

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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Vector3d(com.enderio.core.common.vecmath.Vector3d) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 18 with Vector3d

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;
}
Also used : Vector2d(com.enderio.core.common.vecmath.Vector2d) Vector3d(com.enderio.core.common.vecmath.Vector3d)

Example 19 with Vector3d

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);
}
Also used : Matrix4d(com.enderio.core.common.vecmath.Matrix4d) Vector3d(com.enderio.core.common.vecmath.Vector3d) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 20 with Vector3d

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);
}
Also used : Vector3d(com.enderio.core.common.vecmath.Vector3d)

Aggregations

Vector3d (com.enderio.core.common.vecmath.Vector3d)35 BoundingBox (com.enderio.core.client.render.BoundingBox)9 EnumFacing (net.minecraft.util.EnumFacing)7 BlockPos (net.minecraft.util.math.BlockPos)7 Nonnull (javax.annotation.Nonnull)6 Vertex (com.enderio.core.common.vecmath.Vertex)4 ArrayList (java.util.ArrayList)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 TileEntity (net.minecraft.tileentity.TileEntity)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3 Vec3d (net.minecraft.util.math.Vec3d)3 VertexRotationFacing (com.enderio.core.client.render.VertexRotationFacing)2 Vector2d (com.enderio.core.common.vecmath.Vector2d)2 Vector4f (com.enderio.core.common.vecmath.Vector4f)2 IBlockState (net.minecraft.block.state.IBlockState)2 Minecraft (net.minecraft.client.Minecraft)2 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2