Exemple #1
0
        public void CmdShape(int groupId, CmdArgs args)
        {
            BlockPos pos       = capi.World.Player.CurrentBlockSelection?.Position ?? capi.World.Player.Entity.Pos.AsBlockPos;
            string   arg       = args.PopWord();
            int      radius    = (int)args.PopInt(4);
            int      thickness = (int)args.PopInt(1);
            int      attach    = (bool)args.PopBool(false) ? radius + 1 : 0;

            switch (arg)
            {
            case "sphere":
                for (int x = -radius; x <= radius; x++)
                {
                    for (int y = -radius; y <= radius; y++)
                    {
                        for (int z = -radius; z <= radius; z++)
                        {
                            BlockPos iPos = new BlockPos(pos.X + x, pos.Y + y + attach, pos.Z + z);
                            int      r    = x * x + y * y + z * z;

                            if (r <= (radius * radius) && r > (radius - thickness) * (radius - thickness) && iPos.Y > 0)
                            {
                                highlighted.Add(iPos);
                            }
                        }
                    }
                }
                MakeHighlights(highlighted);
                break;

            case "dome":
                for (int x = -radius; x <= radius; x++)
                {
                    for (int y = -radius; y <= radius; y++)
                    {
                        for (int z = -radius; z <= radius; z++)
                        {
                            if (y < 0)
                            {
                                continue;
                            }
                            BlockPos iPos = new BlockPos(pos.X + x, pos.Y + y + attach, pos.Z + z);
                            int      r    = x * x + y * y + z * z;

                            if (r <= (radius * radius) && r > (radius - thickness) * (radius - thickness) && iPos.Y > 0)
                            {
                                highlighted.Add(iPos);
                            }
                        }
                    }
                }
                MakeHighlights(highlighted);
                break;

            case "cube":
                for (int x = -radius; x <= radius; x++)
                {
                    for (int y = -radius; y <= radius; y++)
                    {
                        for (int z = -radius; z <= radius; z++)
                        {
                            int r = thickness;
                            if (x < r && y < r && z < r && x > -r && y > -r && z > -r)
                            {
                                continue;
                            }
                            BlockPos iPos = new BlockPos(pos.X + x, pos.Y + y + attach - 1, pos.Z + z);
                            if (iPos.Y > 0)
                            {
                                highlighted.Add(iPos);
                            }
                        }
                    }
                }
                MakeHighlights(highlighted);
                break;

            case "path":
                WaypointUtilSystem wUtil = capi.ModLoader.GetModSystem <WaypointUtilSystem>();
                if (radius > wUtil.Waypoints.Count || thickness > wUtil.Waypoints.Count)
                {
                    break;
                }
                BlockPos wp1Pos = wUtil.Waypoints[radius]?.Position?.AsBlockPos, wp2Pos = wUtil.Waypoints[thickness]?.Position?.AsBlockPos;
                if (wp1Pos != null && wp2Pos != null)
                {
                    highlighted = new HashSet <BlockPos>(highlighted.Concat(PlotLine3d(wp1Pos, wp2Pos)));
                }
                MakeHighlights(highlighted);
                break;

            case "circle":
                for (int x = -radius; x <= radius; x++)
                {
                    for (int z = -radius; z <= radius; z++)
                    {
                        BlockPos iPos = new BlockPos(pos.X + x, pos.Y, pos.Z + z);
                        int      r    = x * x + z * z;
                        if (r <= (radius * radius) && r > (radius - thickness) * (radius - thickness) && iPos.Y > 0)
                        {
                            highlighted.Add(iPos);
                        }
                    }
                }
                MakeHighlights(highlighted);
                break;

            case "extrude":
                var tmp = new HashSet <BlockPos>();
                var dir = thickness == 0 ? new Vec3i(0, 1, 0) : thickness == 1 ? new Vec3i(1, 0, 0) : thickness == 2 ? new Vec3i(0, 0, 1) : thickness == 3 ? new Vec3i(1, 1, 1) : new Vec3i(0, 0, 0);
                foreach (var val in highlighted)
                {
                    for (int i = 0; i < radius; i++)
                    {
                        tmp.Add(val.AddCopy(dir * i));
                    }
                }
                highlighted = new HashSet <BlockPos>(highlighted.Concat(tmp).ToList());
                MakeHighlights(highlighted);
                break;

            case "toflatten":
                HashSet <BlockPos> temp = new HashSet <BlockPos>(highlighted);
                foreach (var val in highlighted)
                {
                    if (capi.World.BlockAccessor.GetBlock(val).Id == 0)
                    {
                        temp.Remove(val);
                    }
                }
                highlighted = temp;
                MakeHighlights(highlighted);
                break;

            case "save":
                using (TextWriter tw = new StreamWriter("shape" + radius + ".json"))
                {
                    tw.Write(JsonConvert.SerializeObject(highlighted, Formatting.None));
                    tw.Close();
                }
                break;

            case "load":
                using (TextReader tr = new StreamReader("shape" + radius + ".json"))
                {
                    highlighted = JsonConvert.DeserializeObject <HashSet <BlockPos> >(tr.ReadToEnd());
                    tr.Close();
                }
                MakeHighlights(highlighted);
                break;

            case "clear":
                capi.World.HighlightBlocks(capi.World.Player, 514, new List <BlockPos>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Cubes);
                highlighted.Clear();
                break;

            default:
                break;
            }
        }
Exemple #2
0
        public void CmdMeasuringTape(int groupId, CmdArgs args)
        {
            WaypointUtilSystem wUtil = capi.ModLoader.GetModSystem <WaypointUtilSystem>();
            string             arg   = args.PopWord();

            switch (arg)
            {
            case "start":
                if (capi.World.Player.CurrentBlockSelection != null)
                {
                    start = capi.World.Player.CurrentBlockSelection.Position;
                    //capi.ShowChatMessage("Okay, start set to: " + start);
                    MakeHighlights();
                }
                else
                {
                    capi.ShowChatMessage("Please look at a block.");
                }
                break;

            case "end":
                if (capi.World.Player.CurrentBlockSelection != null)
                {
                    end = capi.World.Player.CurrentBlockSelection.Position;
                    //capi.ShowChatMessage("Okay, end set to: " + end);
                    MakeHighlights();
                }
                else
                {
                    capi.ShowChatMessage("Please look at a block.");
                }
                break;

            case "startwp":
                int?swpID = args.PopInt();
                if (swpID != null)
                {
                    start = wUtil.Waypoints[(int)swpID].Position.AsBlockPos;
                    MakeHighlights();
                }
                else
                {
                    capi.ShowChatMessage("Please enter a waypoint id.");
                }
                break;

            case "endwp":
                int?ewpID = args.PopInt();
                if (ewpID != null)
                {
                    end = wUtil.Waypoints[(int)ewpID].Position.AsBlockPos;
                    MakeHighlights();
                }
                else
                {
                    capi.ShowChatMessage("Please enter a waypoint id.");
                }
                break;

            case "calc":
                string type = args.PopWord();
                switch (type)
                {
                case "block":
                    capi.ShowChatMessage("Block Distance: " + Math.Round(start.DistanceTo(end) + 1));
                    break;

                case "euclidian":
                    capi.ShowChatMessage("Euclidian Distance: " + start.DistanceTo(end));
                    break;

                case "manhattan":
                    capi.ShowChatMessage("Manhattan Distance: " + start.ManhattenDistance(end));
                    break;

                case "horizontal":
                    capi.ShowChatMessage("Horizontal Distance: " + Math.Sqrt(start.HorDistanceSqTo(end.X, end.Z)));
                    break;

                case "horizontalmanhattan":
                    capi.ShowChatMessage("Horizontal Manhattan Distance: " + start.HorizontalManhattenDistance(end));
                    break;

                default:
                    capi.ShowChatMessage("Syntax: .measure calc [block|euclidian|manhattan|horizontal|horizontalmanhattan]");
                    break;
                }
                break;

            default:
                capi.ShowChatMessage("Syntax: .measure [start|end|calc]");
                break;
            }
        }