Exemplo n.º 1
0
        public void SetBlock(int x, int y, int z, eBlock b)
        {
            if (z < 0 || z >= lenZ || y < 0 || y >= lenY || x < 0 || x >= lenX)
                return;

            data[x, y, z] = new Blocks(b);
        }
Exemplo n.º 2
0
 public Blocks Copy()
 {
     Blocks b = new Blocks(X, Y, Z);
     for (int i = 0; i < totalCount; i++)
         b[i] = new Block(this[i]);
     return b;
 }
Exemplo n.º 3
0
 public BlockDrawSettings(Blocks Block, WireMask Mask)
     : this(Block)
 {
     this.Mask = Mask;
 }
Exemplo n.º 4
0
 public BlockDrawSettings(Blocks Block,  bool On)
     : this(Block)
 {
     block.Power = On ? 16 : 0;
 }
Exemplo n.º 5
0
        public static Blocks Load(string filename)
        {
            NbtFile f = new NbtFile();
            f.LoadFile(filename);
            NbtCompound root = f.RootTag;
            NbtTag nBlocks = root["Blocks"];
            NbtTag nData = root["Data"];
            NbtTag nWidth = root["Width"];
            NbtTag nLength = root["Length"];
            NbtTag nHeight = root["Height"];
            byte[] blocks = ((NbtByteArray)nBlocks).Value;
            byte[] extra = ((NbtByteArray)nData).Value;
            int X = (int)((NbtShort)nWidth).Value;
            int Y = (int)((NbtShort)nLength).Value;
            int Z = (int)((NbtShort)nHeight).Value;
            Blocks b = new Blocks(X, Y, Z);
            //bool sch = filename.EndsWith(".schematic");

            for (int i = 0; i < blocks.Length; i++)
                switch (blocks[i])
                {
                    case 0:
                    case 6:
                    case 37:
                    case 38:
                    case 39:
                    case 40:
                    case 51:
                    case 59:
                    case 63:
                    case 65:
                    case 66:
                    case 68:
                    case 78:
                    case 83:
                        b[i] = Block.AIR;
                        break;
                    case 55:
                        b[i] = Block.WIRE;
                        break;
                    case 75: // Off
                        b[i] = new Block(BlockType.TORCH, PlaceTorch(extra[i]), 0, 0, 0);

                        break;
                    case 76: // Off
                        b[i] = new Block(BlockType.TORCH, PlaceTorch(extra[i]), 16, 0, 0);

                       // System.Console.WriteLine("Loc: {2}  Torch Dir: {0}    Byte: {1}", b[i].Place.ToString(), extra[i] & 0x7,i);
                        break;
                    case 69:
                        b[i] = new Block(BlockType.LEVER,  PlaceTorch(extra[i]),(extra[i] & 0x8) == 1 ? 16 : 0, 0, 0);

                     //   System.Console.WriteLine("Lever Dir: {0}    Byte: {1}", b[i].Place.ToString(), extra[i] & 0x7);
                        break;
                    case 70:
                    case 72:
                        b[i] = Block.PREASUREPAD;
                        break;
                    case 77:
                        b[i] = Block.BUTTON;
                        b[i].Place = PlaceButton(extra[i]);
                        break;
                    case 64: // doors not working yet
                    case 71:
                        break;
                    case 93: // skip repeaters for now

                        break;
                    default:
                        b[i] = Block.BLOCK;
                        break;

                }

            return b;
        }
Exemplo n.º 6
0
 public BlockDrawSettings(Blocks Block)
     : this()
 {
     block = Block;
 }
Exemplo n.º 7
0
        public void update()
        {
            // Clear power, tick to torches.  Put in repeater in here
            for (int z = 0; z < lenZ; z++)
            {
                for (int y = 0; y < lenY; y++)
                {
                    for (int x = 0; x < lenX; x++)
                    {
                        BlockVector v = new BlockVector(x, y, z);
                        Blocks      b = GetBlock(v);
                        if (b.Type == eBlock.WIRE || b.Type == eBlock.DOORB)
                        {
                            SetPower(v, 0);
                        }
                        else
                        if (b.isBlock)
                        {
                            SetPower(v, 0);
                            if (GetBlock(v.Down).Powered&& GetBlock(v.Down).Type == eBlock.TORCH)
                            {
                                // A torch below a block powers the block
                                SetPower(v, 17);
                            }
                            else
                            {
                                // Check if there is a switch on the block and turn it on
                                if (GetBlock(v.North).isControl&& GetBlock(v.North).Mount == eMount.NORTH && GetBlock(v).Powered)
                                {
                                    SetPower(v, 17);
                                }
                                if (GetBlock(v.South).isControl&& GetBlock(v.South).Mount == eMount.SOUTH && GetBlock(v).Powered)
                                {
                                    SetPower(v, 17);
                                }
                                if (GetBlock(v.East).isControl&& GetBlock(v.East).Mount == eMount.EAST && GetBlock(v).Powered)
                                {
                                    SetPower(v, 17);
                                }
                                if (GetBlock(v.West).isControl&& GetBlock(v.West).Mount == eMount.WEST && GetBlock(v).Powered)
                                {
                                    SetPower(v, 17);
                                }
                                if (GetBlock(v.Up).isControl&& GetBlock(v.Up).Mount == eMount.TOP && GetBlock(v).Powered)
                                {
                                    SetPower(v, 17);
                                }
                            }
                        }
                    }
                }
            }

            for (int z = 0; z < lenZ; z++)
            {
                for (int y = 0; y < lenY; y++)
                {
                    for (int x = 0; x < lenX; x++)
                    {
                        BlockVector v = new BlockVector(x, y, z);
                        Blocks      b = GetBlock(v);
                        if (b.Power >= (b.Type != eBlock.BUTTON && b.Type != eBlock.PRESS ? 16 : 1) &&
                            (b.Type == eBlock.TORCH || b.isControl || b.isBlock && b.Power == 17))
                        {
                            if (GetBlock(v.Up).Type == eBlock.WIRE)
                            {
                                followWire(v.Up, 15);
                            }
                            if (GetBlock(v.Down).Type == eBlock.WIRE)
                            {
                                followWire(v.Down, 15);
                            }
                            if (GetBlock(v.North).Type == eBlock.WIRE)
                            {
                                followWire(v.North, 15);
                            }
                            if (GetBlock(v.South).Type == eBlock.WIRE)
                            {
                                followWire(v.South, 15);
                            }
                            if (GetBlock(v.East).Type == eBlock.WIRE)
                            {
                                followWire(v.East, 15);
                            }
                            if (GetBlock(v.West).Type == eBlock.WIRE)
                            {
                                followWire(v.West, 15);
                            }
                        }
                    }
                }
            }



            for (int z = 0; z < lenZ; z++)
            {
                for (int y = 0; y < lenY; y++)
                {
                    for (int x = 0; x < lenX; x++)
                    {
                        BlockVector v = new BlockVector(x, y, z);
                        Blocks      b = GetBlock(v);
                        if ((b.isBlock && !b.Powered || b.Type == eBlock.DOORA) &&
                            (GetBlock(v.Up).Type == eBlock.WIRE && GetBlock(v.Up).Powered ||
                             blockConnect(x, y, 0, 1, z, true) ||
                             blockConnect(x, y, 0, -1, z, true) ||
                             blockConnect(x, y, 1, 0, z, true) ||
                             blockConnect(x, y, -1, 0, z, true)))
                        {
                            data[x, y, z].Power = 16;
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        public bool canConnect(int x, int y, int tX, int tY, int z)
        {
            BlockVector v    = new BlockVector(x, y, z); v.SetNext(tX, tY);
            Blocks      test = GetBlock(v);

            if (test.WireConn)
            {
                return(true);
            }
            if (test.isAir)
            {
                return(GetBlockType(v.Down) == eBlock.WIRE);
            }
            if (test.isBlock)
            {
                BlockVector t = BlockVector.Null;
                if (GetBlockType(v.Up) == eBlock.WIRE && !(GetBlockType(v.Old.Up) == eBlock.BLOCK))
                {
                    return(true);
                }

                if (GetBlock(v.North).Mount == eMount.NORTH)
                {
                    t = v.North;
                }
                if (GetBlock(v.South).Mount == eMount.SOUTH)
                {
                    t = v.South;
                }
                if (GetBlock(v.East).Mount == eMount.EAST)
                {
                    t = v.East;
                }
                if (GetBlock(v.West).Mount == eMount.WEST)
                {
                    t = v.West;
                }
                if (GetBlock(v.Up).Mount == eMount.TOP)
                {
                    t = v.Up;
                }

                if (!t.isNull)
                {
                    if (GetBlockType(t) == eBlock.TORCH)
                    {
                        return(blockConnect(v.X, v.Y, v.Old.X - v.X, v.Old.Y - v.Y, z, false));
                    }
                    else
                    {
                        return(GetBlock(v.Up).Mount != eMount.TOP || GetBlockType(t) != eBlock.LEVER);
                    }
                }


                return(GetBlockType(v.Down) == eBlock.TORCH);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 9
0
 public BlockDrawSettings(Blocks Block, bool On) : this(Block) { block.Power = On ? 16 : 0; }
Exemplo n.º 10
0
 public BlockDrawSettings(Blocks Block, WireMask Mask) : this(Block) { this.Mask = Mask; }
Exemplo n.º 11
0
 public BlockDrawSettings(Blocks Block) : this()
 {
     block = Block;
 }