Exemplo n.º 1
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            if (Options.ContainsKey("undo"))
            {
                SendOutput("Please use the bc-undo command to undo changes");

                return;
            }

            var    pos1 = new Vector3i(int.MinValue, 0, int.MinValue);
            var    pos2 = new Vector3i(int.MinValue, 0, int.MinValue);
            string blockname;
            string blockname2 = null;

            //get loc and player current pos
            EntityPlayer sender  = null;
            string       steamId = null;

            if (SenderInfo.RemoteClientInfo != null)
            {
                steamId = SenderInfo.RemoteClientInfo.ownerId;
                sender  = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
                if (sender != null)
                {
                    pos2 = new Vector3i((int)Math.Floor(sender.serverPos.x / 32f), (int)Math.Floor(sender.serverPos.y / 32f), (int)Math.Floor(sender.serverPos.z / 32f));
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
            }

            switch (Params.Count)
            {
            case 2:
            case 3:
                if (steamId != null)
                {
                    pos1 = BCLocation.GetPos(steamId);
                    if (pos1.x == int.MinValue)
                    {
                        SendOutput("No location stored. Use bc-loc to store a location.");

                        return;
                    }

                    blockname = Params[1];
                    if (Params.Count == 3)
                    {
                        blockname2 = Params[2];
                    }
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
                break;

            case 8:
            case 9:
                //parse params
                if (!int.TryParse(Params[1], out pos1.x) || !int.TryParse(Params[2], out pos1.y) || !int.TryParse(Params[3], out pos1.z) || !int.TryParse(Params[4], out pos2.x) || !int.TryParse(Params[5], out pos2.y) || !int.TryParse(Params[6], out pos2.z))
                {
                    SendOutput("Error: unable to parse coordinates");

                    return;
                }
                blockname = Params[7];
                if (Params.Count == 9)
                {
                    blockname2 = Params[8];
                }
                break;

            default:
                SendOutput("Error: Incorrect command format.");
                SendOutput(GetHelp());

                return;
            }

            var size = BCUtils.GetSize(pos1, pos2);

            var position = new Vector3i(
                pos1.x < pos2.x ? pos1.x : pos2.x,
                pos1.y < pos2.y ? pos1.y : pos2.y,
                pos1.z < pos2.z ? pos1.z : pos2.z
                );

            //**************** GET BLOCKVALUE
            var bvNew = int.TryParse(blockname, out var blockId) ? Block.GetBlockValue(blockId) : Block.GetBlockValue(blockname);

            var modifiedChunks = BCUtils.GetAffectedChunks(new BCMCmdArea("Blocks")
            {
                Position = new BCMVector3(position),
                Size     = new BCMVector3(size),
                HasPos   = true,
                HasSize  = true,

                ChunkBounds = new BCMVector4
                {
                    x = World.toChunkXZ(position.x),
                    y = World.toChunkXZ(position.z),
                    z = World.toChunkXZ(position.x + size.x - 1),
                    w = World.toChunkXZ(position.z + size.z - 1)
                },
                HasChunkPos = true
            }, world);

            //CREATE UNDO
            //create backup of area blocks will insert to
            if (!Options.ContainsKey("noundo"))
            {
                BCUtils.CreateUndo(sender, position, size);
            }

            switch (Params[0])
            {
            case "scan":
                ScanBlocks(position, size, bvNew, blockname);
                break;

            case "fill":
                FillBlocks(position, size, bvNew, blockname, modifiedChunks);
                break;

            case "swap":
                SwapBlocks(position, size, bvNew, blockname2, modifiedChunks);
                break;

            case "repair":
                RepairBlocks(position, size, modifiedChunks);
                break;

            case "damage":
                DamageBlocks(position, size, modifiedChunks);
                break;

            case "upgrade":
                UpgradeBlocks(position, size, modifiedChunks);
                break;

            case "downgrade":
                DowngradeBlocks(position, size, modifiedChunks);
                break;

            case "paint":
                SetPaint(position, size, modifiedChunks);
                break;

            case "paintface":
                SetPaintFace(position, size, modifiedChunks);
                break;

            case "paintstrip":
                RemovePaint(position, size, modifiedChunks);
                break;

            case "density":
                SetDensity(position, size, modifiedChunks);
                break;

            case "rotate":
                SetRotation(position, size, modifiedChunks);
                break;

            case "meta1":
                SetMeta(1, position, size, modifiedChunks);
                break;

            case "meta2":
                SetMeta(2, position, size, modifiedChunks);
                break;

            case "meta3":
                SetMeta(3, position, size, modifiedChunks);
                break;

            default:
                SendOutput(GetHelp());
                break;
            }
        }
Exemplo n.º 2
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            if (Options.ContainsKey("undo"))
            {
                SendOutput("Please use the bc-undo command to undo changes");

                return;
            }

            EntityPlayer sender = null;

            if (SenderInfo.RemoteClientInfo != null)
            {
                sender = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
            }

            if (Params.Count == 0)
            {
                return;
            }

            var prefab = new Prefab();

            if (!prefab.Load(Params[0]))
            {
                return;
            }

            if (!GetRxyz(prefab, sender, out var r, out var x, out var y, out var z))
            {
                return;
            }

            var pos = Options.ContainsKey("nooffset") ? new Vector3i(x, y, z) : new Vector3i(x, y + prefab.yOffset, z);

            if (Options.ContainsKey("air"))
            {
                prefab.bCopyAirBlocks = true;
            }
            if (Options.ContainsKey("noair"))
            {
                prefab.bCopyAirBlocks = false;
            }

            BlockTranslations(world, prefab, pos);

            //CREATE UNDO
            //create backup of area prefab will insert to
            if (!Options.ContainsKey("noundo"))
            {
                BCUtils.CreateUndo(sender, pos, prefab.size);
            }

            // SPAWN PREFAB
            Log.Out($"{Config.ModPrefix}Spawning prefab {prefab.filename} @ {pos}, size={prefab.size}, rot={r}");
            SendOutput($"Spawning prefab {prefab.filename} @ {pos}, size={prefab.size}, rot={r}");
            if (Options.ContainsKey("sblock") || Options.ContainsKey("editmode") || GameManager.Instance.IsEditMode())
            {
                SendOutput("* with Sleeper Blocks option set");
            }
            else
            {
                SendOutput("* with Sleeper Spawning option set");
            }
            if (Options.ContainsKey("tfill") || Options.ContainsKey("editmode") || GameManager.Instance.IsEditMode())
            {
                SendOutput("* with Terrain Filler option set");
            }
            if (Options.ContainsKey("notrans") || Options.ContainsKey("editmode") || GameManager.Instance.IsEditMode())
            {
                SendOutput("* with No Placeholder Translations option set");
            }
            SendOutput("use bc-undo to revert the changes");

            InsertPrefab(world, prefab, pos);
        }