static bool RayTrace(Game game, Vector3 origin, Vector3 dir, float reach,
                             PickedPos pos, bool clipMode)
        {
            t.SetVectors(origin, dir);
            BlockInfo info    = game.BlockInfo;
            float     reachSq = reach * reach;
            Vector3I  pOrigin = Vector3I.Floor(origin);

            for (int i = 0; i < 10000; i++)
            {
                int x = t.X, y = t.Y, z = t.Z;
                t.Block = GetBlock(game.World, x, y, z, pOrigin);
                Vector3 min = new Vector3(x, y, z) + info.MinBB[t.Block];
                Vector3 max = new Vector3(x, y, z) + info.MaxBB[t.Block];
                if (info.IsLiquid(t.Block))
                {
                    min.Y -= 1.5f / 16; max.Y -= 1.5f / 16;
                }

                float dx = Math.Min(Math.Abs(origin.X - min.X), Math.Abs(origin.X - max.X));
                float dy = Math.Min(Math.Abs(origin.Y - min.Y), Math.Abs(origin.Y - max.Y));
                float dz = Math.Min(Math.Abs(origin.Z - min.Z), Math.Abs(origin.Z - max.Z));
                if (dx * dx + dy * dy + dz * dz > reachSq)
                {
                    return(false);
                }

                t.Min = min; t.Max = max;
                bool intersect = clipMode ? CameraClip(game, pos) : PickBlock(game, pos);
                if (intersect)
                {
                    return(true);
                }
                t.Step();
            }

            throw new InvalidOperationException("did over 10000 iterations in CalculatePickedBlock(). " +
                                                "Something has gone wrong. (dir: " + dir + ")");
        }
Exemple #2
0
 static bool IsHackBlock(BlockID b)
 {
     return(b == Block.DoubleSlab || b == Block.Bedrock ||
            b == Block.Grass || BlockInfo.IsLiquid(b));
 }