Example #1
0
        private static void RepairBlocks(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        worldBlock.damage = 0;
                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlock(worldPos, worldBlock, false, false);
                        counter++;
                    }
                }
            }

            SendOutput($"Repairing {counter} blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #2
0
        private static void FillBlocks(Vector3i position, Vector3i size, BlockValue bv, string search, Dictionary <long, Chunk> modifiedChunks)
        {
            const int clrIdx = 0;

            if (Block.list[bv.type] == null)
            {
                SendOutput("Unable to find block by id or name");

                return;
            }

            SetBlocks(clrIdx, position, size, bv, search == "*");

            if (Options.ContainsKey("delmulti"))
            {
                SendOutput($"Removed multidim blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            }
            else
            {
                SendOutput($"Inserting block '{Block.list[bv.type].GetBlockName()}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
                SendOutput("Use bc-undo to revert the changes");
            }

            Reload(modifiedChunks);
        }
Example #3
0
        private static void RemovePaint(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Block.shape.IsTerrain() || worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetTextureFull(worldPos, 0L);
                        counter++;
                    }
                }
            }

            SendOutput($"Paint removed from {counter} blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #4
0
        private static void SetRotation(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            byte rotation = 0;

            if (Options.ContainsKey("rot"))
            {
                if (!byte.TryParse(Options["rot"], out rotation))
                {
                    SendOutput($"Unable to parse rotation '{Options["rot"]}'");

                    return;
                }
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air) || worldBlock.ischild || !worldBlock.Block.shape.IsRotatable)
                        {
                            continue;
                        }

                        worldBlock.rotation = rotation;
                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlock(worldPos, worldBlock, false, false);
                        counter++;
                    }
                }
            }

            SendOutput($"Setting rotation on '{counter}' blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #5
0
        private static void SwapBlocks(Vector3i position, Vector3i size, BlockValue newbv, string blockname, Dictionary <long, Chunk> modifiedChunks)
        {
            var targetbv = int.TryParse(blockname, out var blockId) ? Block.GetBlockValue(blockId) : Block.GetBlockValue(blockname);

            var block1 = Block.list[targetbv.type];

            if (block1 == null)
            {
                SendOutput("Unable to find target block by id or name");

                return;
            }

            var block2 = Block.list[newbv.type];

            if (block2 == null)
            {
                SendOutput("Unable to find replacement block by id or name");

                return;
            }

            const int clrIdx  = 0;
            var       counter = 0;
            var       world   = GameManager.Instance.World;

            for (var i = 0; i < size.x; i++)
            {
                for (var j = 0; j < size.y; j++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        sbyte density = 1;
                        if (Options.ContainsKey("d"))
                        {
                            if (sbyte.TryParse(Options["d"], out density))
                            {
                                SendOutput($"Using density {density}");
                            }
                        }
                        else
                        {
                            if (newbv.Equals(BlockValue.Air))
                            {
                                density = MarchingCubes.DensityAir;
                            }
                            else if (newbv.Block.shape.IsTerrain())
                            {
                                density = MarchingCubes.DensityTerrain;
                            }
                        }

                        var textureFull = 0L;
                        if (Options.ContainsKey("t"))
                        {
                            if (!byte.TryParse(Options["t"], out var texture))
                            {
                                SendOutput("Unable to parse texture index");

                                return;
                            }

                            if (BlockTextureData.list[texture] == null)
                            {
                                SendOutput($"Unknown texture index {texture}");

                                return;
                            }

                            var num = 0L;
                            for (var face = 0; face < 6; face++)
                            {
                                var num2 = face * 8;
                                num &= ~(255L << num2);
                                num |= (long)(texture & 255) << num2;
                            }
                            textureFull = num;
                        }

                        var worldPos = new Vector3i(i + position.x, j + position.y, k + position.z);
                        if (world.GetBlock(worldPos).Block.GetBlockName() != block1.GetBlockName())
                        {
                            continue;
                        }

                        world.ChunkClusters[clrIdx].SetBlock(worldPos, true, newbv, false, density, false, false);
                        world.ChunkClusters[clrIdx].SetTextureFull(worldPos, textureFull);
                        counter++;
                    }
                }
            }

            SendOutput($"Replaced {counter} '{block1.GetBlockName()}' blocks with '{block2.GetBlockName()}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #6
0
        private static void SetPaint(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            var texture = 0;

            if (Options.ContainsKey("t"))
            {
                if (!int.TryParse(Options["t"], out texture))
                {
                    SendOutput("Unable to parse texture value");

                    return;
                }
                if (BlockTextureData.list[texture] == null)
                {
                    SendOutput($"Unknown texture index {texture}");

                    return;
                }
            }

            var num = 0L;

            for (var face = 0; face < 6; face++)
            {
                var num2 = face * 8;
                num &= ~(255L << num2);
                num |= (long)(texture & 255) << num2;
            }
            var textureFull = num;

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Block.shape.IsTerrain() || worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetTextureFull(worldPos, textureFull);
                        counter++;
                    }
                }
            }

            SendOutput($"Painting {counter} blocks with texture '{BlockTextureData.GetDataByTextureID(texture)?.Name}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #7
0
        private static void SetPaintFace(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            byte texture = 0;

            if (Options.ContainsKey("t"))
            {
                if (!byte.TryParse(Options["t"], out texture))
                {
                    SendOutput("Unable to parse texture value");

                    return;
                }
                if (BlockTextureData.list[texture] == null)
                {
                    SendOutput($"Unknown texture index {texture}");

                    return;
                }
            }
            uint setFace = 0;

            if (Options.ContainsKey("face"))
            {
                if (!uint.TryParse(Options["face"], out setFace))
                {
                    SendOutput("Unable to parse face value");

                    return;
                }
            }
            if (setFace > 5)
            {
                SendOutput("Face must be between 0 and 5");

                return;
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlockFaceTexture(worldPos, (BlockFace)setFace, texture);
                        counter++;
                    }
                }
            }

            SendOutput($"Painting {counter} blocks on face '{((BlockFace)setFace).ToString()}' with texture '{BlockTextureData.GetDataByTextureID(texture)?.Name}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #8
0
        private static void DamageBlocks(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            var damageMin = 0;
            var damageMax = 0;

            if (Options.ContainsKey("d"))
            {
                if (Options["d"].IndexOf(",", StringComparison.InvariantCulture) > -1)
                {
                    var dRange = Options["d"].Split(',');
                    if (dRange.Length != 2)
                    {
                        SendOutput("Unable to parse damage values");

                        return;
                    }

                    if (!int.TryParse(dRange[0], out damageMin))
                    {
                        SendOutput("Unable to parse damage min value");

                        return;
                    }

                    if (!int.TryParse(dRange[1], out damageMax))
                    {
                        SendOutput("Unable to parse damage max value");

                        return;
                    }
                }
                else
                {
                    if (!int.TryParse(Options["d"], out damageMin))
                    {
                        SendOutput("Unable to parse damage value");

                        return;
                    }
                }
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air))
                        {
                            continue;
                        }

                        var max    = worldBlock.Block.blockMaterial.MaxDamage;
                        var damage = (damageMax != 0 ? UnityEngine.Random.Range(damageMin, damageMax) : damageMin) + worldBlock.damage;
                        if (Options.ContainsKey("nobreak"))
                        {
                            worldBlock.damage = Math.Min(damage, max - 1);
                        }
                        else if (Options.ContainsKey("overkill"))
                        {
                            while (damage >= max)
                            {
                                var downgradeBlock = worldBlock.Block.DowngradeBlock;
                                damage -= max;
                                max     = downgradeBlock.Block.blockMaterial.MaxDamage;
                                downgradeBlock.rotation = worldBlock.rotation;
                                worldBlock = downgradeBlock;
                            }
                            worldBlock.damage = damage;
                        }
                        else
                        {
                            //needs to downgrade if damage > max, no overflow damage
                            if (damage >= max)
                            {
                                var downgradeBlock = worldBlock.Block.DowngradeBlock;
                                downgradeBlock.rotation = worldBlock.rotation;
                                worldBlock = downgradeBlock;
                            }
                            else
                            {
                                worldBlock.damage = damage;
                            }
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlock(worldPos, worldBlock, false, false);
                        counter++;
                    }
                }
            }

            SendOutput($"Damaging {counter} blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #9
0
        private static void SetMeta(int metaIdx, Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            if (!byte.TryParse(Options["meta"], out var meta))
            {
                SendOutput($"Unable to parse meta '{Options["meta"]}'");

                return;
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air) || worldBlock.ischild)
                        {
                            continue;
                        }

                        switch (metaIdx)
                        {
                        case 1:
                            worldBlock.meta = meta;
                            break;

                        case 2:
                            worldBlock.meta2 = meta;
                            break;

                        case 3:
                            worldBlock.meta3 = meta;
                            break;

                        default:
                            return;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx].SetBlock(worldPos, worldBlock, false, false);
                        counter++;
                    }
                }
            }

            SendOutput($"Setting meta{metaIdx} on '{counter}' blocks @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #10
0
        private static void SetDensity(Vector3i position, Vector3i size, Dictionary <long, Chunk> modifiedChunks)
        {
            sbyte density = 1;

            if (Options.ContainsKey("d"))
            {
                if (sbyte.TryParse(Options["d"], out density))
                {
                    SendOutput($"Using density {density}");
                }
            }

            const int clrIdx  = 0;
            var       counter = 0;

            for (var j = 0; j < size.y; j++)
            {
                for (var i = 0; i < size.x; i++)
                {
                    for (var k = 0; k < size.z; k++)
                    {
                        var worldPos   = new Vector3i(i + position.x, j + position.y, k + position.z);
                        var worldBlock = GameManager.Instance.World.GetBlock(clrIdx, worldPos);
                        if (worldBlock.Equals(BlockValue.Air) || worldBlock.ischild)
                        {
                            continue;
                        }

                        GameManager.Instance.World.ChunkClusters[clrIdx]
                        .SetBlock(worldPos, false, worldBlock, true, density, false, false, Options.ContainsKey("force"));
                        counter++;
                    }
                }
            }

            SendOutput($"Setting density on {counter} blocks '{density}' @ {position} to {BCUtils.GetMaxPos(position, size)}");
            SendOutput("Use bc-undo to revert the changes");
            Reload(modifiedChunks);
        }
Example #11
0
        public static Prefab CopyFromWorld(World world, Vector3i pos, Vector3i size)
        {
            var maxPos = BCUtils.GetMaxPos(pos, size);
            //must use size constructor to initialize private arrays
            var prefab = new Prefab(size);
            //Get prefab blocks from the world
            var _y = 0;
            var y  = pos.y;

            while (y <= maxPos.y)
            {
                var _x = 0;
                var x  = pos.x;
                while (x <= maxPos.x)
                {
                    var _z = 0;
                    var z  = pos.z;
                    while (z <= maxPos.z)
                    {
                        prefab.SetBlock(_x, _y, _z, world.GetBlock(x, y, z));
                        prefab.SetDensity(_x, _y, _z, world.GetDensity(0, x, y, z));
                        prefab.SetTexture(_x, _y, _z, world.GetTexture(x, y, z));

                        var te = world.GetTileEntity(0, new Vector3i(x, y, z));
                        if (te != null)
                        {
                            switch (te.GetTileEntityType())
                            {
                            case TileEntityType.VendingMachine:
                            {
                                if (te is TileEntityVendingMachine vm && vm.IsLocked())
                                {
                                    var bv = prefab.GetBlock(_x, _y, _z);
                                    bv.meta |= 4;
                                    prefab.SetBlock(_x, _y, _z, bv);
                                }
                                break;
                            }

                            case TileEntityType.SecureLoot:
                            {
                                if (te is TileEntitySecureLootContainer sl && sl.IsLocked())
                                {
                                    var bv = prefab.GetBlock(_x, _y, _z);
                                    bv.meta |= 4;
                                    prefab.SetBlock(_x, _y, _z, bv);
                                }
                                break;
                            }

                            case TileEntityType.SecureDoor:
                            {
                                if (te is TileEntitySecureDoor sd && sd.IsLocked())
                                {
                                    var bv = prefab.GetBlock(_x, _y, _z);
                                    bv.meta |= 4;
                                    prefab.SetBlock(_x, _y, _z, bv);
                                }
                                break;
                            }

                            case TileEntityType.Sign:
                            {
                                if (te is TileEntitySign sg && sg.IsLocked())
                                {
                                    var bv = prefab.GetBlock(_x, _y, _z);
                                    bv.meta |= 4;
                                    prefab.SetBlock(_x, _y, _z, bv);
                                }
                                break;
                            }
                            }
                        }
                        ++z;
                        ++_z;
                    }
                    ++x;
                    ++_x;
                }
                ++y;
                ++_y;
            }
            prefab.addAllChildBlocks();
            prefab.bSleeperVolumes = false;

            return(prefab);
        }