Beispiel #1
0
 public void SetBlock(int x, int y, int z, Block block)
 {
     if (InRange(x) && InRange(y) && InRange(z))
     {
         blocks[x, y, z] = block;
     }
     else
     {
         world.SetBlock(pos.x + x, pos.y + y, pos.z + z, block);
     }
 }
        public static void SetBlock(int x, int y, int z, Block block, Chunk chunk, bool replaceBlocks = false)
        {
            x -= chunk.pos.x;
            y -= chunk.pos.y;
            z -= chunk.pos.z;

            if (Chunk.InRange(x) && Chunk.InRange(y) && Chunk.InRange(z))
            {
                if (replaceBlocks || chunk.blocks[x, y, z] == null)
                    chunk.SetBlock(x, y, z, block);
            }
        }
Beispiel #3
0
 public void SetActiveBlock(string type)
 {
     switch (type.ToLower())
     {
         case "grass":
             this._activeBlock = new BlockGrass();
             break;
         case "water":
             this._activeBlock = new BlockWater();
             break;
         case "dirt":
             this._activeBlock = new BlockDirt();
             break;
         case "snow":
             this._activeBlock = new BlockSnow();
             break;
         case "sand":
             this._activeBlock = new BlockSand();
             break;
         case "stone":
             this._activeBlock = new BlockStone();
             break;
         case "treered":
             this._activeBlock = new BlockTreeRed();
             break;
         case "treeyellow":
             this._activeBlock = new BlockTreeYellow();
             break;
         case "road":
             this._activeBlock = new BlockRoad();
             break;
         case "air":
             this._activeBlock = new BlockAir();
             break;
         default:
             this._activeBlock = null;
             break;
     }
 }
        public static bool SetUpIfSolidBlock(RaycastHit hit, Block block)
        {
            Chunk chunk = hit.collider.GetComponent<Chunk>();
            if (chunk == null)
                return false;

            MapPosition pos = GetBlockPos(hit);
            if (chunk.world.GetBlock(pos.x, pos.y, pos.z).IsSolid(Direction.up))
            {
                chunk.world.SetBlock(pos.x, pos.y + 1, pos.z, block);
                return true;
            }
            return false;
        }
        public static bool SetBlock(RaycastHit hit, Block block, bool adjacent = false)
        {
            Chunk chunk = hit.collider.GetComponent<Chunk>();
            if (chunk == null)
                return false;

            MapPosition pos = GetBlockPos(hit, adjacent);

            chunk.world.SetBlock(pos.x, pos.y, pos.z, block);

            return true;
        }
Beispiel #6
0
        public void SetBlock(int x, int y, int z, Block block)
        {
            Chunk chunk = GetChunk(x, y, z);

            if (chunk != null)
            {
                chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, block);
                chunk.update = true;

                UpdateIfEqual(x - chunk.pos.x, 0, new MapPosition(x - 1, y, z));
                UpdateIfEqual(x - chunk.pos.x, Chunk.chunkSize - 1, new MapPosition(x + 1, y, z));
                UpdateIfEqual(y - chunk.pos.y, 0, new MapPosition(x, y - 1, z));
                UpdateIfEqual(y - chunk.pos.y, Chunk.chunkSize - 1, new MapPosition(x, y + 1, z));
                UpdateIfEqual(z - chunk.pos.z, 0, new MapPosition(x, y, z - 1));
                UpdateIfEqual(z - chunk.pos.z, Chunk.chunkSize - 1, new MapPosition(x, y, z + 1));
            }
        }